From 1134bd40da28d3833a0dd4f821e75ec938f6061f Mon Sep 17 00:00:00 2001 From: rb7147 Date: Thu, 6 Sep 2018 16:36:22 -0400 Subject: Resolved XACML Platform Sonar issues Issue-ID: POLICY-902 Change-Id: If22627dfe7df993b5c725ddf3a66c10ebbaa73ca Signed-off-by: rb7147 --- .../policy/rest/adapter/PolicyRestAdapter.java | 16 +++--- .../org/onap/policy/rest/util/MSModelUtils.java | 59 +++++++++------------- 2 files changed, 33 insertions(+), 42 deletions(-) (limited to 'ONAP-REST/src') diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java index edadf53de..e3faaff88 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java @@ -129,14 +129,6 @@ public class PolicyRestAdapter { private String blackListEntryType; private String rawXacmlPolicy; - public String getRawXacmlPolicy() { - return rawXacmlPolicy; - } - - public void setRawXacmlPolicy(String rawXacmlPolicy) { - this.rawXacmlPolicy = rawXacmlPolicy; - } - // Rainy Day Decision private RainyDayParams rainyday; private Map rainydayMap; @@ -1145,4 +1137,12 @@ public class PolicyRestAdapter { public void setBlackListEntryType(String blackListEntryType) { this.blackListEntryType = blackListEntryType; } + + public String getRawXacmlPolicy() { + return rawXacmlPolicy; + } + + public void setRawXacmlPolicy(String rawXacmlPolicy) { + this.rawXacmlPolicy = rawXacmlPolicy; + } } 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 411ecaa26..0384d0b2c 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 @@ -172,11 +172,11 @@ public class MSModelUtils { addEnumClassMap(); } if (!matchingClass.isEmpty()){ - CheckForMatchingClass(); + checkForMatchingClass(); } } - private void CheckForMatchingClass() { + private void checkForMatchingClass() { HashMap tempAttribute = new HashMap<>(); for (Entry set : matchingClass.entrySet()){ @@ -194,14 +194,14 @@ public class MSModelUtils { } } - UpdateMatching(tempAttribute, key); + updateMatching(tempAttribute, key); } } - private void UpdateMatching(HashMap tempAttribute, String key) { + private void updateMatching(HashMap tempAttribute, String key) { Map newClass = classMap; for (Entry updateClass : newClass.entrySet()){ @@ -392,20 +392,14 @@ public class MSModelUtils { } public String checkRequiredPattern(int upper, int lower) { - String pattern = XACMLProperties.getProperty(XACMLRestProperties.PROP_XCORE_REQUIRED_PATTERN); - - if (pattern!=null){ - if (upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){ - return REQUIREDTRUE; - } + if (pattern!=null && upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){ + return REQUIREDTRUE; } - return REQUIREDFALSE; } public JSONObject buildJavaObject(Map map){ - return new JSONObject(map); } @@ -777,7 +771,7 @@ public class MSModelUtils { * For TOSCA Model */ public String parseTosca(String fileName) { - LinkedHashMap map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); try { map = load(fileName); if (map != null && map.get(ERROR) != null) { @@ -800,9 +794,9 @@ public class MSModelUtils { } @SuppressWarnings("unchecked") - public LinkedHashMap load(String fileName) throws IOException, ParserException { + public Map load(String fileName) throws IOException, ParserException { File newConfiguration = new File(fileName); - StringBuffer orderInfo = new StringBuffer("["); + StringBuilder orderInfo = new StringBuilder("["); Yaml yaml = new Yaml(); LinkedHashMap yamlMap = null; try (InputStream is = new FileInputStream(newConfiguration)) { @@ -810,6 +804,7 @@ public class MSModelUtils { } catch (FileNotFoundException e) { logger.error(e); } catch (Exception e) { + logger.error(e); throw new ParserException("Invalid TOSCA Model format. Please make sure it is a valid YAML file"); } @@ -828,8 +823,8 @@ public class MSModelUtils { findNode(yamlMap); - if (!isDuplicatedAttributes && orderedElements != null && orderedElements.size() > 0) { - orderedElements.stream().forEach((string) -> { + if (!isDuplicatedAttributes && orderedElements != null && !orderedElements.isEmpty()) { + orderedElements.stream().forEach(string -> { orderInfo.append(string); orderInfo.append(","); logger.info("Content: " + string); @@ -972,7 +967,7 @@ public class MSModelUtils { } - void parseDataAndPolicyNodes(LinkedHashMap map) { + void parseDataAndPolicyNodes(Map map) { for (String key : map.keySet()) { if (key.contains("policy.nodes.Root")) { continue; @@ -1061,7 +1056,7 @@ public class MSModelUtils { logger.info("###############################################################################"); } - LinkedHashMap parseDataNodes(LinkedHashMap map) { + LinkedHashMap parseDataNodes(Map map) { LinkedHashMap dataMapForJson = new LinkedHashMap<>(); matchableValues = new HashMap<>(); for (String uniqueDataKey : uniqueDataKeys) { @@ -1149,7 +1144,7 @@ public class MSModelUtils { if (constraintsValue == null) { break; } else { - System.out.println("constraintsValue => " + constraintsValue); + logger.info("constraintsValue => " + constraintsValue); if (constraintsValue.contains("=")) { constraintsValue = constraintsValue.replace("=", "equal-sign"); } @@ -1170,7 +1165,6 @@ public class MSModelUtils { + ".description"; String userDefinedValue = map.get(findUserDefined); String description = map.get(findDescription); - // String requiredValue = map.get(required); String trimValue = userDefinedValue.substring(userDefinedValue.lastIndexOf('.') + 1); StringBuilder referenceIndividualStringBuilder = new StringBuilder(); referenceIndividualStringBuilder.append(trimValue + REQUIREDVALUE); @@ -1246,9 +1240,9 @@ public class MSModelUtils { for (Map.Entry> entry : mapKey.entrySet()) { String keySetString = entry.getKey(); LinkedHashMap keyValues = mapKey.get(keySetString); - if (keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(STRING) - || keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(INTEGER) - || keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(BOOLEAN)) { + if (keyValues.get("type") != null && (STRING.equalsIgnoreCase(keyValues.get("type")) + || INTEGER.equalsIgnoreCase(keyValues.get("type")) + || BOOLEAN.equalsIgnoreCase(keyValues.get("type")))) { StringBuilder attributeIndividualStringBuilder = new StringBuilder(); attributeIndividualStringBuilder.append(keySetString + "="); attributeIndividualStringBuilder.append(keyValues.get("type") + DEFAULTVALUE); @@ -1256,15 +1250,14 @@ public class MSModelUtils { attributeIndividualStringBuilder.append(keyValues.get("required") + MANYFALSE); attributeIndividualStringBuilder.append(DESCRIPTION_TOKEN + keyValues.get(DESCRIPTION_KEY)); attributeStringBuilder.append(attributeIndividualStringBuilder + ","); - if (keyValues.get(MATCHABLEKEY) != null && keyValues.get(MATCHABLEKEY).equalsIgnoreCase("true")) { + if (keyValues.get(MATCHABLEKEY) != null && "true".equalsIgnoreCase(keyValues.get(MATCHABLEKEY))) { matchableValues.put(keySetString, MATCHINGTRUE); } } else if (LIST.equalsIgnoreCase(keyValues.get("type"))) { - if ("true".equalsIgnoreCase(keyValues.get(MATCHABLEKEY))) { matchableValues.put(keySetString, MATCHINGTRUE); } - // List Datatype + // List Data type Set keys = keyValues.keySet(); Iterator itr = keys.iterator(); boolean isDefinedType = false; @@ -1291,7 +1284,7 @@ public class MSModelUtils { } - if (!isDefinedType && LIST.equalsIgnoreCase(keyValues.get("type"))) { + if (!isDefinedType && LIST.equalsIgnoreCase(keyValues.get("type"))) { if (constraints == null || constraints.isEmpty()) { referenceStringBuilder.append(keySetString + "=MANY-true" + ","); } @@ -1313,7 +1306,7 @@ public class MSModelUtils { } } - if (constraints != null && constraints.isEmpty() == false) { + if (constraints != null && !constraints.isEmpty()) { // List handling. listBuffer.append(keySetString.toUpperCase() + "=["); for (String str : constraints) { @@ -1353,16 +1346,14 @@ public class MSModelUtils { if (key.equals(PROPERTIES_KEY) && value instanceof Map) { saveNodes((LinkedHashMap) value); if (isDuplicatedAttributes) { - orderedElements = new ArrayList(); + orderedElements = new ArrayList<>(); return; } } - if (!key.equals("policy.nodes.Root")) { + if (!"policy.nodes.Root".equals(key) && value instanceof Map) { // value is a Map object, then make a recursive call - if (value instanceof Map) { - findNode((LinkedHashMap) value); - } + findNode((LinkedHashMap) value); } }); -- cgit 1.2.3-korg