summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-audit/provider
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-26 11:28:58 +0100
committerPatrick Brady <pb071s@att.com>2018-02-26 19:10:51 +0000
commit23e0901d5ba71ebadfb99e91d10bda0275708518 (patch)
treeb5e8868515adb7cb1fc2cd912306c6bd87b700b9 /appc-config/appc-config-audit/provider
parent0c712bb997cb5e5482a322d3deef107bd30f5d8e (diff)
CompareNode sonar fixes
Change-Id: Ia467508aa17737caa056b5ed0b6dd28ee4c01a35 Issue-ID: APPC-670 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-config/appc-config-audit/provider')
-rw-r--r--appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareNode.java109
1 files changed, 41 insertions, 68 deletions
diff --git a/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareNode.java b/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareNode.java
index 7ab5829b1..2c4706d6e 100644
--- a/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareNode.java
+++ b/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareNode.java
@@ -25,118 +25,91 @@
package org.onap.sdnc.config.audit.node;
-import java.util.HashMap;
-import java.util.Map;
-
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.util.HashMap;
+import java.util.Map;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-public class CompareNode implements SvcLogicJavaPlugin
-{
+public class CompareNode implements SvcLogicJavaPlugin {
private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareNode.class);
- public void compare( Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException
- {
+ public void compare(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
log.debug("Starting Compare Node Analysis");
- HashMap<String, String> status = new HashMap<String, String>();
+ Map<String, String> status = new HashMap<>();
Parameters params = new Parameters(inParams);
- try
- {
- if(params.getCompareDataType() != null)
- {
- if(params.getPayloadX() !=null && params.getPayloadY() !=null)
- {
+ try {
+ if (params.getCompareDataType() != null) {
+ if (params.getPayloadX() != null && params.getPayloadY() != null) {
status = getCompareResults(params);
log.debug("Compare Result : " + status);
- }
- else
- {
+ } else {
status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
status.put(CompareConstants.ERROR_CODE, "200");
status.put(CompareConstants.ERROR_MESSAGE, "One of the Data Received by CompareNode is Empty");
}
- }
- else
- {
+ } else {
status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
status.put(CompareConstants.ERROR_CODE, "200");
- status.put(CompareConstants.ERROR_MESSAGE, "Missing compareDataType value in input request: Expecting at least one of CLI/RESTCONF/XML");
+ status.put(CompareConstants.ERROR_MESSAGE,
+ "Missing compareDataType value in input request: Expecting at least one of CLI/RESTCONF/XML");
}
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
status.put(CompareConstants.ERROR_CODE, "200");
status.put(CompareConstants.ERROR_MESSAGE, CompareConstants.ERROR_MESSAGE_DETAIL);
- log.debug("Error in Comapre Node Execution " + e.getMessage());
-
+ log.debug("Error in Comapre Node Execution", e);
}
-
- createContextReposne(status, ctx, params.getRequestIdentifier());
+ createContextResponse(status, ctx, params.getRequestIdentifier());
}
- private HashMap<String, String> getCompareResults(Parameters params) throws Exception
- {
- HashMap<String, String> resultMap = new HashMap<String, String>();
- boolean cmpResult = false;
+ private HashMap<String, String> getCompareResults(Parameters params) throws Exception {
+ HashMap<String, String> resultMap = new HashMap<>();
+ boolean cmpResult;
CompareDataInterface handler;
-
-
- if(params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON))
- handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
- else if((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
- || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
- || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML)))
- handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
- else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI))
- handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
- else
- {
- throw new Exception("Format " + params.getCompareDataType() + " not supported");
+ if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON)) {
+ handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
+ } else if ((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
+ || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
+ || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML))) {
+ handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
+ } else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI)) {
+ handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
+ } else {
+ throw new SvcLogicException("Format " + params.getCompareDataType() + " not supported");
}
- try
- {
+ try {
log.debug("Received Format to compare : " + params.getCompareDataType());
cmpResult = handler.compare();
- if(cmpResult)
- {
+ if (cmpResult) {
resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_SUCCESS);
- }
- else
- {
+ } else {
resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
resultMap.put(CompareConstants.ERROR_CODE, "500");
resultMap.put(CompareConstants.ERROR_MESSAGE, CompareConstants.NO_MATCH_MESSAGE);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
throw e;
}
-
- return resultMap;
+ return resultMap;
}
- private void createContextReposne(HashMap status, SvcLogicContext ctx, String requestIdentifier )
- {
- if(requestIdentifier == null)
- requestIdentifier = "";
- else
- requestIdentifier = requestIdentifier + ".";
+ private void createContextResponse(Map<String, String> status, SvcLogicContext ctx, String requestIdentifier) {
+ String requestId = requestIdentifier == null ? "" : requestIdentifier + ".";
- ctx.setAttribute(requestIdentifier.concat( CompareConstants.RESPONSE_STATUS), (String) status.get(CompareConstants.RESPONSE_STATUS));
- ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_CODE), (String) status.get(CompareConstants.ERROR_CODE));
- ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_MESSAGE), (String) status.get(CompareConstants.ERROR_MESSAGE));
+ ctx.setAttribute(requestId.concat(CompareConstants.RESPONSE_STATUS),
+ status.get(CompareConstants.RESPONSE_STATUS));
+ ctx.setAttribute(requestId.concat(CompareConstants.ERROR_CODE),
+ status.get(CompareConstants.ERROR_CODE));
+ ctx.setAttribute(requestId.concat(CompareConstants.ERROR_MESSAGE),
+ status.get(CompareConstants.ERROR_MESSAGE));
}
-
}