Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / impl / OrchestrationTemplateCandidateManagerImpl.java
index 07a3fa7..f613dbb 100644 (file)
@@ -23,11 +23,8 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
-import org.openecomp.core.model.dao.ServiceModelDao;
-import org.openecomp.core.model.types.ServiceElement;
 import org.openecomp.core.utilities.json.JsonUtil;
 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
-import org.openecomp.sdc.activityLog.ActivityLogManager;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.Messages;
 import org.openecomp.sdc.common.utils.CommonUtil;
@@ -35,7 +32,6 @@ import org.openecomp.sdc.common.utils.SdcCommon;
 import org.openecomp.sdc.datatypes.error.ErrorLevel;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.healing.api.HealingManager;
-import org.openecomp.sdc.healing.types.HealCode;
 import org.openecomp.sdc.logging.api.Logger;
 import org.openecomp.sdc.logging.api.LoggerFactory;
 import org.openecomp.sdc.logging.api.annotations.Metrics;
@@ -43,14 +39,7 @@ import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
 import org.openecomp.sdc.logging.messages.AuditMessages;
 import org.openecomp.sdc.logging.types.LoggerServiceName;
 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
@@ -58,9 +47,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.errors.OrchestrationTemplateNotFo
 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateFileHandler;
 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessHandler;
-import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
-import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
 import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
@@ -80,114 +66,52 @@ public class OrchestrationTemplateCandidateManagerImpl
   private static final Logger logger =
       LoggerFactory.getLogger(OrchestrationTemplateCandidateManagerImpl.class);
   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
-  private VendorSoftwareProductDao vendorSoftwareProductDao;
+
   private VendorSoftwareProductInfoDao vspInfoDao;
-  private OrchestrationTemplateDao orchestrationTemplateDataDao;
   private CandidateService candidateService;
   private HealingManager healingManager;
-  private CompositionDataExtractor compositionDataExtractor;
-  private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
-  private CompositionEntityDataManager compositionEntityDataManager;
-  private NicDao nicDao;
-  private ComponentDao componentDao;
-  private ComponentArtifactDao componentArtifactDao;
-  private ActivityLogManager activityLogManager;
-  private ProcessDao processDao;
-
-  /**
-   * Instantiates a new Orchestration template candidate manager.
-   *
-   * @param vendorSoftwareProductDao     the vendor software product dao
-   * @param vspInfoDao                   the vsp info dao
-   * @param orchestrationTemplateDataDao the orchestration template data dao
-   * @param candidateService             the candidate service
-   * @param healingManager               the healing manager
-   * @param compositionDataExtractor     the composition data extractor
-   * @param serviceModelDao              the service model dao
-   * @param compositionEntityDataManager the composition entity data manager
-   * @param nicDao                       the nic dao
-   * @param componentDao                 the component dao
-   * @param componentArtifactDao                       the mib dao
-   * @param processDao                   the process dao
-   * @param activityLogManager           the activity log manager
-   */
-  public OrchestrationTemplateCandidateManagerImpl(
-      VendorSoftwareProductDao vendorSoftwareProductDao, VendorSoftwareProductInfoDao
-      vspInfoDao,
-      OrchestrationTemplateDao orchestrationTemplateDataDao,
-      CandidateService candidateService, HealingManager healingManager,
-      CompositionDataExtractor compositionDataExtractor,
-      ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
-      CompositionEntityDataManager compositionEntityDataManager,
-      NicDao nicDao,
-      ComponentDao componentDao,
-      ComponentArtifactDao componentArtifactDao,
-      ProcessDao processDao,
-      ActivityLogManager activityLogManager) {
-    this.vendorSoftwareProductDao = vendorSoftwareProductDao;
+
+  public OrchestrationTemplateCandidateManagerImpl(VendorSoftwareProductInfoDao vspInfoDao,
+                                                   CandidateService candidateService,
+                                                   HealingManager healingManager) {
     this.vspInfoDao = vspInfoDao;
-    this.orchestrationTemplateDataDao = orchestrationTemplateDataDao;
     this.candidateService = candidateService;
     this.healingManager = healingManager;
-    this.compositionDataExtractor = compositionDataExtractor;
-    this.serviceModelDao = serviceModelDao;
-    this.compositionEntityDataManager = compositionEntityDataManager;
-    this.nicDao = nicDao;
-    this.componentDao = componentDao;
-    this.componentArtifactDao = componentArtifactDao;
-    this.processDao = processDao;
-    this.activityLogManager = activityLogManager;
   }
 
   @Override
   @Metrics
   public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload,
-                                   String user, String filePrefix,
-                                   String networkPackageName) {
+                                   String fileSuffix, String networkPackageName) {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+
     OrchestrationTemplateFileHandler orchestrationTemplateFileHandler =
-            OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(filePrefix);
+        OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(fileSuffix);
+
     VspDetails vspDetails = getVspDetails(vspId, version);
+
     UploadFileResponse uploadResponse = orchestrationTemplateFileHandler
-        .upload(vspId, version, fileToUpload, user, candidateService,
-            vspDetails);
-    vspDetails.setOnboardingOrigin(filePrefix);
-    vspDetails.setNetworkPackageName(networkPackageName);
-    vspInfoDao.update(vspDetails);
+        .upload(vspDetails, fileToUpload, fileSuffix, networkPackageName, candidateService);
 
     uploadResponse.setNetworkPackageName(networkPackageName);
     return uploadResponse;
   }
 
-
-
   @Override
-  public OrchestrationTemplateActionResponse process(String vspId,
-                                                     Version version, String user) {
+  public OrchestrationTemplateActionResponse process(String vspId, Version version) {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
-    OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse();
-
-    Optional<OrchestrationTemplateCandidateData> candidate =
-        fetchCandidateDataEntity(vspId, version);
-    if (!candidate.isPresent()) {
-      throw new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build());
-    }
 
-    VspDetails vspDetails =
-        getVspDetails(vspId, version);
-    Optional<OrchestrationTemplateProcessHandler> processInstance =
-        OrchestrationProcessFactory.getInstance(vspDetails.getOnboardingOrigin());
+    OrchestrationTemplateCandidateData candidate = fetchCandidateDataEntity(vspId, version)
+        .orElseThrow(
+            () -> new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()));
 
-    if(processInstance.isPresent()){
-      response = processInstance.get().process(vspDetails, candidate.get(), user);
-    }
-
-    return response;
+    return OrchestrationProcessFactory.getInstance(candidate.getFileSuffix())
+        .map(processor -> processor.process(getVspDetails(vspId, version), candidate))
+        .orElse(new OrchestrationTemplateActionResponse());
   }
 
   @Override
-  public Optional<FilesDataStructure> getFilesDataStructure(
-      String vspId, Version version, String user) {
+  public Optional<FilesDataStructure> getFilesDataStructure(String vspId, Version version) {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
 
     Optional<FilesDataStructure> candidateFileDataStructure =
@@ -195,19 +119,13 @@ public class OrchestrationTemplateCandidateManagerImpl
     if (candidateFileDataStructure.isPresent()) {
       return candidateFileDataStructure;
     } else {
-      Map<String, Object> healingParams = getHealingParamsAsMap(vspId, version, user);
-
-      mdcDataDebugMessage
-          .debugExitMessage("VSP id", vspId);
-      return (Optional<FilesDataStructure>) healingManager
-          .heal(HealCode.FILE_DATA_STRUCTURE_HEALER, healingParams);
+      mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+      return Optional.empty();
     }
   }
 
   @Override
-
-  public ValidationResponse updateFilesDataStructure(String vspId,
-                                                     Version version, String user,
+  public ValidationResponse updateFilesDataStructure(String vspId, Version version,
                                                      FilesDataStructure fileDataStructure) {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
 
@@ -222,27 +140,23 @@ public class OrchestrationTemplateCandidateManagerImpl
         response.setUploadDataErrors(errorsMap, LoggerServiceName.Update_Manifest,
             LoggerTragetServiceName.VALIDATE_FILE_DATA_STRUCTURE);
 
-        mdcDataDebugMessage
-            .debugExitMessage("VSP id", vspId);
+        mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
         return response;
       }
     }
-    candidateService.updateOrchestrationTemplateCandidateFileDataStructure(vspId, version,
-        fileDataStructure);
+    candidateService
+        .updateOrchestrationTemplateCandidateFileDataStructure(vspId, version, fileDataStructure);
 
-    mdcDataDebugMessage
-        .debugExitMessage("VSP id", vspId);
+    mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
     return response;
   }
 
   @Override
 
-  public Optional<Pair<String, byte[]>> get(String vspId, Version version, String user)
-      throws IOException {
+  public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
 
-    VspDetails vspDetails =
-        getVspDetails(vspId, version);
+    VspDetails vspDetails = getVspDetails(vspId, version);
 
     Optional<OrchestrationTemplateCandidateData> candidateDataEntity =
         fetchCandidateDataEntity(vspId, version);
@@ -252,31 +166,34 @@ public class OrchestrationTemplateCandidateManagerImpl
           Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage());
       logger.error(errorMessage.getMessage());
 
-      mdcDataDebugMessage
-          .debugExitMessage("VSP id", vspId);
+      mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
       return Optional.empty();
     }
     OnboardingTypesEnum type =
-        OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin());
+        OnboardingTypesEnum.getOnboardingTypesEnum(candidateDataEntity.get().getFileSuffix());
 
-    if(CommonUtil.isFileOriginFromZip(vspDetails.getOnboardingOrigin())) {
+    if (CommonUtil.isFileOriginFromZip(candidateDataEntity.get().getFileSuffix())) {
       FilesDataStructure structure = JsonUtil
           .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class);
       String manifest = candidateService.createManifest(vspDetails, structure);
 
-      mdcDataDebugMessage
-          .debugExitMessage("VSP id", vspId);
+      mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
       return Optional.of(
-          new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService
+          new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(), candidateService
               .replaceManifestInZip(candidateDataEntity.get().getContentData(),
-              manifest, vspId, type)));
+                  manifest, vspId, type)));
     }
 
     return Optional.of(
-        new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get()
+        new ImmutablePair<>(candidateDataEntity.get().getFileSuffix(), candidateDataEntity.get()
             .getContentData().array()));
   }
 
+  @Override
+  public OrchestrationTemplateCandidateData getInfo(String vspId, Version version) {
+    return candidateService.getOrchestrationTemplateCandidateInfo(vspId, version);
+  }
+
   private Optional<OrchestrationTemplateCandidateData> fetchCandidateDataEntity(
       String vspId, Version version) {
     return Optional
@@ -286,19 +203,22 @@ public class OrchestrationTemplateCandidateManagerImpl
 
   // todo *************************** move to reusable place! *************************
 
-  private Map<String, Object> getHealingParamsAsMap(String vspId, Version version, String user) {
+  private Map<String, Object> getHealingParamsAsMap(String vspId, Version version) {
     Map<String, Object> healingParams = new HashMap<>();
 
     healingParams.put(SdcCommon.VSP_ID, vspId);
     healingParams.put(SdcCommon.VERSION, version);
-    healingParams.put(SdcCommon.USER, user);
 
     return healingParams;
   }
 
   private VspDetails getVspDetails(String vspId, Version version) {
     VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
-    vspDetails.setValidationData(orchestrationTemplateDataDao.getValidationData(vspId, version));
+/*    OrchestrationTemplateEntity orchestrationTemplateInfo =
+        orchestrationTemplateDao.getInfo(vspId, version);
+    vspDetails.setValidationData(orchestrationTemplateInfo.getValidationData());
+    vspDetails.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
+    vspDetails.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());*/
     return vspDetails;
   }