Return List<Artifact> in ArtifactDownloadManager
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / service / ArtifactDeploymentManager.java
index af006f5..e4535be 100644 (file)
@@ -22,73 +22,57 @@ package org.onap.aai.modelloader.service;
 
 import java.util.ArrayList;
 import java.util.List;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
+
 import org.onap.aai.modelloader.entity.Artifact;
 import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
 import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
 import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.onap.sdc.api.notification.INotificationData;
+import org.springframework.stereotype.Component;
 
 /**
  * This class is responsible for deploying model and catalog artifacts.
  */
+@Component
 public class ArtifactDeploymentManager {
 
-    private ModelLoaderConfig config;
-    private ModelArtifactHandler modelArtifactHandler;
-    private VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
+    private final ModelArtifactHandler modelArtifactHandler;
+    private final VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
+    private final AaiRestClient aaiClient;
 
-    public ArtifactDeploymentManager(ModelLoaderConfig config) {
-        this.config = config;
+    public ArtifactDeploymentManager(ModelArtifactHandler modelArtifactHandler, VnfCatalogArtifactHandler vnfCatalogArtifactHandler, AaiRestClient aaiClient) {
+        this.modelArtifactHandler = modelArtifactHandler;
+        this.vnfCatalogArtifactHandler = vnfCatalogArtifactHandler;
+        this.aaiClient = aaiClient;
     }
 
     /**
      * Deploys model and catalog artifacts to A&AI.
      *
-     * @param data data about the notification that is being processed
+     * @param distributionId data about the notification that is being processed
      * @param modelArtifacts collection of artifacts that represent yml files found in a TOSCA_CSAR file that have been
      *        converted to XML and also those for model query specs
      * @param catalogArtifacts collection of artifacts that represent vnf catalog files
      * @return boolean <code>true</code> if all deployments were successful otherwise <code>false</code>
      */
-    public boolean deploy(final INotificationData data, final List<Artifact> modelArtifacts,
+    public boolean deploy(final String distributionId, final List<Artifact> modelArtifacts,
             final List<Artifact> catalogArtifacts) {
 
-        AaiRestClient aaiClient = new AaiRestClient(config);
-        String distributionId = data.getDistributionID();
-
         List<Artifact> completedArtifacts = new ArrayList<>();
         boolean deploySuccess =
-                getModelArtifactHandler().pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
+                modelArtifactHandler.pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
 
         if (!deploySuccess) {
-            getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
+            modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
         } else {
             List<Artifact> completedImageData = new ArrayList<>();
-            deploySuccess = getVnfCatalogArtifactHandler().pushArtifacts(catalogArtifacts, distributionId,
+            deploySuccess = vnfCatalogArtifactHandler.pushArtifacts(catalogArtifacts, distributionId,
                     completedImageData, aaiClient);
             if (!deploySuccess) {
-                getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
-                getVnfCatalogArtifactHandler().rollback(completedImageData, distributionId, aaiClient);
+                modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
+                vnfCatalogArtifactHandler.rollback(completedImageData, distributionId, aaiClient);
             }
         }
 
         return deploySuccess;
     }
-
-    private ModelArtifactHandler getModelArtifactHandler() {
-        if (modelArtifactHandler == null) {
-            modelArtifactHandler = new ModelArtifactHandler(config);
-        }
-
-        return modelArtifactHandler;
-    }
-
-    private VnfCatalogArtifactHandler getVnfCatalogArtifactHandler() {
-        if (vnfCatalogArtifactHandler == null) {
-            this.vnfCatalogArtifactHandler = new VnfCatalogArtifactHandler(config);
-        }
-
-        return vnfCatalogArtifactHandler;
-    }
-}
+}
\ No newline at end of file