From e44a43f3dbb1dbaa182122f66961c55d3b96b824 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 23 Jan 2018 19:39:07 -0500 Subject: Reduce technical debt Mainly use StringBuilder() to improve speed * Use StringBuilder * Remove superflous exceptions in constructor * Remove unnecessary casts * Remove unnecessary toString() * Combine return into one statement * Move string literal to LHS Issue-ID: POLICY-482 Change-Id: Id196728d92dda7fab7e83d6eea07633c5be37f7c Signed-off-by: Pamela Dragosh --- .../onap/policy/admin/PolicyManagerServlet.java | 18 +++--- .../onap/policy/admin/PolicyRestController.java | 6 +- .../org/onap/policy/admin/RESTfulPAPEngine.java | 6 +- .../policy/components/HumanPolicyComponent.java | 55 ++++++++++--------- .../CreateClosedLoopFaultController.java | 64 +++++++++++----------- .../CreateDcaeMicroServiceController.java | 24 ++++---- .../controller/CreateFirewallController.java | 4 +- .../policy/controller/DashboardController.java | 7 +-- .../controller/PolicyNotificationController.java | 6 +- .../policy/controller/PolicyRolesController.java | 8 +-- 10 files changed, 98 insertions(+), 100 deletions(-) diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java index 91f82932e..1e6e3ef3a 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java @@ -248,7 +248,7 @@ public class PolicyManagerServlet extends HttpServlet { } } - JSONObject responseJsonObject = null; + JSONObject responseJsonObject; responseJsonObject = this.success(); response.setContentType(CONTENTTYPE); PrintWriter out = response.getWriter(); @@ -913,7 +913,6 @@ public class PolicyManagerServlet extends HttpServlet { policyParams.put("newPolicySplit_0", newPolicySplit[0]); List queryData = controller.getDataByQuery(policyEntityquery, policyParams); if(!queryData.isEmpty()){ - entity = (PolicyEntity) queryData.get(0); return error("Policy rename failed. Since, the policy with same name already exists."); } @@ -925,20 +924,21 @@ public class PolicyManagerServlet extends HttpServlet { params.put("oldPolicySplit_0", oldPolicySplit[0]); List oldEntityData = controller.getDataByQuery(oldpolicyEntityquery, params); if(!oldEntityData.isEmpty()){ - String groupQuery = "FROM PolicyGroupEntity where ("; + StringBuilder groupQuery = new StringBuilder(); + groupQuery.append("FROM PolicyGroupEntity where ("); SimpleBindings geParams = new SimpleBindings(); for(int i=0; i groupEntityData = controller.getDataByQuery(groupQuery, geParams); + groupQuery.append(")"); + List groupEntityData = controller.getDataByQuery(groupQuery.toString(), geParams); if(! groupEntityData.isEmpty()){ return error("Policy rename failed. Since the policy or its version is active in PDP Groups."); } @@ -1478,7 +1478,7 @@ public class PolicyManagerServlet extends HttpServlet { String path = params.getString("path"); try{ if(params.has("subScopename")){ - if(!params.getString("subScopename").equals("")){ + if(! "".equals(params.getString("subScopename"))) { name = params.getString("path").replace("/", File.separator) + File.separator +params.getString("subScopename"); } }else{ @@ -1501,7 +1501,7 @@ public class PolicyManagerServlet extends HttpServlet { } } LOGGER.debug("addFolder path: {} name: {}" + path +name); - if(!name.equals("")){ + if(! "".equals(name)){ if(name.startsWith(File.separator)){ name = name.substring(1); } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java index 672177d9b..d930a6d7a 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java @@ -372,7 +372,7 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/getDictionary/*"}, method={RequestMethod.GET}) public void getDictionaryController(HttpServletRequest request, HttpServletResponse response){ String uri = request.getRequestURI().replace("/getDictionary", ""); - String body = null; + String body; ResponseEntity responseEntity = sendToPAP(null, uri, HttpMethod.GET); if(responseEntity != null){ body = responseEntity.getBody().toString(); @@ -428,7 +428,7 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/searchDictionary"}, method={RequestMethod.POST}) public ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { - Object resultList = null; + Object resultList; String uri = request.getRequestURI(); if(uri.startsWith("/")){ uri = uri.substring(uri.indexOf('/')+1); @@ -461,7 +461,7 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/searchPolicy"}, method={RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ - Object resultList = null; + Object resultList; String uri = request.getRequestURI()+"?action=search"; if(uri.startsWith("/")){ uri = uri.substring(uri.indexOf('/')+1); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java index 40917bc81..0e7c0561e 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java @@ -81,7 +81,7 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP * Set up link with PAP Servlet and get our initial set of Groups * @throws Exception */ - public RESTfulPAPEngine (String myURLString) throws PAPException, IOException { + public RESTfulPAPEngine (String myURLString) throws PAPException { // // Get our URL to the PAP servlet // @@ -358,9 +358,9 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP try { String fullURL = papServletURLString; if (parameters != null && parameters.length > 0) { - String queryString = ""; + StringBuilder queryString = new StringBuilder(); for (String p : parameters) { - queryString += "&" + p; + queryString.append("&" + p); } fullURL += "?" + queryString.substring(1); } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java index aa9ec7ab9..512901d4f 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java @@ -689,7 +689,7 @@ class HtmlProcessor extends SimpleCallback { if (anyOfList != null) { Iterator iterAnyOf = anyOfList.iterator(); - String targetInHuman = ""; + StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List allOfList = anyOf.getAllOf(); @@ -701,7 +701,7 @@ class HtmlProcessor extends SimpleCallback { if (matchList != null) { Iterator iterMatch = matchList.iterator(); if (matchList.size() > 1) - targetInHuman += "("; + targetInHuman.append("("); while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); // @@ -740,7 +740,7 @@ class HtmlProcessor extends SimpleCallback { attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier,ai); - targetInHuman += "" + succintIdentifier + " " + functionName + " "; + targetInHuman.append("" + succintIdentifier + " " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; @@ -752,38 +752,39 @@ class HtmlProcessor extends SimpleCallback { int countValues = 0; for (Object o : value_s) { countValues++; - targetInHuman += " " + o + ""; + targetInHuman.append(" " + o + ""); if (countValues < numValues) { - targetInHuman += ", or"; + targetInHuman.append(", or"); } } } else { - targetInHuman += " " + v.getValue() + ""; + targetInHuman.append(" " + v.getValue() + ""); if (count < numAttributes) { - targetInHuman += ", or "; + targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { - targetInHuman += " and "; + targetInHuman.append(" and "); } } // end iterMatch if (matchList.size() > 1) { - targetInHuman += ")"; + targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { - targetInHuman += " or "; + targetInHuman.append(" or "); } } // end iterAllOf } if (iterAnyOf.hasNext()) { - targetInHuman = "(" + targetInHuman + ")" + " or "; + targetInHuman = new StringBuilder(); + targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { - targetInHuman += ")"; + targetInHuman.append(")"); } } } // end iterAnyOf @@ -857,17 +858,17 @@ class HtmlProcessor extends SimpleCallback { if (exps == null || exps.isEmpty()) return ""; else { - String forResult = ""; + StringBuilder forResult = new StringBuilder(); for (JAXBElement e : exps) { Object v = e.getValue(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("one-and-only children: " + v); } if (v != null) { - forResult += stringifyExpression(v); + forResult.append(stringifyExpression(v)); } } - return forResult; + return forResult.toString(); } } @@ -882,20 +883,20 @@ class HtmlProcessor extends SimpleCallback { if (LOGGER.isDebugEnabled()) { LOGGER.debug(functionName + " 1 expression: " + numExpr); } - String applySubresult = ""; + StringBuilder applySubresult = new StringBuilder(); for (JAXBElement e : apply.getExpression()) { Object v = e.getValue(); if (v != null) { - applySubresult += this.stringifyExpression(e.getValue()); + applySubresult.append(this.stringifyExpression(e.getValue())); } } - return " " + removePrimitives(functionName) + " (" + applySubresult + ")"; + return " " + removePrimitives(functionName) + " (" + applySubresult.toString() + ")"; } else { // > 1 arguments if (LOGGER.isDebugEnabled()) { LOGGER.debug(functionName + " > 1 expressions: " + numExpr); } - String applySubresult = ""; + StringBuilder applySubresult = new StringBuilder(); int exprCount = 0; for (JAXBElement e : apply.getExpression()) { exprCount++; @@ -903,20 +904,20 @@ class HtmlProcessor extends SimpleCallback { if (ev != null) { if (ev instanceof ApplyType) { if (((ApplyType) ev).getFunctionId().contains("one-and-only")) { - applySubresult += this.stringifyExpression(e.getValue()); + applySubresult.append(this.stringifyExpression(e.getValue())); } else { - applySubresult += "(" + this.stringifyExpression(e.getValue()) + ")"; + applySubresult.append("(" + this.stringifyExpression(e.getValue()) + ")"); } } else { - applySubresult += this.stringifyExpression(e.getValue()); + applySubresult.append(this.stringifyExpression(e.getValue())); } if (exprCount < numExpr) { - applySubresult += " " + removePrimitives(functionName) + " "; + applySubresult.append(" " + removePrimitives(functionName) + " "); } } } - return applySubresult; + return applySubresult.toString(); } } if (expression instanceof AttributeDesignatorType) { @@ -951,11 +952,11 @@ class HtmlProcessor extends SimpleCallback { if (expression instanceof AttributeValueType) { AttributeValueType avt = (AttributeValueType) expression; List content = avt.getContent(); - String value_s = ""; + StringBuilder value_s = new StringBuilder(); for (Object o: content) { - value_s += " " + o.toString(); + value_s.append(" " + o.toString()); } - return " " + value_s; + return " " + value_s.toString(); } if (expression instanceof VariableReferenceType) { // diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java index 839a79f29..8ce32670f 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java @@ -93,21 +93,21 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ faultSignatureDatas.add(faultDatas); } - String resultBody = ""; + StringBuilder resultBody = new StringBuilder(); if(!policyJsonData.getConnecttriggerSignatures().isEmpty()){ - resultBody = resultBody + "("; + resultBody.append("("); for(int i = policyJsonData.getConnecttriggerSignatures().size()-1; i>=0 ; i--){ String connectBody = connectTriggerSignature(i, policyJsonData.getConnecttriggerSignatures(), trapSignatureDatas.get(0)); - resultBody = resultBody + connectBody; + resultBody.append(connectBody); } - resultBody = resultBody + ")"; + resultBody.append(resultBody + ")"); }else{ if(!trapSignatureDatas.isEmpty()){ - resultBody = callTrap("nill", trapSignatureDatas.get(0)); + resultBody.append(callTrap("nill", trapSignatureDatas.get(0))); } } ClosedLoopSignatures triggerSignatures = new ClosedLoopSignatures(); - triggerSignatures.setSignatures(resultBody); + triggerSignatures.setSignatures(resultBody.toString()); if(policyData.getClearTimeOut() != null){ triggerSignatures.setTimeWindow(Integer.parseInt(policyData.getClearTimeOut())); triggerSignatures.setTrapMaxAge(Integer.parseInt(policyData.getTrapMaxAge())); @@ -124,21 +124,21 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } jsonBody.setTriggerSignatures(triggerSignatures); - String faultBody = ""; + StringBuilder faultBody = new StringBuilder(); if(!policyJsonData.getConnectVerificationSignatures().isEmpty()){ - faultBody = faultBody + "("; + faultBody.append("("); for(int i = policyJsonData.getConnectVerificationSignatures().size()-1; i>=0 ; i--){ String connectBody = connectTriggerSignature(i, policyJsonData.getConnectVerificationSignatures(), faultSignatureDatas.get(0)); - faultBody = faultBody + connectBody; + faultBody.append(connectBody); } - faultBody = faultBody + ")"; + faultBody.append(")"); }else{ if(!faultSignatureDatas.isEmpty()){ - faultBody = callTrap("nill", faultSignatureDatas.get(0)); + faultBody.append(callTrap("nill", faultSignatureDatas.get(0))); } } ClosedLoopSignatures faultSignatures = new ClosedLoopSignatures(); - faultSignatures.setSignatures(faultBody); + faultSignatures.setSignatures(faultBody.toString()); if(policyData.getVerificationclearTimeOut() != null){ faultSignatures.setTimeWindow(Integer.parseInt(policyData.getVerificationclearTimeOut())); ClosedLoopFaultTriggerUISignatures uifaultSignatures = new ClosedLoopFaultTriggerUISignatures(); @@ -166,31 +166,31 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ @SuppressWarnings("unchecked") private String connectTriggerSignature(int index, ArrayList triggerSignatures, Object object) { - String resultBody = ""; + StringBuilder resultBody = new StringBuilder(); Map connectTraps = (Map) triggerSignatures.get(index); try{ String notBox = ""; if(connectTraps.keySet().contains("notBox")){ notBox = connectTraps.get("notBox"); } - resultBody = resultBody + "(" + notBox; + resultBody.append("(" + notBox); }catch(NullPointerException e){ policyLogger.info("General error" , e); - resultBody = resultBody + "("; + resultBody.append("("); } String connectTrap1 = connectTraps.get("connectTrap1"); if(connectTrap1.startsWith("Trap") || connectTrap1.startsWith("Fault")){ String trapBody = callTrap(connectTrap1, object); if(trapBody!=null){ - resultBody = resultBody + trapBody; + resultBody.append(trapBody); } }else if(connectTrap1.startsWith("C")){ for(int i=0; i<= triggerSignatures.size(); i++){ Map triggerSignature = (Map) triggerSignatures.get(i); if(triggerSignature.get("id").equals(connectTrap1)){ - resultBody = resultBody + "("; + resultBody.append("("); String connectBody = connectTriggerSignature(i, triggerSignatures, object); - resultBody = resultBody + connectBody + ")"; + resultBody.append(connectBody + ")"); }else{ i++; } @@ -198,13 +198,13 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } try{ String trapCount1 = connectTraps.get("trapCount1"); - resultBody = resultBody + ", Time = " + trapCount1 + ")"; + resultBody.append(", Time = " + trapCount1 + ")"); }catch(NullPointerException e){ policyLogger.info("General error" , e); } try{ String operatorBox = connectTraps.get("operatorBox"); - resultBody = resultBody + operatorBox +"("; + resultBody.append(operatorBox +"("); }catch (NullPointerException e){ policyLogger.info("General error" , e); } @@ -213,15 +213,15 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ if(connectTrap2.startsWith("Trap") || connectTrap2.startsWith("Fault")){ String trapBody = callTrap(connectTrap2, object); if(trapBody!=null){ - resultBody = resultBody + trapBody; + resultBody.append(trapBody); } }else if(connectTrap2.startsWith("C")){ for(int i=0; i<= triggerSignatures.size(); i++){ Map triggerSignature = (Map) triggerSignatures.get(i); if(triggerSignature.get("id").equals(connectTrap2)){ - resultBody = resultBody + "("; + resultBody.append("("); String connectBody = connectTriggerSignature(i, triggerSignatures, object); - resultBody = resultBody + connectBody + ")"; + resultBody.append(connectBody + ")"); }else{ i++; } @@ -232,11 +232,11 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } try{ String trapCount2 = connectTraps.get("trapCount2"); - resultBody = resultBody + ", Time = " + trapCount2 + ")"; + resultBody.append(", Time = " + trapCount2 + ")"); }catch(NullPointerException e){ policyLogger.info("General error" , e); } - return resultBody; + return resultBody.toString(); } @@ -379,7 +379,7 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ //connect traps data set to JSON Body as String @SuppressWarnings({ "unchecked", "rawtypes" }) private String getUIConnectTraps(ArrayList connectTrapSignatures) { - String resultBody = ""; + StringBuilder resultBody = new StringBuilder(); String connectMainBody = ""; for(int j = 0; j < connectTrapSignatures.size(); j++){ Map connectTraps = (Map)connectTrapSignatures.get(j); @@ -412,7 +412,7 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } connectBody = notBox + "@!" + connectTrap1 + "@!" + trapCount1 + "@!" + operatorBox + "@!" + connectTrap2 + "@!" + trapCount2 + "#!?!"; } - resultBody = resultBody + connectBody; + resultBody.append(connectBody); } connectMainBody = connectMainBody + resultBody; return connectMainBody; @@ -423,7 +423,7 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ // get Trigger signature from JSON body @SuppressWarnings({ "rawtypes", "unchecked" }) private String getUITriggerSignature(String trap, Object object2) { - String triggerBody = ""; + StringBuilder triggerBody = new StringBuilder(); TrapDatas trapDatas = (TrapDatas) object2; ArrayList attributeList = new ArrayList<>(); // Read the Trap @@ -470,7 +470,7 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } for(int j = 0; j < attributeList.size(); j++){ - String signatureBody = ""; + StringBuilder signatureBody = new StringBuilder(); ArrayList connectTraps = (ArrayList) attributeList.get(j); for(int i =0 ; i < connectTraps.size(); i++){ String connectBody = ""; @@ -494,12 +494,12 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController{ } connectBody = notBox + "@!" + trigger1 + "@!" + operatorBox + "@!" + trigger2 + "#!"; } - signatureBody = signatureBody + connectBody; + signatureBody.append(connectBody); } - triggerBody = triggerBody + signatureBody + "?!"; + triggerBody.append(signatureBody + "?!"); } - return triggerBody; + return triggerBody.toString(); } public void prePopulateClosedLoopFaultPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index e9a121b97..d8ccd9a02 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -189,8 +189,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } private GroupPolicyScopeList getPolicyObject(String policyScope) { - GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope); - return groupList; + return (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope); } private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent, String dummyValue) { @@ -1099,7 +1098,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class); JSONObject object = new JSONObject(); - JSONArray array = new JSONArray(); + JSONArray array; for (Entry keySet : attributeMap.entrySet()){ array = new JSONArray(); @@ -1140,10 +1139,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { @SuppressWarnings("unchecked") private JSONObject recursiveReference(String name, Map subAttributeMap, String enumAttribute) { JSONObject object = new JSONObject(); - Map map = new HashMap<>(); + Map map; Object returnClass = subAttributeMap.get(name); map = (Map) returnClass; - JSONArray array = new JSONArray(); + JSONArray array; for( Entry m:map.entrySet()){ String[] splitValue = m.getValue().split(":"); @@ -1258,7 +1257,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); String value = root.get("policyData").toString().replaceAll("^\"|\"$", ""); - String servicename = value.toString().split("-v")[0]; + String servicename = value.split("-v")[0]; Set returnList = getVersionList(servicename); response.setCharacterEncoding("UTF-8"); @@ -1274,7 +1273,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } private Set getVersionList(String name) { - MicroServiceModels workingModel = new MicroServiceModels(); + MicroServiceModels workingModel; Set list = new HashSet<>(); List microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name); for (int i = 0; i < microServiceModelsData.size(); i++) { @@ -1426,7 +1425,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { String policyScopeName = null; ObjectMapper mapper = new ObjectMapper(); try { - DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class); + DCAEMicroServiceObject msBody = mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class); policyScopeName = getPolicyScope(msBody.getPolicyScope()); policyAdapter.setPolicyScope(policyScopeName); @@ -1500,7 +1499,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { //Convert the map values and set into JSON body public Map convertMap(Map attributesMap, Map attributesRefMap) { Map attribute = new HashMap<>(); - String temp = null; + StringBuilder temp = null; String key; String value; for (Entry entry : attributesMap.entrySet()) { @@ -1523,9 +1522,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { temp = null; for (Object textList : arrayList.getValue()){ if (temp == null){ - temp = "[" + textList; + temp = new StringBuilder(); + temp.append("[" + textList); }else{ - temp = temp + "," + textList; + temp.append("," + textList); } } attribute.put(key, temp+ "]"); @@ -1727,7 +1727,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { private void retreiveDependency(String workingFile, Boolean modelClass) { MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName()); - HashMap tempMap = new HashMap<>(); + HashMap tempMap; tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java index 5b34db455..f0681a388 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java @@ -122,7 +122,7 @@ public class CreateFirewallController extends RestrictedBaseController { String jsonBody=""; termCollectorList = new ArrayList <>(); tagCollectorList = new ArrayList <>(); - if(policyData.getAttributes().size() > 0){ + if(! policyData.getAttributes().isEmpty()){ for(Object attribute : policyData.getAttributes()){ if(attribute instanceof LinkedHashMap){ String key = ((LinkedHashMap) attribute).get("key").toString(); @@ -321,7 +321,7 @@ public class CreateFirewallController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyRestAdapter policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); - if(policyData.getAttributes().size() > 0){ + if(! policyData.getAttributes().isEmpty()){ for(Object attribute : policyData.getAttributes()){ if(attribute instanceof LinkedHashMap){ String key = ((LinkedHashMap) attribute).get("key").toString(); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java index 901b5929f..6679b8954 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java @@ -194,7 +194,6 @@ public class DashboardController extends RestrictedBaseController{ PolicyController controller = getPolicyControllerInstance(); Set groups = controller.getPapEngine().getOnapPDPGroups(); if (groups == null) { - papStatus = "UNKNOWN"; throw new PAPException("PAP not running"); }else { papStatus = "IS_OK"; @@ -281,8 +280,7 @@ public class DashboardController extends RestrictedBaseController{ private long getRequestCounts(String host, int port, String jmxAttribute) { policyLogger.debug("Create an RMI connector client and connect it to the JMX connector server"); - HashMap map = new HashMap(); - map = null; + HashMap map = null; JMXConnector jmxConnection; try { jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); @@ -383,8 +381,7 @@ public class DashboardController extends RestrictedBaseController{ @SuppressWarnings({ "rawtypes", "unchecked" }) private Object getPolicy(String host, int port, String jmxAttribute){ policyLogger.debug("Create an RMI connector client and connect it to the JMX connector server for Policy: " + host); - HashMap map = new HashMap(); - map = null; + HashMap map = null; JMXConnector jmxConnection; try { jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java index 845b5f5a7..1a13d1d37 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java @@ -60,7 +60,7 @@ public class PolicyNotificationController extends RestrictedBaseController { @RequestMapping(value={"/watchPolicy"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView watchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ - String path = ""; + StringBuilder path = new StringBuilder(); String responseValue = ""; try { String userId = UserUtils.getUserSession(request).getOrgUserId(); @@ -76,9 +76,9 @@ public class PolicyNotificationController extends RestrictedBaseController { for (int i = 0; i < arrayNode.size(); i++) { JsonNode individualElement = arrayNode.get(i); if(i == 0){ - path = path + individualElement.toString().replace("\"", "").trim(); + path.append(individualElement.toString().replace("\"", "").trim()); }else{ - path = path + File.separator + individualElement.toString().replace("\"", "").trim(); + path.append(File.separator + individualElement.toString().replace("\"", "").trim()); } } } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java index a30acc383..4b966154c 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java @@ -81,7 +81,7 @@ public class PolicyRolesController extends RestrictedBaseController{ @RequestMapping(value={"/save_NonSuperRolesData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView SaveRolesEntityData(HttpServletRequest request, HttpServletResponse response){ try{ - String scopeName = null; + StringBuilder scopeName = new StringBuilder(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String userId = UserUtils.getUserSession(request).getOrgUserId(); @@ -89,9 +89,9 @@ public class PolicyRolesController extends RestrictedBaseController{ ReadScopes adapter = mapper.readValue(root.get("editRoleData").toString(), ReadScopes.class); for(int i = 0; i < adapter.getScope().size(); i++){ if(i == 0){ - scopeName = adapter.getScope().get(0); + scopeName.append(adapter.getScope().get(0)); }else{ - scopeName = scopeName + "," + adapter.getScope().get(i); + scopeName.append("," + adapter.getScope().get(i)); } } LOGGER.info("****************************************Logging UserID for Roles Function********************************************************"); @@ -101,7 +101,7 @@ public class PolicyRolesController extends RestrictedBaseController{ roles.setId(adapter.getId()); roles.setLoginId(adapter.getLoginId()); roles.setRole(adapter.getRole()); - roles.setScope(scopeName); + roles.setScope(scopeName.toString()); commonClassDao.update(roles); response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); -- cgit 1.2.3-korg