Merge "Included Policy GUI Enhancements and validations"
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / CreateDcaeMicroServiceController.java
index e2db78c..d1043f7 100644 (file)
@@ -701,6 +701,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                //List Datatype
                                Set<String> keys= keyValues.keySet();
                                Iterator<String> itr=keys.iterator();
+                               boolean isDefinedType = false;
                                while(itr.hasNext()){
                                        String key= itr.next();
                                        if(!("type").equals(key) ||("required").equals(key))
@@ -713,18 +714,19 @@ 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{
@@ -892,52 +894,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){
@@ -1726,7 +1704,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        private void retreiveDependency(String workingFile, Boolean modelClass) {
                
                MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
-           HashMap<String, MSAttributeObject> tempMap;
+           Map<String, MSAttributeObject> tempMap;
            
            tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);