Sonar fix in MSOCommonBPMN 81/93381/4
authorParshad Patel <pars.patel@samsung.com>
Tue, 13 Aug 2019 04:38:06 +0000 (13:38 +0900)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 16 Aug 2019 09:27:14 +0000 (09:27 +0000)
Either log or rethrow this exception
Remove this useless assignment to local variable "serviceInstance"
Remove the declaration of thrown exception  which is a runtime exception
Move the string literal on the left side of this string comparison

Issue-ID: SO-1841
Change-Id: I24cdd3682eddd2e5ceb7e961477a61457ef91ab2
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExtractPojosForBB.java

index 09a5424..be53e50 100644 (file)
@@ -104,6 +104,7 @@ public class ExecuteBuildingBlockRainyDay {
                     }
                 } catch (Exception ex) {
                     // keep default serviceType value
+                    logger.error("Exception in serviceType retrivel", ex);
                 }
                 String vnfType = ASTERISK;
                 try {
@@ -115,6 +116,7 @@ public class ExecuteBuildingBlockRainyDay {
                     }
                 } catch (Exception ex) {
                     // keep default vnfType value
+                    logger.error("Exception in vnfType retrivel", ex);
                 }
 
                 String errorCode = ASTERISK;
@@ -122,12 +124,14 @@ public class ExecuteBuildingBlockRainyDay {
                     errorCode = "" + workflowException.getErrorCode();
                 } catch (Exception ex) {
                     // keep default errorCode value
+                    logger.error("Exception in errorCode retrivel", ex);
                 }
 
                 try {
                     errorCode = "" + (String) execution.getVariable("WorkflowExceptionCode");
                 } catch (Exception ex) {
                     // keep default errorCode value
+                    logger.error("Exception in errorCode retrivel", ex);
                 }
 
                 String workStep = ASTERISK;
@@ -135,6 +139,7 @@ public class ExecuteBuildingBlockRainyDay {
                     workStep = workflowException.getWorkStep();
                 } catch (Exception ex) {
                     // keep default workStep value
+                    logger.error("Exception in workStep retrivel", ex);
                 }
 
                 String errorMessage = ASTERISK;
@@ -142,6 +147,7 @@ public class ExecuteBuildingBlockRainyDay {
                     errorMessage = workflowException.getErrorMessage();
                 } catch (Exception ex) {
                     // keep default workStep value
+                    logger.error("Exception in errorMessage retrivel", ex);
                 }
 
                 String serviceRole = ASTERISK;
@@ -177,14 +183,14 @@ public class ExecuteBuildingBlockRainyDay {
                         logger.error("Failed to update Request Db Infra Active Requests with Retry Status", ex);
                     }
                 }
-                if (handlingCode.equals("RollbackToAssigned") && !aLaCarte) {
+                if ("RollbackToAssigned".equals(handlingCode) && !aLaCarte) {
                     handlingCode = "Rollback";
                 }
                 if (handlingCode.startsWith("Rollback")) {
                     String targetState = "";
-                    if (handlingCode.equalsIgnoreCase("RollbackToAssigned")) {
+                    if ("RollbackToAssigned".equalsIgnoreCase(handlingCode)) {
                         targetState = Status.ROLLED_BACK_TO_ASSIGNED.toString();
-                    } else if (handlingCode.equalsIgnoreCase("RollbackToCreated")) {
+                    } else if ("RollbackToCreated".equalsIgnoreCase(handlingCode)) {
                         targetState = Status.ROLLED_BACK_TO_CREATED.toString();
                     } else {
                         targetState = Status.ROLLED_BACK.toString();
@@ -204,7 +210,7 @@ public class ExecuteBuildingBlockRainyDay {
             int envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
             execution.setVariable("maxRetries", envMaxRetries);
         } catch (Exception ex) {
-            logger.error("Could not read maxRetries from config file. Setting max to 5 retries");
+            logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
             execution.setVariable("maxRetries", 5);
         }
     }
@@ -247,8 +253,7 @@ public class ExecuteBuildingBlockRainyDay {
             request.setLastModifiedBy("CamundaBPMN");
             requestDbclient.updateInfraActiveRequests(request);
         } catch (Exception e) {
-            logger.error("Failed to update Request db with extSystemErrorSource or rollbackExtSystemErrorSource: "
-                    + e.getMessage());
+            logger.error("Failed to update Request db with extSystemErrorSource or rollbackExtSystemErrorSource: ", e);
         }
     }
 
index b2dbd97..aee28ca 100644 (file)
@@ -90,7 +90,6 @@ public class ExtractPojosForBB {
                     result = lookupObjectInList(serviceInstance.getConfigurations(), value);
                     break;
                 case VPN_ID:
-                    serviceInstance = extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
                     result = lookupObjectInList(gBBInput.getCustomer().getVpnBindings(), value);
                     break;
                 case VPN_BONDING_LINK_ID:
@@ -107,8 +106,9 @@ public class ExtractPojosForBB {
         } catch (BBObjectNotFoundException e) { // re-throw parent object not found
             throw e;
         } catch (Exception e) { // convert all other exceptions to object not found
-            logger.warn("BBObjectNotFoundException in ExtractPojosForBB",
-                    "BBObject " + key + " was not found in " + "gBBInput using reference value: " + value);
+            logger.warn(
+                    "BBObjectNotFoundException in ExtractPojosForBB, BBObject {} was not found in gBBInput using reference value: {} {}",
+                    key, value, e);
             throw new BBObjectNotFoundException(key, value);
         }
 
@@ -119,13 +119,8 @@ public class ExtractPojosForBB {
         }
     }
 
-    protected <T> Optional<T> lookupObject(Object obj, String value) throws IllegalAccessException,
-            IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
-        return findValue(obj, value);
-    }
-
-    protected <T> Optional<T> lookupObjectInList(List<?> list, String value) throws IllegalAccessException,
-            IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+    protected <T> Optional<T> lookupObjectInList(List<?> list, String value)
+            throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         Optional<T> result = Optional.empty();
         for (Object obj : list) {
             result = findValue(obj, value);
@@ -137,8 +132,8 @@ public class ExtractPojosForBB {
 
     }
 
-    protected <T> Optional<T> findValue(Object obj, String value) throws IllegalAccessException,
-            IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+    protected <T> Optional<T> findValue(Object obj, String value)
+            throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         for (Field field : obj.getClass().getDeclaredFields()) {
             if (field.isAnnotationPresent(Id.class)) {
                 String fieldName = field.getName();