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=777fb89e378b8a910a70ce8b57db26844195a5cc;hb=e92ff832cf993db876f22b2d27562fedf59f5043;hp=e156002bf5f4156d29cd9495774dfeb2c7ef23a6;hpb=570290dc6ba8198e653022c2f6f8e5d01cfa8d1b;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 e156002bf..777fb89e3 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 @@ -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; @@ -160,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; @@ -224,7 +225,7 @@ 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); String cleanJson = cleanUPJson(json); @@ -254,7 +255,7 @@ 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; } @@ -311,7 +312,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { public Map load(byte[] source) throws IOException { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") - Map yamlMap = (Map) yaml.load(source.toString()); + Map yamlMap = (Map) yaml.load(Arrays.toString(source)); StringBuilder sb = new StringBuilder(); Map settings = new HashMap <>(); if (yamlMap == null) { @@ -397,10 +398,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { HashMap dataMapForJson=new HashMap <>(); for(String uniqueDataKey: uniqueDataKeys){ if(uniqueDataKey.contains("%")){ - String[] uniqueDataKeySplit= uniqueDataKey.split("%",2); - if (uniqueDataKeySplit.length < 2) { - continue; - } + String[] uniqueDataKeySplit= uniqueDataKey.split("%"); String findType=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+TYPE; String typeValue=map.get(findType); LOGGER.info(typeValue); @@ -476,10 +474,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { HashMap hmSub; for(Map.Entry entry: dataMapForJson.entrySet()){ String uniqueDataKey= entry.getKey(); - String[] uniqueDataKeySplit=uniqueDataKey.split("%",2); - if (uniqueDataKeySplit.length < 2) { - continue; - } + String[] uniqueDataKeySplit=uniqueDataKey.split("%"); String value= dataMapForJson.get(uniqueDataKey); if(dataMapKey.containsKey(uniqueDataKeySplit[0])){ hmSub = dataMapKey.get(uniqueDataKeySplit[0]); @@ -743,10 +738,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { 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(); } @@ -1231,18 +1223,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } } - private String getPolicyScope(String value) { - GroupPolicyScopeList pScope = new GroupPolicyScopeList(); - List 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 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