Sonar fixes for TOSCA Parser 75/49175/3
authorMichael Mokry <mm117s@att.com>
Fri, 25 May 2018 18:25:26 +0000 (13:25 -0500)
committerMichael Mokry <mm117s@att.com>
Fri, 25 May 2018 19:26:53 +0000 (14:26 -0500)
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 <mm117s@att.com>
ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java

index 1a62ccc..1f40be6 100644 (file)
@@ -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<String,String> parseDataNodes(LinkedHashMap<String,String> map){
                LinkedHashMap<String,String> 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+",");
                                                                }