Fix Blocker/Critical sonar issues 05/13105/3
authorshashikanth <shashikanth.vh@huawei.com>
Mon, 18 Sep 2017 10:53:55 +0000 (16:23 +0530)
committerSkip Wonnell <skip@att.com>
Tue, 19 Sep 2017 14:27:55 +0000 (14:27 +0000)
Fix Blocker/Critical sonar issues in appc module
https://sonar.onap.org/component_issues?id=org.openecomp.appc%3Aappc#resolved=false|severities=BLOCKER

Fixed null pointer exceptions for localContext and removed redundant check for localContext

Issue-Id: APPC-186
Change-Id: I38223655d69b89f6828fbdc7f3f388031e22f412
Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
appc-config/appc-flow-controller/provider/src/main/java/org/openecomp/appc/flow/controller/dbervices/FlowControlDBService.java

index 34ba743..153f5ef 100644 (file)
@@ -104,24 +104,26 @@ public class FlowControlDBService {
             if(status.toString().equals("FAILURE"))
                 throw new SvcLogicException("Error - while getting FlowReferenceData ");
         }
-                    
-        return localContext.getAttribute("artifact-content");
+        return localContext != null ? localContext.getAttribute("artifact-content") : null;
     }
     public QueryStatus loadSequenceIntoDB(SvcLogicContext localContext) throws SvcLogicException {
-        String fn = "DBService.saveArtifacts";
-        localContext.setAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED, EscapeUtils.escapeSql(localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT)));
-        log.debug("ESCAPED sequence for DB : "  +  localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED));
+             
+        QueryStatus status = null;
+      
+        if (localContext != null) {
+            String fn = "DBService.saveArtifacts";
+          
+            localContext.setAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED,
+                                      EscapeUtils.escapeSql(localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT)));
+            log.debug("ESCAPED sequence for DB : "  +  localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED));
         
-        for (Object key : localContext.getAttributeKeySet()) {
-            String parmName = (String) key;
-            String parmValue = localContext.getAttribute(parmName);
-            log.debug(" loadSequenceIntoDB " + parmName +  "="  + parmValue);
+            for (Object key : localContext.getAttributeKeySet()) {
+                String parmName = (String) key;
+                String parmValue = localContext.getAttribute(parmName);
+                log.debug(" loadSequenceIntoDB " + parmName +  "="  + parmValue);
             
-        }
-        
-        
-        QueryStatus status = null;
-        if (serviceLogic != null && localContext != null) {
+            }
+          
             String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS + 
                         " set request_id =  $" + FlowControllerConstants.REQUEST_ID + 
                         " , action =  $" + FlowControllerConstants.REQUEST_ACTION + 
@@ -130,7 +132,8 @@ public class FlowControlDBService {
                         " , category = $" + FlowControllerConstants.CATEGORY + 
                         " , artifact_content = $" + FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED + 
                         " , updated_date = sysdate() ";        
-
+          
+            log.debug(fn + "Query String : " + queryString);
             status = serviceLogic.save("SQL", false, false, queryString, null, null, localContext);
             if(status.toString().equals("FAILURE"))
                 throw new SvcLogicException("Error While processing storing Artifact: " +localContext.getAttribute(FlowControllerConstants.ARTIFACT_NAME));
@@ -142,26 +145,25 @@ public class FlowControlDBService {
         String fn = "FlowControlDBService.populateModuleAndRPC ";
         QueryStatus status = null;
         SvcLogicContext context = new SvcLogicContext();        
-        if (serviceLogic != null && context != null) {    
-            String key = "select execution_type, execution_module, execution_rpc from " + FlowControllerConstants.DB_PROCESS_FLOW_REFERENCE + 
-                        " where action = '" + transaction.getAction() + "'" + 
-                        " and action_level = '" + transaction.getActionLevel() + "'" + 
-                        " and protocol in ( select protocol from " + FlowControllerConstants.DB_PROTOCOL_REFERENCE  + 
-                        " where action = '" + transaction.getAction() + "'" ;
-            if(vnf_type !=null && !vnf_type.isEmpty())
-                key = key +     " and vnf_type ='" + vnf_type + "' )" ;
-            else
-                key = key + " ) " ;
-            log.debug(fn + "Query String : " + key);
-            status = serviceLogic.query("SQL", false, null, key, null, null, context);
-            if(status.toString().equals("FAILURE"))
-                throw new SvcLogicException("Error - while getting FlowReferenceData ");
-            
-            transaction.setExecutionModule(context.getAttribute(FlowControllerConstants.EXECUTTION_MODULE));
-            transaction.setExecutionRPC(context.getAttribute(FlowControllerConstants.EXECUTION_RPC));
-            transaction.setExecutionType(context.getAttribute(FlowControllerConstants.EXECUTION_TYPE));
-        }
-     
+        
+        String key = "select execution_type, execution_module, execution_rpc from " + FlowControllerConstants.DB_PROCESS_FLOW_REFERENCE + 
+                    " where action = '" + transaction.getAction() + "'" + 
+                    " and action_level = '" + transaction.getActionLevel() + "'" + 
+                    " and protocol in ( select protocol from " + FlowControllerConstants.DB_PROTOCOL_REFERENCE  + 
+                    " where action = '" + transaction.getAction() + "'" ;
+        if(vnf_type !=null && !vnf_type.isEmpty())
+            key = key +     " and vnf_type ='" + vnf_type + "' )" ;
+        else
+            key = key + " ) " ;
+        log.debug(fn + "Query String : " + key);
+        status = serviceLogic.query("SQL", false, null, key, null, null, context);
+        if(status.toString().equals("FAILURE"))
+            throw new SvcLogicException("Error - while getting FlowReferenceData ");
+           
+        transaction.setExecutionModule(context.getAttribute(FlowControllerConstants.EXECUTTION_MODULE));
+        transaction.setExecutionRPC(context.getAttribute(FlowControllerConstants.EXECUTION_RPC));
+        transaction.setExecutionType(context.getAttribute(FlowControllerConstants.EXECUTION_TYPE));
+        
     }
     
     public String getDependencyInfo(SvcLogicContext localContext) throws SvcLogicException {
@@ -187,8 +189,9 @@ public class FlowControlDBService {
             if(status.toString().equals("FAILURE"))
                 throw new SvcLogicException("Error - while getting dependencyData ");
         }
-                    
-        return localContext.getAttribute("artifact-content");
+
+        return localContext != null ? localContext.getAttribute("artifact-content") : null;
+
     }
     
         public String getCapabilitiesData(SvcLogicContext localContext) throws SvcLogicException {
@@ -214,7 +217,6 @@ public class FlowControlDBService {
                 if(status.toString().equals("FAILURE"))
                     throw new SvcLogicException("Error - while getting capabilitiesData ");
             }
-                        
-            return localContext.getAttribute("artifact-content");
+            return localContext != null ? localContext.getAttribute("artifact-content") : null;
         }
 }