Return List<Artifact> in ArtifactDownloadManager
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / service / ModelController.java
index 343fdca..233f2ab 100644 (file)
@@ -29,11 +29,13 @@ import org.onap.aai.cl.api.Logger;
 import org.onap.aai.cl.eelf.LoggerFactory;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
 import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
 import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
 import org.onap.aai.modelloader.notification.NotificationDataImpl;
 import org.onap.aai.modelloader.notification.NotificationPublisher;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -83,7 +85,7 @@ public class ModelController {
             response = processTestArtifact(modelName, modelVersion, payload);
         } else {
             logger.debug("Simulation interface disabled");
-            response = ResponseEntity.internalServerError().build();
+            response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
         }
 
         return response;
@@ -102,11 +104,16 @@ public class ModelController {
 
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Generating XML models from test artifact");
 
+            List<Artifact> artifacts = artifactDownloadManager.processToscaArtifacts(csarFile, artifactInfo, "test-transaction-id", modelVersion);
             List<Artifact> modelArtifacts = new ArrayList<>();
             List<Artifact> catalogArtifacts = new ArrayList<>();
-
-            artifactDownloadManager.processToscaArtifacts(modelArtifacts,
-                    catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion);
+            for(Artifact artifact : artifacts) {
+                if(artifact.getType().equals(ArtifactType.MODEL)) {
+                    modelArtifacts.add(artifact);
+                } else {
+                    catalogArtifacts.add(artifact);
+                }
+            }
 
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Loading xml models from test artifacts: "
                     + modelArtifacts.size() + " model(s) and " + catalogArtifacts.size() + " catalog(s)");
@@ -114,9 +121,9 @@ public class ModelController {
             NotificationDataImpl notificationData = new NotificationDataImpl();
             notificationData.setDistributionID("TestDistributionID");
             boolean success =
-                    artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts);
+                    artifactDeploymentManager.deploy(notificationData.getDistributionID(), modelArtifacts, catalogArtifacts);
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Deployment success was " + success);
-            response = success ? ResponseEntity.ok().build() : ResponseEntity.internalServerError().build();
+            response = success ? ResponseEntity.ok().build() : ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
         } catch (Exception e) {
             String responseMessage = e.getMessage();
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Exception handled: " + responseMessage);
@@ -126,7 +133,7 @@ public class ModelController {
             } else {
                 responseMessage += "\nSDC publishing is enabled but has been bypassed";
             }
-            response = ResponseEntity.internalServerError().body(responseMessage);
+            response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseMessage);
         }
         return response;
     }