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=422c18a316f28e2c10e0436822d2ba16676f576b;hb=4938fc8ff0a231e26d63c06016365bea5c021c3f;hp=e2db78c6ca895c2ad7334e8cb47b8e77da133346;hpb=9df8b88412f6e890320bc446ba1c83a13e99822d;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 e2db78c6c..422c18a31 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 @@ -113,7 +113,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; @RequestMapping("/") public class CreateDcaeMicroServiceController extends RestrictedBaseController { private static final Logger LOGGER = FlexLogger.getLogger(CreateDcaeMicroServiceController.class); - + private Map matchableValues; private static CommonClassDao commonClassDao; public static CommonClassDao getCommonClassDao() { @@ -151,7 +151,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { public static final String DEFAULT=".default"; public static final String REQUIRED=".required"; public static final String MANYFALSE=":MANY-false"; - + public static final String MATCHABLE=".matchable"; @Autowired private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){ @@ -520,6 +520,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { HashMap parseDataNodes(Map map){ HashMap dataMapForJson=new HashMap <>(); + matchableValues = new HashMap <>(); for(String uniqueDataKey: uniqueDataKeys){ if(uniqueDataKey.contains("%")){ String[] uniqueDataKeySplit= uniqueDataKey.split("%"); @@ -538,6 +539,15 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { String requiredValue= map.get(findRequired); LOGGER.info("requiredValue is:"+ requiredValue); + String matchable =DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+MATCHABLE; + + String matchableValue= map.get(matchable); + + if("true".equalsIgnoreCase(matchableValue)){ + String key=uniqueDataKeySplit[uniqueDataKeySplit.length -1]; + matchableValues.put(key, "matching-true"); + } + StringBuilder attributeIndividualStringBuilder= new StringBuilder(); attributeIndividualStringBuilder.append(typeValue+":defaultValue-"); attributeIndividualStringBuilder.append(defaultValue+":required-"); @@ -545,6 +555,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { dataMapForJson.put(uniqueDataKey, attributeIndividualStringBuilder.toString()); } else if(typeValue != null && typeValue.equalsIgnoreCase(LIST)){ + + String findList= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.type"; String listValue=map.get(findList); if(listValue!=null){ @@ -569,6 +581,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { break; } else{ + if(constraintsValue.contains("=")){ + constraintsValue = constraintsValue.replace("=", "equal-sign"); + } dataConstraints.add(constraintsValue); dataListBuffer.append(constraintsValue+","); } @@ -588,6 +603,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString()); } + }else{ + matchableValues.put(uniqueDataKey, "matching-true"); } } return dataMapForJson; @@ -695,12 +712,19 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { attributeIndividualStringBuilder.append(keyValues.get("default")+":required-"); attributeIndividualStringBuilder.append(keyValues.get("required")+":MANY-false"); attributeStringBuilder.append(attributeIndividualStringBuilder+","); - + if("true".equalsIgnoreCase(keyValues.get("matchable"))){ + matchableValues.put(keySetString, "matching-true"); + } } else if(keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(LIST)){ + + if("true".equalsIgnoreCase(keyValues.get("matchable"))){ + matchableValues.put(keySetString, "matching-true"); + } //List Datatype Set keys= keyValues.keySet(); Iterator itr=keys.iterator(); + boolean isDefinedType = false; while(itr.hasNext()){ String key= itr.next(); if(!("type").equals(key) ||("required").equals(key)) @@ -713,22 +737,26 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { constraints.add(keyValues.get(key)); } }else{ - //This is user defined string + //This is user defined type String trimValue=value.substring(value.lastIndexOf('.')+1); StringBuilder referenceIndividualStringBuilder= new StringBuilder(); referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true"); referenceStringBuilder.append(referenceIndividualStringBuilder+","); + isDefinedType = true; } } } - if(keyValues.get("type").equalsIgnoreCase(LIST) && - (constraints == null || constraints.isEmpty()) ) { + if(!isDefinedType && keyValues.get("type").equalsIgnoreCase(LIST) && + (constraints == null || constraints.isEmpty()) ) { //type is list but no constraints defined. referenceStringBuilder.append(keySetString+"=MANY-true"+","); } }else{ //User defined Datatype. + if("true".equalsIgnoreCase(keyValues.get("matchable"))){ + matchableValues.put(keySetString, "matching-true"); + } String value=keyValues.get("type"); if(value != null && !value.isEmpty()){ String trimValue=value.substring(value.lastIndexOf('.')+1); @@ -892,52 +920,28 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } node.put(key.substring(key.indexOf('.')+1), value); } - }else if(node.size()!=0){ - if(nodeKey.contains("@")){ - if(arryKey==null){ - arryKey = nodeKey.substring(0,nodeKey.indexOf('@')); - } - if(nodeKey.endsWith("@0")){ - isArray = true; - jsonArray = new JSONArray(); - } - if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){ - jsonArray.put(decodeContent(node)); - } - jsonResult.put(arryKey, jsonArray); - jsonArray = new JSONArray(); - arryKey = nodeKey.substring(0,nodeKey.indexOf('@')); - }else{ - isArray = false; - jsonResult.put(nodeKey, decodeContent(node)); - } - node = nodeFactory.objectNode(); - if(key.contains("@")){ - isArray = true; - if(key.endsWith("@0")|| jsonArray==null){ + }else { + if(node.size()!=0){ + if(nodeKey.contains("@")){ + if(arryKey==null){ + arryKey = nodeKey.substring(0,nodeKey.indexOf('@')); + } + if(nodeKey.endsWith("@0")){ + isArray = true; + jsonArray = new JSONArray(); + } + if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){ + jsonArray.put(decodeContent(node)); + } + jsonResult.put(arryKey, jsonArray); jsonArray = new JSONArray(); - } - }else if(!key.contains("@")){ - isArray = false; - } - if(isArray){ - if(oldValue==null){ - oldValue = key.substring(0,key.indexOf('@')); - } - if(oldValue!=prevKey){ - oldValue = key.substring(0,key.indexOf('@')); - } - if(oldValue.equals(key.substring(0,key.indexOf('@')))){ - jsonArray.put(value); + arryKey = nodeKey.substring(0,nodeKey.indexOf('@')); }else{ - jsonResult.put(oldValue, jsonArray); - jsonArray = new JSONArray(); + isArray = false; + jsonResult.put(nodeKey, decodeContent(node)); } - oldValue = key.substring(0,key.indexOf('@')); - }else{ - jsonResult.put(key, value); + node = nodeFactory.objectNode(); } - }else{ if(key.contains("@")){ isArray = true; if(key.endsWith("@0")|| jsonArray==null){ @@ -1011,9 +1015,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { LOGGER.info("allkeys : " + allkeys); } - String allManyTrueKeys = ""; + String nameOfTrueKey = ""; if(allkeys != null){ - allManyTrueKeys = allkeys.toString(); + nameOfTrueKey = allkeys.toString(); } String jsonModel = createMicroSeriveJson(returnModel, allkeys); @@ -1057,10 +1061,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(returnModel); JSONObject j; - if("".equals(allManyTrueKeys)){ + if("".equals(nameOfTrueKey)){ j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}"); }else{ - j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}"); + j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + nameOfTrueKey+ "}"); } list.add(j); out.write(list.toString()); @@ -1634,7 +1638,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { msAttributes.setAttribute(returnAttributeList); msAttributes.setSubClass(this.retmap); - + msAttributes.setMatchingSet(matchableValues); HashMap returnReferenceList =new HashMap<>(); returnReferenceList.put(className, this.referenceAttributes); msAttributes.setRefAttribute(returnReferenceList); @@ -1726,7 +1730,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { private void retreiveDependency(String workingFile, Boolean modelClass) { MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName()); - HashMap tempMap; + Map tempMap; tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI); @@ -1738,9 +1742,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } private List listModelFiles(String directoryName) { - File directory = new File(directoryName); + File fileDirectory = new File(directoryName); List resultList = new ArrayList<>(); - File[] fList = directory.listFiles(); + File[] fList = fileDirectory.listFiles(); for (File file : fList) { if (file.isFile()) { resultList.add(file);