X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FCreateDcaeMicroServiceController.java;h=a40b48aa2cafba75d94b5cc85d290d5b116a4fad;hb=aa9e865ccf191e814b50b8b4b51d516fc359d948;hp=ff5ccffb033327567d4d6498e4bdc51019574995;hpb=ace557a95b46f994554bac3447136c022bfecab2;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index ff5ccffb0..a40b48aa2 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -73,7 +73,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.controller.PolicyController; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; @@ -83,8 +82,8 @@ import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.util.MSAttributeObject; import org.onap.policy.rest.util.MSModelUtils; import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -141,6 +140,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { Set uniqueDataKeys= new HashSet<>(); StringBuilder dataListBuffer=new StringBuilder(); List dataConstraints= new ArrayList <>(); + Set allManyTrueKeys= new HashSet <>(); public static final String DATATYPE = "data_types.policy.data."; public static final String PROPERTIES=".properties."; @@ -411,23 +411,17 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } + @SuppressWarnings("unchecked") public Map load(String fileName) throws IOException { File newConfiguration = new File(fileName); - InputStream is = null; - try { - is = new FileInputStream(newConfiguration); + Yaml yaml = new Yaml(); + Map yamlMap = null; + try(InputStream is = new FileInputStream(newConfiguration)){ + yamlMap = (Map) yaml.load(is); } catch (FileNotFoundException e) { LOGGER.error(e); } - Yaml yaml = new Yaml(); - - Map yamlMap = null; - try{ - yamlMap = (Map) yaml.load(is); - }catch(Exception e){ - LOGGER.error("load:", e); - } StringBuilder sb = new StringBuilder(); Map settings = new HashMap<>(); if (yamlMap == null) { @@ -714,17 +708,25 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { //The "." in the value determines if its a string or a user defined type. if (!value.contains(".")){ //This is string - constraints.add(keyValues.get(key)); + if(StringUtils.isNumeric(key) ){ //only integer key for the value of Constrains + constraints.add(keyValues.get(key)); + } }else{ - //This is userdefined string + //This is user defined string String trimValue=value.substring(value.lastIndexOf('.')+1); StringBuilder referenceIndividualStringBuilder= new StringBuilder(); referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true"); referenceStringBuilder.append(referenceIndividualStringBuilder+","); } - } + } + } + if(keyValues.get("type").equalsIgnoreCase(LIST)){ + if(constraints == null || constraints.isEmpty()){ + referenceStringBuilder.append(keySetString+"=MANY-true"+","); + } + } }else{ //User defined Datatype. String value=keyValues.get("type"); @@ -997,11 +999,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { MicroServiceModels returnModel = getAttributeObject(servicename, version); - //get all keys with "MANY-true" defined in their value from subAttribute + //Get all keys with "MANY-true" defined in their value from subAttribute Set allkeys = null; if(returnModel.getSub_attributes() != null && !returnModel.getSub_attributes().isEmpty()){ - JSONObject json = new JSONObject(returnModel.getSub_attributes()); - allkeys = getAllKeys(json); + JSONObject json = new JSONObject(returnModel.getSub_attributes()); + getAllKeys(json); + allkeys = allManyTrueKeys; + allManyTrueKeys = new HashSet <>(); LOGGER.info("allkeys : " + allkeys); } @@ -1018,7 +1022,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if(allkeys != null){ Iterator iter = allkeys.iterator(); while(iter.hasNext()){ - //convert to array values for MANY-true keys + //Convert to array values for MANY-true keys finalJsonObject = convertToArrayElement(jsonObject, iter.next()); } } @@ -1040,7 +1044,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if(finalJsonObject != null){ LOGGER.info(finalJsonObject.toString()); - jsonModel = finalJsonObject.toString(); + jsonModel = finalJsonObject.toString(); } } @@ -1050,7 +1054,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { List list = new ArrayList<>(); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(returnModel); - JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}"); + JSONObject j = null; + if("".equals(allManyTrueKeys)){ + j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}"); + }else{ + j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}"); + } list.add(j); out.write(list.toString()); return null; @@ -1159,19 +1168,6 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { return object; } - //call this method to check if the key is in the many-true key set - private boolean isKeyFound(Set allManyTruekeys, String key){ - - if(allManyTruekeys != null && key != null){ - Iterator iter = allManyTruekeys.iterator(); - while(iter.hasNext()){ - if(key.equals(iter.next())){ - return true; - } - } - } - return false; - } public static JSONObject convertToArrayElement(JSONObject json, String keyValue) { return convertToArrayElement(json, new HashSet<>(), keyValue); @@ -1245,7 +1241,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if(obj instanceof String && ((String) obj).contains("MANY-true")){ LOGGER.info("key : " + key); LOGGER.info("obj : " + obj); - keys.addAll(json.keySet()); + allManyTrueKeys.add(key); } if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key))); if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key))); @@ -1574,10 +1570,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { else { this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", "")); } - }else{ - errorMsg = "Upload error: The file name should contain '-v', such as xxx-v1802.yml"; - } - + } }catch(Exception e){ LOGGER.error("Upload error : ", e); errorMsg = "Upload error:" + e.getMessage(); @@ -1594,14 +1587,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { response.setContentType("application / json"); request.setCharacterEncoding("UTF-8"); - ObjectMapper mapper = new ObjectMapper(); JSONObject j = new JSONObject(); j.put("errorMsg", errorMsg); out.write(j.toString()); return; } - List fileList = new ArrayList<>();; + List fileList = new ArrayList<>(); this.directory = "model"; if (zip){ extractFolder(this.newFile);