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=7d2fe23c6868fe90c885417d062f14ff56fb15d5;hb=428150834ee60899b9a8da019bae3c8bf009adf1;hp=43b62b0c0640b9f7ee289e6c0e2a2a2633e5ae93;hpb=775f45908025e46a40c9c147fca2066af5c8c5b8;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 43b62b0c0..7d2fe23c6 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."; @@ -991,11 +991,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); } @@ -1044,7 +1046,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; @@ -1153,19 +1160,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); @@ -1239,7 +1233,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))); @@ -1579,23 +1573,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } } - - if(!errorMsg.isEmpty()){ - - PrintWriter out = response.getWriter(); - - response.setCharacterEncoding("UTF-8"); - 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);