X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fcontroller%2FCreateDcaeMicroServiceController.java;h=f3e313144b6618f7533bcd97eca81cd21978d7a5;hb=d9007d680d19734d5dc106479784c420236cca4b;hp=aeb5266c5d992b7be88a62401c15e0a09a719f98;hpb=dda032f8bb161d54eb1f59de2b4a3efb774fc4d1;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java index aeb5266c5..f3e313144 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java @@ -92,6 +92,7 @@ import com.google.gson.Gson; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; @@ -100,23 +101,32 @@ 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 modelList = new ArrayList(); - private List dirDependencyList = new ArrayList(); - private HashMap classMap = new HashMap(); + private List modelList = new ArrayList<>(); + private List dirDependencyList = new ArrayList<>(); + private HashMap classMap = new HashMap<>(); //Tosca Model related Datastructure. String referenceAttributes; String attributeString; String listConstraints; String subAttributeString; - HashMap retmap = new HashMap(); - Set uniqueKeys= new HashSet(); - Set uniqueDataKeys= new HashSet(); + HashMap retmap = new HashMap<>(); + Set uniqueKeys= new HashSet<>(); + Set uniqueDataKeys= new HashSet<>(); @Autowired private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){ @@ -127,8 +137,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { protected PolicyRestAdapter policyAdapter = null; private int priorityCount; - private Map attributesListRefMap = new HashMap(); - private Map> arrayTextList = new HashMap>(); + private Map attributesListRefMap = new HashMap<>(); + private Map> arrayTextList = new HashMap<>(); public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) { @@ -137,7 +147,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"); } return policyData; @@ -201,9 +211,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"); } - logger.info(json); + LOGGER.info(json); String cleanJson = cleanUPJson(json); cleanJson = removeNullAttributes(cleanJson); policyAdapter.setJsonBody(cleanJson); @@ -231,13 +241,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"); } return cleanJson; } // Second index of dot should be returned. - public void stringBetweenDots(String str,String value){ + public int stringBetweenDots(String str,String value){ String stringToSearch=str; String[]ss=stringToSearch.split("\\."); if(ss!=null){ @@ -246,6 +256,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { uniqueKeys.add(ss[2]); } } + + return uniqueKeys.size(); } public void stringBetweenDotsForDataFields(String str,String value){ @@ -267,14 +279,14 @@ 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 yamlMap = (Map) yaml.load(is); StringBuilder sb = new StringBuilder(); - Map settings = new HashMap(); + Map settings = new HashMap<>(); if (yamlMap == null) { return settings; } @@ -347,12 +359,11 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { public void parseTosca (String fileName){ - Map map= new HashMap(); + Map map= new HashMap<>(); try { map=load(fileName); for(String key:map.keySet()){ - if(key.contains("policy.nodes.Root")) - { + if(key.contains("policy.nodes.Root")){ continue; } else if(key.contains("policy.nodes")){ @@ -368,21 +379,11 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { String subNodeString= key.substring(indexForPolicyNode+12, key.length()); stringBetweenDotsForDataFields(subNodeString,map.get(key)); - Iterator itr= uniqueDataKeys.iterator(); - while(itr.hasNext()){ - logger.info(itr.next()); - } } } - String attributeIndividualString=""; String userDefinedIndividualString=""; - String referenceIndividualAttributes=""; - - String attributeString=""; String userDefinedString=""; - String referenceAttributes=""; - String listConstraints=""; for(String uniqueDataKey: uniqueDataKeys){ String[] uniqueDataKeySplit= uniqueDataKey.split("%"); @@ -404,7 +405,6 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } } } - } if(userDefinedString!=""){ userDefinedString=userDefinedString+","+userDefinedIndividualString; @@ -413,9 +413,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } userDefinedIndividualString=""; } - logger.info("userDefinedString :"+userDefinedString); + LOGGER.info("userDefinedString :"+userDefinedString); - HashMap> mapKey= new HashMap>(); + HashMap> mapKeyUserdefined= new HashMap<>(); String secondPartString=""; String firstPartString=""; for(String value: userDefinedString.split(",")){ @@ -423,30 +423,27 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1); firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%")); ArrayList list; - if(mapKey.containsKey(firstPartString)){ - list = mapKey.get(firstPartString); + if(mapKeyUserdefined.containsKey(firstPartString)){ + list = mapKeyUserdefined.get(firstPartString); list.add(secondPartString+"<"+splitWithEquals[1]); } else { list = new ArrayList(); list.add(secondPartString+"<"+splitWithEquals[1]); - mapKey.put(firstPartString, list); + mapKeyUserdefined.put(firstPartString, list); } } JSONObject mainObject= new JSONObject();; JSONObject json; - for(String s: mapKey.keySet()){ + for(String s: mapKeyUserdefined.keySet()){ json= new JSONObject(); - List value=mapKey.get(s); + List value=mapKeyUserdefined.get(s); for(String listValue:value){ String[] splitValue=listValue.split("<"); json.put(splitValue[0], splitValue[1]); } mainObject.put(s,json); } - - logger.info(mainObject); - Iterator keysItr = mainObject.keys(); while(keysItr.hasNext()) { String key = keysItr.next(); @@ -454,138 +451,116 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { retmap.put(key, value); } - for(String str:retmap.keySet()){ - logger.info(str+":"+retmap.get(str)); - } + LOGGER.info("#############################################################################"); + LOGGER.info(mainObject); + LOGGER.info("###############################################################################"); - String typeValueFromKey=""; - boolean userDefinedDataType=false; - boolean isList=false; + HashMap> mapKey= new HashMap<>(); for(String uniqueKey: uniqueKeys){ - List constraints= new ArrayList(); - logger.info("===================="); - attributeIndividualString=attributeIndividualString+uniqueKey+"="; - attributeIndividualString=attributeIndividualString+"#A:defaultValue-#B:required-#C:MANY-false"; + HashMap hm; - 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=""; - } - - } - } - } - - if(!(typeValueFromKey.equals("string")|| - typeValueFromKey.equals("integer") || - typeValueFromKey.equals("boolean"))) - { - 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)); + if(key.contains(uniqueKey)){ + if(mapKey.containsKey(uniqueKey)){ + hm = mapKey.get(uniqueKey); + String keyStr= key.substring(key.lastIndexOf(".")+1); + String valueStr= map.get(key); + if(keyStr.equals("type")){ + if(!key.contains("entry_schema")){ + hm.put(keyStr,valueStr); } - else if(key.contains("type")){ - String typeValue= map.get(key); - attributeIndividualString=attributeIndividualString.replace("#A", typeValue); - } + }else{ + hm.put(keyStr,valueStr); } - 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"; + } else { + hm = new HashMap<>(); + String keyStr= key.substring(key.lastIndexOf(".")+1); + String valueStr= map.get(key); + if(keyStr.equals("type")){ + if(!key.contains("entry_schema")){ + hm.put(keyStr,valueStr); } - attributeIndividualString=""; + }else{ + hm.put(keyStr,valueStr); } + mapKey.put(uniqueKey, hm); } } } + } + StringBuilder attributeStringBuilder= new StringBuilder(); + StringBuilder referenceStringBuilder= new StringBuilder(); + StringBuilder listBuffer= new StringBuilder(); + + List constraints= new ArrayList<>(); + for(String keySetString: mapKey.keySet()){ + HashMap 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+","); + } + else if(keyValues.get("type").equalsIgnoreCase("list")){ + //List Datatype + Set keys= keyValues.keySet(); + Iterator itr=keys.iterator(); + while(itr.hasNext()){ + String key= itr.next().toString(); + if((!key.equals("type"))){ + 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 user defined string + String trimValue=value.substring(value.lastIndexOf(".")+1); + StringBuilder referenceIndividualStringBuilder= new StringBuilder(); + referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true"); + referenceStringBuilder.append(referenceIndividualStringBuilder+","); + } + } + } + }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. - listConstraints=uniqueKey.toUpperCase()+"=["; - isList=true; + listBuffer.append(keySetString.toUpperCase()+"=["); for(String str:constraints){ - listConstraints=listConstraints+str+","; + listBuffer.append(str+","); } - listConstraints+="],"; - logger.info(listConstraints); - attributeIndividualString=""; - referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+uniqueKey.toUpperCase()+":MANY-false"; - constraints=null; + listBuffer.append("]#"); + LOGGER.info(listBuffer); - } - 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; - } - logger.info("ReferenceAttributes: "+referenceAttributes); - } - logger.info("AttributeString: "+ attributeString); - logger.info("ListConstraints is: "+listConstraints); + StringBuilder referenceIndividualStringBuilder= new StringBuilder(); + referenceIndividualStringBuilder.append(keySetString+"="+keySetString.toUpperCase()+":MANY-false"); + referenceStringBuilder.append(referenceIndividualStringBuilder+","); + constraints.clear(); + } + } - attributeIndividualString=""; - referenceIndividualAttributes=""; - userDefinedDataType=false; - isList=false; + LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); + LOGGER.info("Whole attribute String is:"+attributeStringBuilder); + LOGGER.info("Whole reference String is:"+referenceStringBuilder); + LOGGER.info("List String is:"+listBuffer); + LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); + this.listConstraints=listBuffer.toString(); + this.referenceAttributes=referenceStringBuilder.toString(); + this.attributeString=attributeStringBuilder.toString(); - } - this.listConstraints=listConstraints; - this.referenceAttributes=referenceAttributes; - this.attributeString=attributeString; } catch (IOException e) { - logger.error(e); + LOGGER.error(e); } } @@ -610,7 +585,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { private JSONObject decodeContent(JsonNode jsonNode){ Iterator jsonElements = jsonNode.elements(); Iterator jsonKeys = jsonNode.fieldNames(); - Map element = new TreeMap(); + Map element = new TreeMap<>(); while(jsonElements.hasNext() && jsonKeys.hasNext()){ element.put(jsonKeys.next(), jsonElements.next().toString()); } @@ -633,7 +608,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); @@ -663,7 +638,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)); } if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){ @@ -695,7 +670,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); @@ -810,8 +785,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { @SuppressWarnings({ "unchecked", "rawtypes" }) private String createMicroSeriveJson(MicroServiceModels returnModel) { - Map attributeMap = new HashMap(); - Map refAttributeMap = new HashMap(); + Map attributeMap = new HashMap<>(); + Map refAttributeMap = new HashMap<>(); String attribute = returnModel.getAttributes(); if(attribute != null){ attribute = attribute.trim(); @@ -881,7 +856,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { @SuppressWarnings("unchecked") private JSONObject recursiveReference(String name, Map subAttributeMap, String enumAttribute) { JSONObject object = new JSONObject(); - Map map = new HashMap(); + Map map = new HashMap<>(); Object returnClass = subAttributeMap.get(name); map = (Map) returnClass; JSONArray array = new JSONArray(); @@ -934,7 +909,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { private Set getVersionList(String name) { MicroServiceModels workingModel = new MicroServiceModels(); - Set list = new HashSet(); + Set list = new HashSet<>(); List microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name); for (int i = 0; i < microServiceModelsData.size(); i++) { workingModel = (MicroServiceModels) microServiceModelsData.get(i); @@ -971,9 +946,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 model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - List priorityList = new ArrayList(); + List priorityList = new ArrayList<>(); priorityCount = 10; for (int i = 1; i < priorityCount; i++) { priorityList.add(String.valueOf(i)); @@ -984,7 +959,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { response.getWriter().write(j.toString()); } catch (Exception e){ - logger.error(e); + LOGGER.error(e); } } @@ -1020,52 +995,45 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { // Under AllOFType we have Match List matchList = allOf.getMatch(); if (matchList != null) { - int index = 0; Iterator iterMatch = matchList.iterator(); while (matchList.size()>1 && iterMatch.hasNext()) { MatchType match = iterMatch.next(); // - // Under the match we have attributevalue and + // Under the match we have attribute value and // attributeDesignator. So,finally down to the actual attribute. // AttributeValueType attributeValue = match.getAttributeValue(); String value = (String) attributeValue.getContent().get(0); - + AttributeDesignatorType designator = match.getAttributeDesignator(); + String attributeId = designator.getAttributeId(); // First match in the target is EcompName, so set that value. - if (index == 0) { + if (attributeId.equals("ECOMPName")) { policyAdapter.setEcompName(value); } - if (index == 1){ + if (attributeId.equals("ConfigName")){ policyAdapter.setConfigName(value); } - if (index == 2){ - if(value != null){ - readFile(policyAdapter, entity); - } - } - if (index == 3){ + if (attributeId.equals("uuid")){ policyAdapter.setUuid(value); } - if (index == 4){ + if (attributeId.equals("location")){ policyAdapter.setLocation(value); } - if (index == 5){ + if (attributeId.equals("RiskType")){ policyAdapter.setRiskType(value); } - - if (index == 6){ + if (attributeId.equals("RiskLevel")){ policyAdapter.setRiskLevel(value); } - - if (index == 7){ + if (attributeId.equals("guard")){ policyAdapter.setGuard(value); } - if (index == 8 && !value.contains("NA")){ + if (attributeId.equals("TTLDate") && !value.contains("NA")){ String newDate = convertDate(value, true); policyAdapter.setTtlDate(newDate); } - index++; } + readFile(policyAdapter, entity); } } } @@ -1085,7 +1053,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } public static Map convert(String str, String split) { - Map map = new HashMap(); + Map map = new HashMap<>(); for(final String entry : str.split(split)) { String[] parts = entry.split("="); map.put(parts[0], parts[1]); @@ -1112,14 +1080,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { policyAdapter.setServiceType(msBody.getService()); } if(msBody.getContent() != null){ - LinkedHashMap data = new LinkedHashMap(); + LinkedHashMap data = new LinkedHashMap<>(); LinkedHashMap map = (LinkedHashMap) msBody.getContent(); readRecursivlyJSONContent(map, data); policyAdapter.setRuleData(data); } } catch (Exception e) { - logger.error(e); + LOGGER.error(e); } } @@ -1130,7 +1098,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { Object key = iterator.next(); Object value = map.get(key); if(value instanceof LinkedHashMap){ - LinkedHashMap secondObjec = new LinkedHashMap(); + LinkedHashMap secondObjec = new LinkedHashMap<>(); readRecursivlyJSONContent((LinkedHashMap) value, secondObjec); for(String objKey: secondObjec.keySet()){ data.put(key+"." +objKey, secondObjec.get(objKey)); @@ -1140,7 +1108,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { for(int i = 0; i < jsonArrayVal.size(); i++){ Object arrayvalue = jsonArrayVal.get(i); if(arrayvalue instanceof LinkedHashMap){ - LinkedHashMap newData = new LinkedHashMap(); + LinkedHashMap newData = new LinkedHashMap<>(); readRecursivlyJSONContent((LinkedHashMap) arrayvalue, newData); for(String objKey: newData.keySet()){ data.put(key+"@"+i+"." +objKey, newData.get(objKey)); @@ -1177,7 +1145,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { //Convert the map values and set into JSON body public Map convertMap(Map attributesMap, Map attributesRefMap) { - Map attribute = new HashMap(); + Map attribute = new HashMap<>(); String temp = null; String key; String value; @@ -1242,12 +1210,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } }catch(Exception e){ - logger.error("Upload error : " + e); + LOGGER.error("Upload error : " + e); } } } - List fileList = new ArrayList();; + List fileList = new ArrayList<>();; this.directory = "model"; if (zip){ extractFolder(this.newFile); @@ -1262,7 +1230,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if(yml==false){ modelType="xmi"; //Process Main Model file first - classMap = new HashMap(); + classMap = new HashMap<>(); for (File file : fileList) { if(!file.isDirectory() && file.getName().endsWith(".xmi")){ retreiveDependency(file.toString(), true); @@ -1280,25 +1248,30 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { MSAttributeObject msAttributes= new MSAttributeObject(); msAttributes.setClassName(className); - HashMap returnAttributeList =new HashMap(); + HashMap returnAttributeList =new HashMap<>(); returnAttributeList.put(className, this.attributeString); msAttributes.setAttribute(returnAttributeList); msAttributes.setSubClass(this.retmap); - HashMap returnReferenceList =new HashMap(); + HashMap returnReferenceList =new HashMap<>(); //String[] referenceArray=this.referenceAttributes.split("="); returnReferenceList.put(className, this.referenceAttributes); msAttributes.setRefAttribute(returnReferenceList); if(this.listConstraints!=""){ - HashMap enumList =new HashMap(); - String[] listArray=this.listConstraints.split("="); - enumList.put(listArray[0], listArray[1]); + HashMap 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(); + classMap=new HashMap<>(); classMap.put(className, msAttributes); } @@ -1325,7 +1298,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); @@ -1363,19 +1336,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 tempMap = new HashMap(); + MSModelUtils utils = new MSModelUtils(PolicyController.getMsEcompName(), PolicyController.getMsPolicyName()); + HashMap tempMap = new HashMap<>(); tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI); classMap.putAll(tempMap); - logger.info(tempMap); + LOGGER.info(tempMap); return; @@ -1383,7 +1363,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { private List listModelFiles(String directoryName) { File directory = new File(directoryName); - List resultList = new ArrayList(); + List resultList = new ArrayList<>(); File[] fList = directory.listFiles(); for (File file : fList) { if (file.isFile()) { @@ -1401,7 +1381,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); } } } @@ -1415,7 +1395,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } private List createList() { - List list = new ArrayList(); + List list = new ArrayList<>(); for (Entry cMap : classMap.entrySet()){ if (cMap.getValue().isPolicyTempalate()){ list.add(cMap.getKey()); @@ -1433,23 +1413,31 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { return list; } + public Map getAttributesListRefMap() { + return attributesListRefMap; + } + + public Map> 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;