Merge "Fix issues reported by sonar"
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / util / PolicyValidation.java
index 2e685d4..0478f5f 100644 (file)
@@ -940,20 +940,25 @@ public class PolicyValidation {
                                                                responseString.append("Guard Params <b>Time Units</b> is Required" + HTML_ITALICS_LNBREAK);
                                                                valid = false;
                                                        }
-                                               }else if("GUARD_BL_YAML".equals(policyData.getRuleProvider())){
-                                                       if(policyData.getYamlparams().getBlackList()==null || policyData.getYamlparams().getBlackList().isEmpty()){
-                                                               responseString.append(" Guard Params <b>BlackList</b> is Required " + HTML_ITALICS_LNBREAK);
-                                                               valid = false;
-                                                       }else{
-                                                               for(String blackList: policyData.getYamlparams().getBlackList()){
-                                                                       if(blackList==null || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))){
-                                                                               responseString.append(" Guard Params <b>BlackList</b> Should be valid String" + HTML_ITALICS_LNBREAK);
-                                                                               valid = false;
-                                                                               break;
-                                                                       }
-                                                               }
-                                                       }
-                                               }
+                                               } else if ("GUARD_BL_YAML".equals(policyData.getRuleProvider())
+                                && "Use Manual Entry".equals(policyData.getBlackListEntryType())) {
+                            if (policyData.getYamlparams().getBlackList() == null
+                                    || policyData.getYamlparams().getBlackList().isEmpty()) {
+                                responseString
+                                        .append(" Guard Params <b>BlackList</b> is Required " + HTML_ITALICS_LNBREAK);
+                                valid = false;
+                            } else {
+                                for (String blackList : policyData.getYamlparams().getBlackList()) {
+                                    if (blackList == null
+                                            || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))) {
+                                        responseString.append(" Guard Params <b>BlackList</b> Should be valid String"
+                                                + HTML_ITALICS_LNBREAK);
+                                        valid = false;
+                                        break;
+                                    }
+                                }
+                            }
+                        }
                                        }
                                }
                        }
@@ -1085,9 +1090,11 @@ public class PolicyValidation {
                        final JsonNode value = field.getValue();
                        
                        if (value.isContainerNode() && !value.isArray()) {
+                               jsonRequestMap.put(key, "containerNode");
                                pullModelJsonKeyPairs(value); // RECURSIVE CALL
                        } else if (value.isArray()) {
                                try {
+                                       jsonRequestMap.put(key, "array");
                                        String stringValue = StringUtils.replaceEach(value.toString(), new String[]{"[", "]"}, new String[]{"",""});
                                        ObjectMapper mapper = new ObjectMapper();
                                        JsonNode newValue = mapper.readTree(stringValue);
@@ -1098,8 +1105,7 @@ public class PolicyValidation {
                        } else {
                                jsonRequestMap.put(key, value.toString().trim());
                        }
-               }
-                               
+               }                               
        }
        
     private JsonObject stringToJsonObject(String value) {