Fix sonar issue 51/55951/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 6 Jul 2018 11:23:16 +0000 (13:23 +0200)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 6 Jul 2018 11:23:16 +0000 (13:23 +0200)
Fix a NPE reported by Sonar recently

Issue-ID: CLAMP-198
Change-Id: I1d9ec510dee4aeec676ca67c2072e7f0a7aea972
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/service/CldsService.java

index c0ff83c..a63d021 100644 (file)
@@ -468,30 +468,35 @@ public class CldsService extends SecureServiceBase {
                 // refresh model info from db (get fresh event info)
                 retrievedModel = CldsModel.retrieve(cldsDao, modelName, false);
             }
-            if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
-                || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
-                || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
-                if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) {
-                    // SDC artifact case
-                    logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification");
-                    DcaeEvent dcaeEvent = new DcaeEvent();
-                    dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml");
-                    dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
-                    CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),
-                        CldsEvent.ACTION_STATE_RECEIVED, null);
-                } else {
-                    // This should be done only when the call to DCAE
-                    // has not yet been done. When CL comes from SDC
-                    // this is not required as the DCAE inventory call is done
-                    // during the CL deployment.
-                    dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
+            if (retrievedModel != null) {
+                if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
+                    || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
+                    || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
+                    if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) {
+                        // SDC artifact case
+                        logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification");
+                        DcaeEvent dcaeEvent = new DcaeEvent();
+                        dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml");
+                        dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
+                        CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),
+                            CldsEvent.ACTION_STATE_RECEIVED, null);
+                    } else {
+                        // This should be done only when the call to DCAE
+                        // has not yet been done. When CL comes from SDC
+                        // this is not required as the DCAE inventory call is done
+                        // during the CL deployment.
+                        dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
+                    }
+                    retrievedModel.save(cldsDao, getUserId());
                 }
-                retrievedModel.save(cldsDao, getUserId());
+                // audit log
+                LoggingUtils.setTimeContext(startTime, new Date());
+                LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName());
+                auditLogger.info("Process model action completed");
+            } else {
+                logger.error("CldsModel not found in database with modelName: " + modelName);
+                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("CldsModel not found in database with modelName: \" + modelName").build();
             }
-            // audit log
-            LoggingUtils.setTimeContext(startTime, new Date());
-            LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName());
-            auditLogger.info("Process model action completed");
         } catch (Exception e) {
             errorCase = true;
             logger.error("Exception occured during putModelAndProcessAction", e);