From 142ae9408466e78a4509490eb9ffe8bbc19f634a Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Fri, 25 May 2018 13:25:26 -0500 Subject: [PATCH] Sonar fixes for TOSCA Parser I fixed the sonar blocker in regards to nullPointerException and few other majors that I found and were easy to fix. I ran my local sonar and the blocker was removed after the changes. Change-Id: I7dcd7584fc955e1b520235a8e1376cf871761d21 Issue-ID: POLICY-776 Signed-off-by: Michael Mokry --- .../java/org/onap/policy/rest/util/MSModelUtils.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java index 1a62ccc88..1f40be60a 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java @@ -35,6 +35,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; + import java.util.Map.Entry; import org.apache.commons.lang.StringUtils; @@ -1036,7 +1037,6 @@ public class MSModelUtils { logger.info(mainObject); logger.info("###############################################################################"); } - LinkedHashMap parseDataNodes(LinkedHashMap map){ LinkedHashMap dataMapForJson=new LinkedHashMap <>(); matchableValues = new HashMap <>(); @@ -1098,9 +1098,9 @@ public class MSModelUtils { else{ StringBuilder stringListItems= new StringBuilder(); if(LIST.equalsIgnoreCase(typeValue)){ - stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+":required-"+requiredValue +":MANY-false"); + stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+REQUIREDVALUE+requiredValue +MANYFALSE); }else if( MAP.equalsIgnoreCase(typeValue)){ - stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+":required-"+requiredValue +":MANY-true"); + stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+REQUIREDVALUE+requiredValue +MANYTRUE); } dataMapForJson.put(uniqueDataKey, stringListItems.toString()); boolean isConstraintsFound = false; @@ -1109,7 +1109,8 @@ public class MSModelUtils { logger.info("findConstraints => " + findConstraints); String constraintsValue=map.get(findConstraints); logger.info("constraintsValue => " + constraintsValue); - if((constraintsValue==null || constraintsValue.isEmpty()) && i==0){ //if no constraints at all ( index i as 0 can tell this ) + + if((constraintsValue==null || constraintsValue.isEmpty()) && i==0){ //if no constraints at all ( index i as 0 can tell this ) isConstraintsFound = false; //if type is list but no constraints String newValue = dataMapForJson.get(uniqueDataKey).replace("MANY-false", "MANY-true"); @@ -1121,10 +1122,13 @@ public class MSModelUtils { if(i == 0){ // only need to add one time for the same attribute dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase()+"=["); } - - if(constraintsValue.contains("=")){ + + if(constraintsValue==null){ + constraintsValue = ""; + }else if (constraintsValue.contains("=")) { constraintsValue = constraintsValue.replace("=", "equal-sign"); } + dataConstraints.add(constraintsValue); dataListBuffer.append(constraintsValue+","); } -- 2.16.6