[Policy-52, Policy-92, Policy-93] Policy Enhancements and bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / CreateDcaeMicroServiceController.java
index ce6531f..777fb89 100644 (file)
@@ -35,6 +35,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -101,23 +102,45 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
 @Controller
 @RequestMapping("/")
 public class CreateDcaeMicroServiceController extends RestrictedBaseController {
-       private static final Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
+       private static final Logger LOGGER = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
 
        private static CommonClassDao commonClassDao;
+       
+       public static CommonClassDao getCommonClassDao() {
+               return commonClassDao;
+       }
+
+       public static void setCommonClassDao(CommonClassDao commonClassDao) {
+               CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
+       }
+
        private MicroServiceModels newModel;
        private String newFile;
        private String directory;
-       private List<String> modelList = new ArrayList<String>();
-       private List<String> dirDependencyList = new ArrayList<String>();
-       private HashMap<String,MSAttributeObject > classMap = new HashMap<String,MSAttributeObject>();
+       private List<String> modelList = new ArrayList<>();
+       private List<String> dirDependencyList = new ArrayList<>();
+       private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
        //Tosca Model related Datastructure. 
        String referenceAttributes;
        String attributeString;
        String listConstraints;
        String subAttributeString;
-       HashMap<String, Object> retmap = new HashMap<String, Object>();
-       Set<String> uniqueKeys= new HashSet<String>();
-       Set<String> uniqueDataKeys= new HashSet<String>();
+       HashMap<String, Object> retmap = new HashMap<>();
+       Set<String> uniqueKeys= new HashSet<>();
+       Set<String> uniqueDataKeys= new HashSet<>();
+       StringBuilder dataListBuffer=new StringBuilder();
+       List<String> dataConstraints= new ArrayList <>();
+       
+       public static final String DATATYPE  = "data_types.policy.data.";
+       public static final String PROPERTIES=".properties.";
+       public static final String TYPE=".type";
+       public static final String STRING="string";
+       public static final String INTEGER="integer";
+       public static final String LIST="list";
+       public static final String DEFAULT=".default";
+       public static final String REQUIRED=".required";
+       public static final String MANYFALSE=":MANY-false";
+       
        
        @Autowired
        private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
@@ -128,8 +151,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
 
        protected PolicyRestAdapter policyAdapter = null;
        private int priorityCount; 
-       private Map<String, String> attributesListRefMap =  new HashMap<String, String>();
-       private Map<String, LinkedList<String>> arrayTextList =  new HashMap<String, LinkedList<String>>();
+       private Map<String, String> attributesListRefMap =  new HashMap<>();
+       private Map<String, LinkedList<String>> arrayTextList =  new HashMap<>();
 
        public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
                
@@ -138,7 +161,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        jsonContent = decodeContent(root.get("policyJSON")).toString();
                        constructJson(policyData, jsonContent);
                }catch(Exception e){
-                       logger.error("Error while decoding microservice content");
+                       LOGGER.error("Error while decoding microservice content", e);
                }
                
                return policyData;
@@ -202,9 +225,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                try {
                        json = om.writeValueAsString(microServiceObject);
                } catch (JsonProcessingException e) {
-                       logger.error("Error writing out the object");
+                       LOGGER.error("Error writing out the object", e);
                }
-               logger.info(json);
+               LOGGER.info(json);
                String cleanJson = cleanUPJson(json);
                cleanJson = removeNullAttributes(cleanJson);
                policyAdapter.setJsonBody(cleanJson);
@@ -232,13 +255,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                cleanJson = returnNode.toString();
                        }
                } catch (IOException e) {
-                       logger.error("Error writing out the JsonNode");
+                       LOGGER.error("Error writing out the JsonNode",e);
                }
                return cleanJson;
        }
        
        // Second index of dot should be returned. 
-       public void stringBetweenDots(String str,String value){
+       public int stringBetweenDots(String str){
                String stringToSearch=str;
                String[]ss=stringToSearch.split("\\.");
                if(ss!=null){
@@ -247,9 +270,11 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                uniqueKeys.add(ss[2]);
                        }
                }
+               
+               return uniqueKeys.size();
        }
        
-       public void stringBetweenDotsForDataFields(String str,String value){
+       public void stringBetweenDotsForDataFields(String str){
                String stringToSearch=str;
                String[]ss=stringToSearch.split("\\.");
                if(ss!=null){
@@ -268,18 +293,18 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                try {
                        is = new FileInputStream(newConfiguration);
                } catch (FileNotFoundException e) {
-                       logger.error(e);
+                       LOGGER.error(e);
                }
 
                Yaml yaml = new Yaml();
                @SuppressWarnings("unchecked")
                Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is); 
                StringBuilder sb = new StringBuilder(); 
-               Map<String, String> settings = new HashMap<String, String>(); 
+               Map<String, String> settings = new HashMap<>(); 
                if (yamlMap == null) { 
                        return settings; 
                } 
-               List<String> path = new ArrayList<String>(); 
+               List<String> path = new ArrayList <>(); 
                serializeMap(settings, sb, path, yamlMap); 
                return settings; 
        } 
@@ -287,13 +312,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        public Map<String, String> load(byte[] source) throws IOException { 
                Yaml yaml = new Yaml(); 
                @SuppressWarnings("unchecked")
-               Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source.toString()); 
+               Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(Arrays.toString(source)); 
                StringBuilder sb = new StringBuilder(); 
-               Map<String, String> settings = new HashMap<String, String>(); 
+               Map<String, String> settings = new HashMap <>(); 
                if (yamlMap == null) { 
                        return settings; 
                } 
-               List<String> path = new ArrayList<String>(); 
+               List<String> path = new ArrayList <>(); 
                serializeMap(settings, sb, path, yamlMap); 
                return settings; 
        } 
@@ -346,248 +371,294 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                settings.put(sb.toString(), value.toString()); 
        } 
     
-    
-       public void parseTosca (String fileName){
-               Map<String,String> map= new HashMap<String, String>();
-               try {
-                       map=load(fileName);
-                       for(String key:map.keySet()){
-                               if(key.contains("policy.nodes.Root"))
-                               {
-                                       continue;
-                               }
-                               else if(key.contains("policy.nodes")){
-                                       String wordToFind = "policy.nodes.";
-                                       int indexForPolicyNode=key.indexOf(wordToFind);
-                                       String subNodeString= key.substring(indexForPolicyNode+13, key.length());
-
-                                       stringBetweenDots(subNodeString,map.get(key));
-                               }
-                               else if(key.contains("policy.data")){
-                                       String wordToFind="policy.data.";
-                                       int indexForPolicyNode=key.indexOf(wordToFind);
-                                       String subNodeString= key.substring(indexForPolicyNode+12, key.length());
-
-                                       stringBetweenDotsForDataFields(subNodeString,map.get(key));
-                                       Iterator<String> itr= uniqueDataKeys.iterator();
-                                       while(itr.hasNext()){
-                                               logger.info(itr.next());
-                                       }
-                               }
+       void parseDataAndPolicyNodes(Map<String,String> map){
+               for(String key:map.keySet()){
+                       if(key.contains("policy.nodes.Root"))
+                       {
+                               continue;
                        }
+                       else if(key.contains("policy.nodes")){
+                               String wordToFind = "policy.nodes.";
+                               int indexForPolicyNode=key.indexOf(wordToFind);
+                               String subNodeString= key.substring(indexForPolicyNode+13, key.length());
 
-                       String attributeIndividualString="";
-                       String userDefinedIndividualString="";
-                       String referenceIndividualAttributes="";
-
-                       String attributeString="";
-                       String userDefinedString="";
-                       String referenceAttributes="";
-                       String listConstraints="";
+                               stringBetweenDots(subNodeString);
+                       }
+                       else if(key.contains("policy.data")){
+                               String wordToFind="policy.data.";
+                               int indexForPolicyNode=key.indexOf(wordToFind);
+                               String subNodeString= key.substring(indexForPolicyNode+12, key.length());
 
-                       for(String uniqueDataKey: uniqueDataKeys){
+                               stringBetweenDotsForDataFields(subNodeString);
+                       }
+               }
+       }
+       
+       HashMap<String,String> parseDataNodes(Map<String,String> map){
+               HashMap<String,String> dataMapForJson=new HashMap <>(); 
+               for(String uniqueDataKey: uniqueDataKeys){
+                       if(uniqueDataKey.contains("%")){
                                String[] uniqueDataKeySplit= uniqueDataKey.split("%");
-                               userDefinedIndividualString=userDefinedIndividualString+uniqueDataKey+"=";
-                               userDefinedIndividualString=userDefinedIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
-                               for(String key:map.keySet()){
-                                       if(key.contains("policy.data")){
-                                               String containsKey= uniqueDataKeySplit[1]+".type";
-                                               if(key.contains(uniqueDataKeySplit[0])){
-                                                       if(key.contains("default")){
-                                                               userDefinedIndividualString=userDefinedIndividualString.replace("#B", map.get(key));
-                                                       }
-                                                       else if(key.contains("required")){
-                                                               userDefinedIndividualString=userDefinedIndividualString.replace("#C", map.get(key));
+                               String findType=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+TYPE;
+                               String typeValue=map.get(findType);
+                               LOGGER.info(typeValue);
+                               if(typeValue.equalsIgnoreCase(STRING)||
+                                               typeValue.equalsIgnoreCase(INTEGER)
+                                 )
+                               {
+                                       String findDefault=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+DEFAULT;
+                                       String defaultValue= map.get(findDefault);
+                                       LOGGER.info("defaultValue is:"+ defaultValue);
+                                       
+                                       String findRequired=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+REQUIRED;
+                                       String requiredValue= map.get(findRequired);
+                                       LOGGER.info("requiredValue is:"+ requiredValue);
+                                       
+                                       StringBuilder attributeIndividualStringBuilder= new StringBuilder();
+                                       attributeIndividualStringBuilder.append(typeValue+":defaultValue-");
+                                       attributeIndividualStringBuilder.append(defaultValue+":required-");
+                                       attributeIndividualStringBuilder.append(requiredValue+MANYFALSE);
+                                       dataMapForJson.put(uniqueDataKey, attributeIndividualStringBuilder.toString());         
+                               }
+                               else if(typeValue.equalsIgnoreCase(LIST)){
+                                       String findList= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.type";
+                                       String listValue=map.get(findList);
+                                       if(listValue!=null){
+                                               LOGGER.info("Type of list is:"+ listValue);
+                                               //Its userdefined
+                                               if(listValue.contains(".")){
+                                                       String trimValue=listValue.substring(listValue.lastIndexOf('.')+1);
+                                                       StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                                                       referenceIndividualStringBuilder.append(trimValue+":MANY-true");
+                                                       dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
+                                               }//Its string
+                                               else{
+                                                       StringBuilder stringListItems= new StringBuilder();
+                                                       stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+":MANY-false");
+                                                       dataMapForJson.put(uniqueDataKey, stringListItems.toString());
+                                                       dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase()+"=[");
+                                                       for(int i=0;i<10;i++){
+                                                               String findConstraints= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.constraints.0.valid_values."+i;
+                                                               String constraintsValue=map.get(findConstraints);
+                                                               LOGGER.info(constraintsValue);
+                                                               if(constraintsValue==null){
+                                                                       break;
+                                                               }
+                                                               else{
+                                                                       dataConstraints.add(constraintsValue);
+                                                                       dataListBuffer.append(constraintsValue+",");
+                                                               }
                                                        }
-                                                       else if(key.contains(containsKey)){
-                                                               String typeValue= map.get(key);
-                                                               userDefinedIndividualString=userDefinedIndividualString.replace("#A", typeValue);
-                                                       } 
+                                                       dataListBuffer.append("]#");
+                                                       
+                                                       LOGGER.info(dataListBuffer);
                                                }
                                        }
-
-                               }
-                               if(userDefinedString!=""){
-                                       userDefinedString=userDefinedString+","+userDefinedIndividualString;
-                               }else{
-                                       userDefinedString=userDefinedString+userDefinedIndividualString;
                                }
-                               userDefinedIndividualString="";
-                       }
-                       logger.info("userDefinedString   :"+userDefinedString);
-
-                       HashMap<String,ArrayList<String>> mapKey= new HashMap<String,ArrayList<String>>();
-                       String secondPartString="";
-                       String firstPartString="";
-                       for(String value: userDefinedString.split(",")){
-                               String[] splitWithEquals= value.split("=");
-                               secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1);
-                               firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%"));
-                               ArrayList<String> list;
-                               if(mapKey.containsKey(firstPartString)){
-                                       list = mapKey.get(firstPartString);
-                                       list.add(secondPartString+"<"+splitWithEquals[1]);
-                               } else {
-                                       list = new ArrayList<String>();
-                                       list.add(secondPartString+"<"+splitWithEquals[1]);
-                                       mapKey.put(firstPartString, list);
+                               else{
+                                       String findUserDefined="data_types.policy.data."+uniqueDataKeySplit[0]+"."+"properties"+"."+uniqueDataKeySplit[1]+".type";
+                                       String userDefinedValue=map.get(findUserDefined);
+                                       String trimValue=userDefinedValue.substring(userDefinedValue.lastIndexOf('.')+1);
+                                       StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                                       referenceIndividualStringBuilder.append(trimValue+":MANY-false");
+                                       dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
+                                       
                                }
                        }
-
-                       JSONObject mainObject= new JSONObject();;
-                       JSONObject json;
-                       for(String s: mapKey.keySet()){
-                               json= new JSONObject();
-                               List<String> value=mapKey.get(s);
-                               for(String listValue:value){
-                                       String[] splitValue=listValue.split("<");
-                                       json.put(splitValue[0], splitValue[1]);
-                               }
-                               mainObject.put(s,json);
+               }
+               return dataMapForJson;
+       }
+       
+       void constructJsonForDataFields(HashMap<String,String> dataMapForJson){
+               HashMap<String,HashMap<String,String>> dataMapKey= new HashMap <>();
+               HashMap<String,String> hmSub;
+               for(Map.Entry<String, String> entry: dataMapForJson.entrySet()){
+                       String uniqueDataKey= entry.getKey();
+                       String[] uniqueDataKeySplit=uniqueDataKey.split("%");
+                       String value= dataMapForJson.get(uniqueDataKey);
+                       if(dataMapKey.containsKey(uniqueDataKeySplit[0])){
+                               hmSub = dataMapKey.get(uniqueDataKeySplit[0]);
+                               hmSub.put(uniqueDataKeySplit[1], value);
                        }
-
-                       logger.info(mainObject);
-
-                       Iterator<String> keysItr = mainObject.keys();
-                       while(keysItr.hasNext()) {
-                               String key = keysItr.next();
-                               String value = mainObject.get(key).toString();
-                               retmap.put(key, value);
+                       else{
+                               hmSub=new HashMap <>();
+                               hmSub.put(uniqueDataKeySplit[1], value);
                        }
-
-                       for(String str:retmap.keySet()){
-                               logger.info(str+":"+retmap.get(str));
+                               
+                       dataMapKey.put(uniqueDataKeySplit[0], hmSub);
+               }
+                               
+               JSONObject mainObject= new JSONObject();
+               JSONObject json;
+               for(Map.Entry<String,HashMap<String,String>> entry: dataMapKey.entrySet()){
+                       String s=entry.getKey();
+                       json= new JSONObject();
+                       HashMap<String,String> jsonHm=dataMapKey.get(s);
+                       for(Map.Entry<String,String> entryMap:jsonHm.entrySet()){
+                               String key=entryMap.getKey();
+                               json.put(key, jsonHm.get(key));
                        }
-
-                       String typeValueFromKey="";
-                       boolean userDefinedDataType=false;
-                       boolean isList=false;
-                       for(String uniqueKey: uniqueKeys){
-                               List<String> constraints= new ArrayList<String>();
-                               logger.info("====================");
-                               attributeIndividualString=attributeIndividualString+uniqueKey+"=";
-                               attributeIndividualString=attributeIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
-
-                               logger.info("UniqueStrings: "+uniqueKey);
-                               for(String key:map.keySet()){
-                                       if(key.contains("policy.nodes.Root")||
-                                                       key.contains("policy.data"))
-                                       {
-                                               continue;
-                                       }
-                                       else if(key.contains("policy.nodes")){
-                                               if(key.contains(uniqueKey)){
-                                                       int p=key.lastIndexOf(".");
-                                                       String firstLastOccurance=key.substring(0,p);
-                                                       int p1=firstLastOccurance.lastIndexOf(".");
-                                                       String secondLastOccurance= firstLastOccurance.substring(p1+1,firstLastOccurance.length());
-                                                       if(secondLastOccurance.equals(uniqueKey)){
-                                                               String checkTypeString= firstLastOccurance+".type";
-                                                               typeValueFromKey= map.get(checkTypeString);
-                                                       }//Its a list. 
-                                                       else if (key.contains("entry_schema")){
-                                                               if(key.contains("constraints")){
-                                                                       constraints.add(map.get(key));
-                                                               }
-                                                               if(key.contains("type")){
-                                                                       isList=true;
-                                                                       String value= map.get(key);
-                                                                       if(! (value.contains("string")) ||
-                                                                                       (value.contains("integer")) || 
-                                                                                       (value.contains("boolean")) )
-                                                                       {
-                                                                               if(!key.contains("valid_values")){
-                                                                                       String trimValue=value.substring(value.lastIndexOf(".")+1);
-                                                                                       referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-true";
-                                                                                       attributeIndividualString="";
-                                                                               }
-
-                                                                       }
-                                                               }
+                       mainObject.put(s,json);
+               }       
+               Iterator<String> keysItr = mainObject.keys();
+               while(keysItr.hasNext()) {
+                       String key = keysItr.next();
+                       String value = mainObject.get(key).toString();
+                       retmap.put(key, value);
+               }
+               
+               LOGGER.info("#############################################################################");
+               LOGGER.info(mainObject);
+               LOGGER.info("###############################################################################"); 
+       }
+       
+       
+       HashMap<String,HashMap<String,String>> parsePolicyNodes(Map<String,String> map){
+               HashMap<String,HashMap<String,String>> mapKey= new HashMap <>();
+               for(String uniqueKey: uniqueKeys){
+                       HashMap<String,String> hm;
+
+                       for(Map.Entry<String,String> entry:map.entrySet()){
+                               String key=entry.getKey();
+                               if(key.contains(uniqueKey) && key.contains("policy.nodes")){
+                                       if(mapKey.containsKey(uniqueKey)){
+                                               hm = mapKey.get(uniqueKey);
+                                               String keyStr= key.substring(key.lastIndexOf('.')+1);
+                                               String valueStr= map.get(key);
+                                               if(("type").equals(keyStr)){
+                                                       if(!key.contains("entry_schema"))
+                                                       {
+                                                               hm.put(keyStr,valueStr);
                                                        }
+                                               }else{
+                                                       hm.put(keyStr,valueStr);
+                                               }
 
-                                                       if(!(typeValueFromKey.equals("string")||
-                                                                       typeValueFromKey.equals("integer") ||
-                                                                       typeValueFromKey.equals("boolean")))
+                                       } else {
+                                               hm = new HashMap <>();
+                                               String keyStr= key.substring(key.lastIndexOf('.')+1);
+                                               String valueStr= map.get(key);
+                                               if(("type").equals(keyStr)){
+                                                       if(!key.contains("entry_schema"))
                                                        {
-                                                               if(typeValueFromKey.equals("list")){
-                                                                       isList=true;
-                                                                       userDefinedDataType=false;
-                                                               }
-                                                               else{
-                                                                       userDefinedDataType=true;
-                                                               }
-                                                       }
-                                                       if(userDefinedDataType==false && isList==false){
-                                                               if(key.contains("default")){
-                                                                       attributeIndividualString=attributeIndividualString.replace("#B", map.get(key));
-                                                               }
-                                                               else if(key.contains("required")){
-                                                                       attributeIndividualString=attributeIndividualString.replace("#C", map.get(key));
-                                                               }
-                                                               else if(key.contains("type")){
-                                                                       String typeValue= map.get(key);
-                                                                       attributeIndividualString=attributeIndividualString.replace("#A", typeValue);
-                                                               } 
-                                                       }
-                                                       else if(userDefinedDataType==true){
-                                                               String checkTypeAndUpdate=key.substring(p+1);
-                                                               if(checkTypeAndUpdate.equals("type")){
-                                                                       String value=map.get(key);
-                                                                       String trimValue=value.substring(value.lastIndexOf(".")+1);
-                                                                       referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-false";
-                                                               }
-                                                               attributeIndividualString="";
+                                                               hm.put(keyStr,valueStr);
                                                        }
+                                               }else{
+                                                       hm.put(keyStr,valueStr);
                                                }
+                                               mapKey.put(uniqueKey, hm);
                                        }
                                }
+                       }
+               }
+               return mapKey;
+       }
 
-                               if(constraints!=null &&constraints.isEmpty()==false){
-                                       //List handling. 
-                                       listConstraints=uniqueKey.toUpperCase()+"=[";
-                                       isList=true;
-                                       for(String str:constraints){
-                                               listConstraints=listConstraints+str+",";
-                                       }
-                                       listConstraints+="],";
-                                       logger.info(listConstraints);
-                                       attributeIndividualString="";
-                                       referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+uniqueKey.toUpperCase()+":MANY-false";
-                                       constraints=null;
+       void createAttributes(HashMap<String,HashMap<String,String>> mapKey){
+               StringBuilder attributeStringBuilder= new StringBuilder();
+               StringBuilder referenceStringBuilder= new StringBuilder();
+               StringBuilder listBuffer= new StringBuilder();
+               List<String> constraints= new ArrayList<>();
+               for(Map.Entry<String,HashMap<String,String>> entry: mapKey.entrySet()){
+                       String keySetString= entry.getKey();
+                       HashMap<String,String> keyValues=mapKey.get(keySetString);
+                       if(keyValues.get("type").equalsIgnoreCase(STRING)||
+                                       keyValues.get("type").equalsIgnoreCase(INTEGER)
+                                       ){
+                               StringBuilder attributeIndividualStringBuilder= new StringBuilder();
+                               attributeIndividualStringBuilder.append(keySetString+"=");
+                               attributeIndividualStringBuilder.append(keyValues.get("type")+":defaultValue-");
+                               attributeIndividualStringBuilder.append(keyValues.get("default")+":required-");
+                               attributeIndividualStringBuilder.append(keyValues.get("required")+":MANY-false");
+                               attributeStringBuilder.append(attributeIndividualStringBuilder+",");    
 
-                               }
-                               if(userDefinedDataType==false && isList==false){
-                                       if(attributeString!=""){
-                                               attributeString=attributeString+","+attributeIndividualString;
-                                       }else{
-                                               attributeString=attributeString+attributeIndividualString;
-                                       }
-                               }
-                               if(isList==true || userDefinedDataType==true){
-                                       if(referenceAttributes!=""){
-                                               referenceAttributes=referenceAttributes+","+referenceIndividualAttributes;
-                                       }else{
-                                               referenceAttributes=referenceAttributes+referenceIndividualAttributes;
+                       }
+                       else if(keyValues.get("type").equalsIgnoreCase(LIST)){
+                               //List Datatype
+                               Set<String> keys= keyValues.keySet();
+                               Iterator<String> itr=keys.iterator();
+                               while(itr.hasNext()){
+                                       String key= itr.next();
+                                       if((!("type").equals(key) ||("required").equals(key)))
+                                       {
+                                               String value= keyValues.get(key);
+                                               //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));
+                                               }else{
+                                                       //This is userdefined string
+                                                       String trimValue=value.substring(value.lastIndexOf('.')+1);
+                                                       StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                                                       referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true");
+                                                       referenceStringBuilder.append(referenceIndividualStringBuilder+",");
+                                               }
                                        }
-                                       logger.info("ReferenceAttributes: "+referenceAttributes);
                                }
 
-                               logger.info("AttributeString: "+ attributeString);
-                               logger.info("ListConstraints is: "+listConstraints);
+                       }else{
+                               //User defined Datatype. 
+                               String value=keyValues.get("type");
+                               String trimValue=value.substring(value.lastIndexOf('.')+1);
+                               StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                               referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
+                               referenceStringBuilder.append(referenceIndividualStringBuilder+",");
+
+                       }
+                       if(constraints!=null &&constraints.isEmpty()==false){
+                               //List handling. 
+                               listBuffer.append(keySetString.toUpperCase()+"=[");
+                               for(String str:constraints){
+                                       listBuffer.append(str+",");
+                               }
+                               listBuffer.append("]#");
+                               LOGGER.info(listBuffer);
 
-                               attributeIndividualString="";
-                               referenceIndividualAttributes="";
-                               userDefinedDataType=false;
-                               isList=false;
 
+                               StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                               referenceIndividualStringBuilder.append(keySetString+"="+keySetString.toUpperCase()+":MANY-false");
+                               referenceStringBuilder.append(referenceIndividualStringBuilder+",");
+                               constraints.clear();
                        }
-                       this.listConstraints=listConstraints;
-                       this.referenceAttributes=referenceAttributes;
-                       this.attributeString=attributeString;
-               } catch (IOException e) {
-                       logger.error(e);
                }
+               
+               dataListBuffer.append(listBuffer);
+               
+
+               LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
+               LOGGER.info("Whole attribute String is:"+attributeStringBuilder);       
+               LOGGER.info("Whole reference String is:"+referenceStringBuilder);
+               LOGGER.info("List String is:"+listBuffer);
+               LOGGER.info("Data list buffer is:"+dataListBuffer);
+               LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
+               
+               this.listConstraints=dataListBuffer.toString();
+               this.referenceAttributes=referenceStringBuilder.toString();
+               this.attributeString=attributeStringBuilder.toString();
+       }
+       
+       
+    
+       public void parseTosca (String fileName){
+               Map<String,String> map= new HashMap<>();
+    
+       try {
+                       map=load(fileName);
+                       
+                       parseDataAndPolicyNodes(map);
+                       
+                       HashMap<String,String> dataMapForJson=parseDataNodes(map);
+                       
+                       constructJsonForDataFields(dataMapForJson);     
+                       
+                       HashMap<String,HashMap<String,String>> mapKey= parsePolicyNodes(map);
+                       
+                       createAttributes(mapKey);
+               
+       } catch (IOException e) {
+               LOGGER.error(e);
+       }
+       
        } 
 
        private String cleanUPJson(String json) {
@@ -611,7 +682,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        private JSONObject decodeContent(JsonNode jsonNode){
                Iterator<JsonNode> jsonElements = jsonNode.elements();
                Iterator<String> jsonKeys = jsonNode.fieldNames();
-               Map<String,String> element = new TreeMap<String,String>();
+               Map<String,String> element = new TreeMap<>();
                while(jsonElements.hasNext() && jsonKeys.hasNext()){
                        element.put(jsonKeys.next(), jsonElements.next().toString());
                }
@@ -634,7 +705,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                presKey = key;
                        }
                        // first check if we are different from old.
-                       logger.info(key+"\n");
+                       LOGGER.info(key+"\n");
                        if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
                                if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
                                        jsonResult.put(oldValue, jsonArray);
@@ -664,13 +735,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                                                isArray = true;
                                                                jsonArray = new JSONArray();
                                                        }
-                                                       if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
+                                                       if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
                                                                jsonArray.put(decodeContent(node));
                                                        } 
-                                                       if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){
-                                                               jsonResult.put(arryKey, jsonArray);
-                                                               jsonArray = new JSONArray();
-                                                       }else if(!key.contains("@")){
+                                                       if((key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))) || !key.contains("@")){
                                                                jsonResult.put(arryKey, jsonArray);
                                                                jsonArray = new JSONArray();
                                                        }
@@ -696,7 +764,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                                isArray = true;
                                                jsonArray = new JSONArray();
                                        }
-                                       if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
+                                       if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
                                                jsonArray.put(decodeContent(node));
                                        }
                                        jsonResult.put(arryKey, jsonArray);
@@ -811,8 +879,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        
        @SuppressWarnings({ "unchecked", "rawtypes" })
        private String createMicroSeriveJson(MicroServiceModels returnModel) {
-               Map<String, String> attributeMap = new HashMap<String, String>();
-               Map<String, String> refAttributeMap = new HashMap<String, String>();
+               Map<String, String> attributeMap = new HashMap<>();
+               Map<String, String> refAttributeMap = new HashMap<>();
                String attribute = returnModel.getAttributes();
                if(attribute != null){
                        attribute = attribute.trim();
@@ -882,7 +950,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        @SuppressWarnings("unchecked")
        private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
                JSONObject object = new JSONObject();
-               Map<String, String> map = new HashMap<String, String>();
+               Map<String, String> map = new HashMap<>();
                Object returnClass = subAttributeMap.get(name);
                map = (Map<String, String>) returnClass; 
                JSONArray array = new JSONArray();
@@ -935,7 +1003,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
 
        private Set<String> getVersionList(String name) {       
                MicroServiceModels workingModel = new MicroServiceModels();
-               Set<String> list = new HashSet<String>();
+               Set<String> list = new HashSet<>();
                List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
                for (int i = 0; i < microServiceModelsData.size(); i++) {
                        workingModel = (MicroServiceModels) microServiceModelsData.get(i);
@@ -972,9 +1040,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
-                       List<String> priorityList = new ArrayList<String>();
+                       List<String> priorityList = new ArrayList<>();
                        priorityCount = 10;
                        for (int i = 1; i < priorityCount; i++) {
                                priorityList.add(String.valueOf(i));
@@ -985,7 +1053,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       logger.error(e);
+                       LOGGER.error(e);
                }
        }
 
@@ -1079,7 +1147,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        }
        
        public static Map<String, String> convert(String str, String split) {
-               Map<String, String> map = new HashMap<String, String>();
+               Map<String, String> map = new HashMap<>();
                for(final String entry : str.split(split)) {
                    String[] parts = entry.split("=");
                    map.put(parts[0], parts[1]);
@@ -1106,14 +1174,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                policyAdapter.setServiceType(msBody.getService());
                        }
                        if(msBody.getContent() != null){
-                               LinkedHashMap<String, Object>  data = new LinkedHashMap<String, Object>();
+                               LinkedHashMap<String, Object>  data = new LinkedHashMap<>();
                                LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
                                readRecursivlyJSONContent(map, data);
                                policyAdapter.setRuleData(data);
                        }
 
                } catch (Exception e) {
-                       logger.error(e);
+                       LOGGER.error(e);
                }
 
        }
@@ -1124,7 +1192,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        Object key =  iterator.next();
                        Object value = map.get(key);
                        if(value instanceof LinkedHashMap<?, ?>){
-                               LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<String, Object>(); 
+                               LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>(); 
                                readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
                                for(String objKey: secondObjec.keySet()){
                                        data.put(key+"." +objKey, secondObjec.get(objKey));
@@ -1134,7 +1202,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                for(int i = 0; i < jsonArrayVal.size(); i++){
                                        Object arrayvalue = jsonArrayVal.get(i);
                                        if(arrayvalue instanceof LinkedHashMap<?, ?>){
-                                               LinkedHashMap<String, Object> newData = new LinkedHashMap<String, Object>();   
+                                               LinkedHashMap<String, Object> newData = new LinkedHashMap<>();   
                                                readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
                                                for(String objKey: newData.keySet()){
                                                        data.put(key+"@"+i+"." +objKey, newData.get(objKey));
@@ -1155,23 +1223,18 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                }
        }
 
-       private String getPolicyScope(String value) {   
-               GroupPolicyScopeList pScope = new GroupPolicyScopeList();
-               List<Object> groupList= commonClassDao.getData(GroupPolicyScopeList.class);
-               if(groupList.size() > 0){
-                       for(int i = 0 ; i < groupList.size() ; i ++){
-                               pScope = (GroupPolicyScopeList) groupList.get(i);
-                               if (pScope.getGroupList().equals(value)){
-                                       break;
-                               }               
-                       }
+       private String getPolicyScope(String value) {
+               List<Object> groupList= commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
+               if(groupList != null && !groupList.isEmpty()){
+                       GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
+                       return pScope.getGroupName();           
                }
-               return pScope.getGroupName();
+               return null;
        }
 
        //Convert the map values and set into JSON body
        public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
-               Map<String, String> attribute = new HashMap<String, String>();
+               Map<String, String> attribute = new HashMap<>();
                String temp = null;
                String key;
                String value;
@@ -1236,12 +1299,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                        }
                                
                                }catch(Exception e){
-                                       logger.error("Upload error : " + e);
+                                       LOGGER.error("Upload error : " + e);
                                }
                        }
                        
                }
-               List<File> fileList = new ArrayList<File>();;
+               List<File> fileList = new ArrayList<>();;
                this.directory = "model";
                if (zip){
                        extractFolder(this.newFile);
@@ -1256,7 +1319,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                if(yml==false){
                        modelType="xmi";
                        //Process Main Model file first
-                       classMap = new HashMap<String,MSAttributeObject>();
+                       classMap = new HashMap<>();
                        for (File file : fileList) {
                                if(!file.isDirectory() && file.getName().endsWith(".xmi")){
                        retreiveDependency(file.toString(), true);
@@ -1274,25 +1337,30 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        MSAttributeObject msAttributes= new MSAttributeObject();
                        msAttributes.setClassName(className);
                        
-                       HashMap<String, String> returnAttributeList =new HashMap<String, String>();
+                       HashMap<String, String> returnAttributeList =new HashMap<>();
                        returnAttributeList.put(className, this.attributeString);
                        msAttributes.setAttribute(returnAttributeList);
                        
                        msAttributes.setSubClass(this.retmap);
                        
-                       HashMap<String, String> returnReferenceList =new HashMap<String, String>();
+                       HashMap<String, String> returnReferenceList =new HashMap<>();
                        //String[] referenceArray=this.referenceAttributes.split("=");
                        returnReferenceList.put(className, this.referenceAttributes);
                        msAttributes.setRefAttribute(returnReferenceList);
                        
                        if(this.listConstraints!=""){
-                               HashMap<String, String> enumList =new HashMap<String, String>();
-                               String[] listArray=this.listConstraints.split("=");
-                               enumList.put(listArray[0], listArray[1]);
+                               HashMap<String, String> enumList =new HashMap<>();
+                               String[] listArray=this.listConstraints.split("#");
+                for(String str:listArray){
+                    String[] strArr= str.split("=");
+                    if(strArr.length>1){
+                        enumList.put(strArr[0], strArr[1]);
+                    }
+                }
                                msAttributes.setEnumType(enumList);
                        }
                        
-                       classMap=new HashMap<String,MSAttributeObject>();
+                       classMap=new HashMap<>();
                        classMap.put(className, msAttributes);
                        
                }
@@ -1319,7 +1387,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
            int BUFFER = 2048;
            File file = new File(zipFile);
 
-           ZipFile zip;
+           ZipFile zip = null;
                try {
                        zip = new ZipFile(file);
                    String newPath =  "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
@@ -1357,19 +1425,26 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        }
                    }
            } catch (IOException e) {
-               logger.error("Failed to unzip model file " + zipFile);
+               LOGGER.error("Failed to unzip model file " + zipFile);
+               }finally{
+                       try {
+                               if(zip != null)
+                               zip.close();
+                       } catch (IOException e) {
+                               LOGGER.error("Exception Occured While closing zipfile " + e);
+                       }
                }
        }
        
        private void retreiveDependency(String workingFile, Boolean modelClass) {
                
-               MSModelUtils utils = new MSModelUtils(PolicyController.msEcompName, PolicyController.msPolicyName);
-           HashMap<String, MSAttributeObject> tempMap = new HashMap<String, MSAttributeObject>();
+               MSModelUtils utils = new MSModelUtils(PolicyController.getMsEcompName(), PolicyController.getMsPolicyName());
+           HashMap<String, MSAttributeObject> tempMap = new HashMap<>();
            
            tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
            
            classMap.putAll(tempMap);
-           logger.info(tempMap);
+           LOGGER.info(tempMap);
            
            return;     
            
@@ -1377,7 +1452,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                
        private List<File> listModelFiles(String directoryName) {
                File directory = new File(directoryName);
-               List<File> resultList = new ArrayList<File>();
+               List<File> resultList = new ArrayList<>();
                File[] fList = directory.listFiles();
                for (File file : fList) {
                        if (file.isFile()) {
@@ -1395,7 +1470,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
             try {
                 FileUtils.forceDelete(new File(path));
             } catch (IOException e) {
-               logger.error("Failed to delete folder " + path);
+               LOGGER.error("Failed to delete folder " + path);
             }  
         }
     }
@@ -1409,7 +1484,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
     }
        
     private List<String> createList() {
-        List<String> list = new  ArrayList<String>();
+        List<String> list = new  ArrayList<>();
         for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
             if (cMap.getValue().isPolicyTempalate()){
                 list.add(cMap.getKey());
@@ -1427,23 +1502,31 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
         return list;
     }
 
+       public Map<String, String> getAttributesListRefMap() {
+               return attributesListRefMap;
+       }
+
+       public Map<String, LinkedList<String>> getArrayTextList() {
+               return arrayTextList;
+       }
+
 }
 
 class DCAEMicroServiceObject {
 
-       public String service;
-       public String location;
-       public String uuid;
-       public String policyName;
-       public String description;
-       public String configName;
-       public String templateVersion;
-       public String version;
-       public String priority;
-       public String policyScope;
-       public String riskType;
-       public String riskLevel; 
-       public String guard = null;
+       private String service;
+       private String location;
+       private String uuid;
+       private String policyName;
+       private String description;
+       private String configName;
+       private String templateVersion;
+       private String version;
+       private String priority;
+       private String policyScope;
+       private String riskType;
+       private String riskLevel; 
+       private String guard = null;
 
        public String getGuard() {
                return guard;