fix wrong handling of checking null values 70/98170/1
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 8 Nov 2019 10:17:37 +0000 (11:17 +0100)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 8 Nov 2019 10:17:37 +0000 (11:17 +0100)
Checking null values is handled by catching null pointer exception, this is not acceptable.

Change-Id: I0c43bc8853b67579a50bc9e69c599b93b978f741
Issue-ID: SO-2187
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java

index 11c6455..c3f5a98 100644 (file)
@@ -71,11 +71,13 @@ import org.onap.so.db.catalog.beans.VfModuleCustomization;
 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
 import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.serviceinstancebeans.CloudConfiguration;
 import org.onap.so.serviceinstancebeans.ModelInfo;
 import org.onap.so.serviceinstancebeans.ModelType;
 import org.onap.so.serviceinstancebeans.Networks;
 import org.onap.so.serviceinstancebeans.RelatedInstance;
 import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.onap.so.serviceinstancebeans.RequestInfo;
 import org.onap.so.serviceinstancebeans.Service;
 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
 import org.onap.so.serviceinstancebeans.VfModules;
@@ -182,21 +184,7 @@ public class WorkflowAction {
             execution.setVariable(BBConstants.G_ISTOPLEVELFLOW, true);
             ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
             RequestDetails requestDetails = sIRequest.getRequestDetails();
-            String cloudOwner = "";
-            try {
-                cloudOwner = requestDetails.getCloudConfiguration().getCloudOwner();
-            } catch (Exception ex) {
-                logger.error("Exception in getCloundOwner", ex);
-                cloudOwner = environment.getProperty(defaultCloudOwner);
-            }
-            boolean suppressRollback = false;
-            try {
-                suppressRollback = requestDetails.getRequestInfo().getSuppressRollback();
-            } catch (Exception ex) {
-                logger.error("Exception in getSuppressRollback", ex);
-                suppressRollback = false;
-            }
-            execution.setVariable("suppressRollback", suppressRollback);
+            execution.setVariable("suppressRollback", isSuppressRollback(requestDetails.getRequestInfo()));
             boolean isResume = false;
             if (isUriResume(uri)) {
                 isResume = true;
@@ -234,6 +222,7 @@ public class WorkflowAction {
                             "Could not resume request with request Id: " + requestId + ". No flowsToExecute was found");
                 }
             } else {
+                String cloudOwner = getCloudOwner(requestDetails.getCloudConfiguration());
                 if (aLaCarte) {
                     if (orchFlows == null || orchFlows.isEmpty()) {
                         orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte,
@@ -410,6 +399,21 @@ public class WorkflowAction {
         }
     }
 
+    private String getCloudOwner(CloudConfiguration cloudConfiguration) {
+        if (cloudConfiguration != null && cloudConfiguration.getCloudOwner() != null) {
+            return cloudConfiguration.getCloudOwner();
+        }
+        logger.warn("cloud owner value not found in request details, it will be set as default");
+        return environment.getProperty(defaultCloudOwner);
+    }
+
+    private boolean isSuppressRollback(RequestInfo requestInfo) {
+        if (requestInfo != null) {
+            return requestInfo.getSuppressRollback();
+        }
+        return false;
+    }
+
     protected <T> List<T> getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class<T> resultClass,
             AAIObjectType type) {
         List<T> vnfcs = new ArrayList<>();