Fix sonar in policy/gui 87/121887/2
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Fri, 11 Jun 2021 20:01:27 +0000 (16:01 -0400)
committerRam Krishna Verma <ram_krishna.verma@bell.ca>
Mon, 14 Jun 2021 13:52:32 +0000 (09:52 -0400)
use "var" for local variables

Issue-ID: POLICY-3077
Change-Id: I6e31317bfda3d2b9bdde038cec709a3398f2f655
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandler.java
gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringServerParameterParser.java
gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/rest/PdpMonitoringRestResource.java

index dcf3988..0b777b6 100644 (file)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2020 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -823,7 +824,7 @@ public class ApexEditorRestResource implements RestCommandHandler {
     protected static int createCorruptSession() {
         final var apexEditorRestResource = new ApexEditorRestResource();
         final ApexApiResult result = apexEditorRestResource.createSession();
-        final int corruptSessionId = Integer.parseInt(result.getMessages().get(0));
+        final var corruptSessionId = Integer.parseInt(result.getMessages().get(0));
 
         SESSION_HANDLER.setCorruptSession(corruptSessionId);
 
index 6c34cc4..38c7fec 100644 (file)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +23,6 @@
 
 package org.onap.policy.gui.editors.apex.rest.handling;
 
-import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonObject;
 import java.util.ArrayList;
@@ -317,7 +317,7 @@ public class ModelHandler implements RestCommandHandler {
      * @return The list result, containing JSON augmented representations of objects stored in its "messages" array
      */
     private ApexApiResult addKeyInfo2Messages(final RestSession session, final ApexApiResult incomingResult) {
-        final ApexApiResult result = new ApexApiResult(incomingResult.getResult());
+        final var result = new ApexApiResult(incomingResult.getResult());
         result.setMessages(incomingResult.getMessages());
 
         final List<String> messages = incomingResult.getMessages();
@@ -344,7 +344,7 @@ public class ModelHandler implements RestCommandHandler {
      * @return the augmented message
      */
     private String addKeyInfo2Message(final RestSession session, final String message) {
-        final Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
+        final var gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
 
         var jsonObject = gson.fromJson(message, JsonObject.class);
         if (jsonObject == null) {
@@ -418,7 +418,7 @@ public class ModelHandler implements RestCommandHandler {
     private boolean setUuidAndDescription(final RestSession session, JsonObject jsonObject, String name,
         String version) {
         // Look up the key information for the name and version
-        JsonObject keyInfoJsonObject = lookupKeyInfo(session, name, version);
+        var keyInfoJsonObject = lookupKeyInfo(session, name, version);
         if (keyInfoJsonObject == null || keyInfoJsonObject.get(APEX_KEY_INFO) != null) {
             return false;
         }
@@ -456,7 +456,7 @@ public class ModelHandler implements RestCommandHandler {
             return null;
         }
 
-        final Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
+        final var gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
         final String keyInfoJson = keyInfoMessages.get(0);
         return gson.fromJson(keyInfoJson, JsonObject.class);
     }
index c0eb876..662c634 100644 (file)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2020 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -212,7 +213,7 @@ public class RestSession {
 
         AxArtifactKey policyModelKey = apexModelBeingUploaded.getPolicyModel().getKey();
 
-        String policyModelUUid = apexModelBeingUploaded.getPolicyModel().getKeyInformation().get(policyModelKey)
+        var policyModelUUid = apexModelBeingUploaded.getPolicyModel().getKeyInformation().get(policyModelKey)
             .getUuid().toString();
         return new PolicyUploadHandler().doUpload(result.getMessage(), policyModelKey, policyModelUUid);
     }
index 51b65fc..42ba08e 100644 (file)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2020 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -90,7 +91,7 @@ public abstract class RestUtils {
         }
         if (val.isJsonArray()) {
             final var arr = val.getAsJsonArray();
-            for (int i = 0; i < arr.size(); i++) {
+            for (var i = 0; i < arr.size(); i++) {
                 arr.set(i, blank2null(arr.get(i)));
             }
         }
@@ -156,7 +157,7 @@ public abstract class RestUtils {
     public static <C extends AxConcept> C getConceptFromJson(final String jsonString, final Class<C> clz)
         throws JAXBException {
         Unmarshaller unmarshaller = null;
-        final JAXBContext jaxbContext = JAXBContext.newInstance(clz);
+        final var jaxbContext = JAXBContext.newInstance(clz);
         unmarshaller = jaxbContext.createUnmarshaller();
         if (jsonString.matches(JSON_INPUT_TYPE_REGEXP)) {
             unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
index 8223033..ebbe3db 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Nordix Foundation
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -25,7 +26,6 @@ import java.util.Base64;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
 import org.onap.policy.apex.model.modelapi.ApexApiResult;
@@ -56,7 +56,7 @@ public class PolicyUploadHandler {
         LOGGER.entry();
 
         if (StringUtils.isBlank(ApexEditorMain.getParameters().getUploadUrl())) {
-            final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
+            final var apexApiResult = new ApexApiResult(Result.FAILED);
             apexApiResult.addMessage("Model upload is disabled, parameter upload-url is not set on server");
             LOGGER.exit(MODEL_UPLOAD_NOT_OK);
             return apexApiResult;
index 76fa005..7846b0e 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -106,7 +107,7 @@ public class PdpMonitoringServerParameterParser {
         final var stringWriter = new StringWriter();
         final var stringPrintWriter = new PrintWriter(stringWriter);
 
-        final HelpFormatter helpFormatter = new HelpFormatter();
+        final var helpFormatter = new HelpFormatter();
         helpFormatter.printHelp(stringPrintWriter, 120, mainClassName + " [options...] ", "", options, 0, 0, "");
 
         return stringWriter.toString();
index 419fe04..ede9bee 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -45,7 +46,6 @@ import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpEngineWorkerStatistics;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
@@ -134,7 +134,7 @@ public class PdpMonitoringRestResource {
             throw new IllegalArgumentException("Cannot parse groupName, subGroup and instanceId from " + id);
         }
 
-        Pdp pdp = pdpGroups.getGroups().stream().filter(group -> group.getName().equals(groupName))
+        var pdp = pdpGroups.getGroups().stream().filter(group -> group.getName().equals(groupName))
                 .flatMap(group -> group.getPdpSubgroups().stream().filter(sub -> sub.getPdpType().equals(subGroup)))
                 .flatMap(sub -> sub.getPdpInstances().stream()
                         .filter(instance -> instance.getInstanceId().equals(instanceId)))
@@ -157,7 +157,7 @@ public class PdpMonitoringRestResource {
         final List<EngineStatus> engineStatusList = new ArrayList<>();
 
         if (!pdpStats.isEmpty()) {
-            PdpStatistics pdpStatistics = pdpStats.get(groupName).get(subGroup).get(0);
+            var pdpStatistics = pdpStats.get(groupName).get(subGroup).get(0);
             responseObject.setTimeStamp(pdpStatistics.getTimeStamp().toString());
             responseObject.setPolicyDeployCount(pdpStatistics.getPolicyDeployCount());
             responseObject.setPolicyDeploySuccessCount(pdpStatistics.getPolicyDeploySuccessCount());
@@ -169,7 +169,7 @@ public class PdpMonitoringRestResource {
             // Engine Status data
             for (final PdpEngineWorkerStatistics engineStats : pdpStatistics.getEngineStats()) {
                 try {
-                    final EngineStatus engineStatusObject = new EngineStatus();
+                    final var engineStatusObject = new EngineStatus();
                     engineStatusObject.setTimestamp(pdpStatistics.getTimeStamp().toString());
                     engineStatusObject.setId(engineStats.getEngineId());
                     engineStatusObject.setStatus(engineStats.getEngineWorkerState().name());