Download processed file 01/34701/2
authorshrikantawachar <shrikant.awachar@amdocs.com>
Thu, 8 Mar 2018 08:03:17 +0000 (13:33 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Thu, 8 Mar 2018 08:46:07 +0000 (08:46 +0000)
Download processed file

Change-Id: Ieaaea0ce231bc0418d9d997d652f85f1743031f0
Issue-ID: SDC-1087
Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/OrchestrationTemplateCandidate.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VspZusammenUtil.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java

index cb3abee..ee9ab56 100644 (file)
@@ -64,8 +64,8 @@ public interface OrchestrationTemplateCandidate extends VspEntities {
   @GET
   @Path("/")
   @Produces(MediaType.APPLICATION_OCTET_STREAM)
-  @ApiOperation(value = "Get uploaded candidate HEAT file",
-      notes = "Downloads in process candidate HEAT file",
+  @ApiOperation(value = "Get uploaded Network Package file",
+      notes = "Downloads in uploaded Network Package file",
       response = File.class)
   Response get(
       @PathParam("vspId") String vspId,
index d856cfc..a152e44 100644 (file)
@@ -25,6 +25,10 @@ import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
 import org.openecomp.sdc.activitylog.dao.type.ActivityType;
 import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
@@ -54,12 +58,14 @@ import java.util.Optional;
 
 import static org.openecomp.core.utilities.file.FileUtils.getFileExtension;
 import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
 
 @Named
 @Service("orchestrationTemplateCandidate")
 @Scope(value = "prototype")
 public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplateCandidate {
-
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(OrchestrationTemplateCandidateImpl.class);
   private OrchestrationTemplateCandidateManager candidateManager =
       OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
   private VendorSoftwareProductManager vendorSoftwareProductManager = VspManagerFactory
@@ -84,13 +90,24 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
   @Override
   public Response get(String vspId, String versionId, String user) throws IOException {
     Optional<Pair<String, byte[]>> zipFile = candidateManager.get(vspId, new Version(versionId));
-
-    if (!zipFile.isPresent()) {
-      return Response.status(Response.Status.NOT_FOUND).build();
+    String fileName = null;
+    if (zipFile.isPresent()) {
+      fileName = "Candidate." + zipFile.get().getLeft();
+    } else {
+      zipFile = vendorSoftwareProductManager.get(vspId, new Version((versionId)));
+
+      if (!zipFile.isPresent()) {
+        ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
+            getErrorWithParameters(
+                Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(),
+                ""));
+        LOGGER.error(errorMessage.getMessage());
+        return Response.status(Response.Status.NOT_FOUND).build();
+      }
+      fileName = "Processed." + zipFile.get().getLeft();
     }
     Response.ResponseBuilder response = Response.ok(zipFile.get().getRight());
-    String filename = "Candidate." + zipFile.get().getLeft();
-    response.header("Content-Disposition", "attachment; filename=" + filename);
+    response.header("Content-Disposition", "attachment; filename=" + fileName);
     return response.build();
   }
 
index 423f9a5..1b07f68 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.openecomp.sdc.vendorsoftwareproduct;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
@@ -68,6 +69,7 @@ public interface VendorSoftwareProductManager {
 
   File getInformationArtifact(String vspId, Version version);
 
+  public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException;
 
   Collection<ComputeEntity> getComputeByVsp(String vspId, Version version);
 }
index 97a4a21..cfb4c9d 100644 (file)
@@ -22,10 +22,8 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.core.utilities.json.JsonUtil;
 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.Messages;
 import org.openecomp.sdc.common.utils.CommonUtil;
 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.logging.api.Logger;
 import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -52,8 +50,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
 public class OrchestrationTemplateCandidateManagerImpl
     implements OrchestrationTemplateCandidateManager {
   private static final Logger LOGGER =
@@ -128,10 +124,6 @@ public class OrchestrationTemplateCandidateManagerImpl
         fetchCandidateDataEntity(vspId, version);
 
     if (!candidateDataEntity.isPresent()) {
-      ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
-          getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(),
-              ""));
-      LOGGER.error(errorMessage.getMessage());
       return Optional.empty();
     }
     OnboardingTypesEnum type =
index ada88b8..f116abe 100644 (file)
@@ -18,6 +18,8 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.core.dao.UniqueValueDao;
 import org.openecomp.core.enrichment.api.EnrichmentManager;
 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
@@ -82,6 +84,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilde
 import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder;
 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder;
 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
+import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult;
@@ -144,6 +147,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
   private final ImageDao imageDao;
   private final ManualVspToscaManager manualVspToscaManager;
   private final UniqueValueUtil uniqueValueUtil;
+  private final CandidateService candidateService;
 
   public VendorSoftwareProductManagerImpl(
       VspMergeDao vspMergeDao,
@@ -163,7 +167,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
       ComputeDao computeDao,
       ImageDao imageDao,
       ManualVspToscaManager manualVspToscaManager,
-      UniqueValueDao uniqueValueDao) {
+      UniqueValueDao uniqueValueDao,
+      CandidateService candidateService) {
     this.vspMergeDao = vspMergeDao;
     this.orchestrationTemplateDao = orchestrationTemplateDataDao;
     this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
@@ -182,6 +187,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     this.imageDao = imageDao;
     this.manualVspToscaManager = manualVspToscaManager;
     this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
+    this.candidateService = candidateService;
 
     registerToVersioning();
   }
@@ -817,6 +823,24 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
   }
 
+  @Override
+  public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException {
+
+    OrchestrationTemplateEntity orchestrationTemplateEntity =
+        orchestrationTemplateDao.get(vspId, version);
+
+    if (isOrchestrationTemplateMissing(orchestrationTemplateEntity)) {
+      return Optional.empty();
+    }
+
+    if (CommonUtil.isFileOriginFromZip(orchestrationTemplateEntity.getFileSuffix())) {
+      return Optional.of(new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(), candidateService
+          .getZipData(orchestrationTemplateEntity.getContentData())));
+    }
+    return Optional.of(new ImmutablePair<>(orchestrationTemplateEntity.getFileSuffix(),
+        orchestrationTemplateEntity.getContentData().array()));
+  }
+
   void updateUniqueName(String oldVspName, String newVspName) {
     uniqueValueUtil.updateUniqueValue(
         VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
index da4328d..75351e2 100644 (file)
@@ -25,6 +25,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateMan
 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
 import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.*;
+import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactory;
 
 public class VspManagerFactoryImpl extends VspManagerFactory {
@@ -47,7 +48,8 @@ public class VspManagerFactoryImpl extends VspManagerFactory {
           ComputeDaoFactory.getInstance().createInterface(),
           ImageDaoFactory.getInstance().createInterface(),
           new ManualVspToscaManagerImpl(),
-          UniqueValueDaoFactory.getInstance().createInterface());
+          UniqueValueDaoFactory.getInstance().createInterface(), CandidateServiceFactory
+          .getInstance().createInterface());
 
   @Override
   public VendorSoftwareProductManager createInterface() {
index f3d2916..0012075 100644 (file)
@@ -61,6 +61,8 @@ public interface CandidateService {
   OrchestrationTemplateCandidateData getOrchestrationTemplateCandidateInfo(String vspId,
                                                                        Version version);
 
+  byte[] getZipData(ByteBuffer contentData) throws IOException;
+
   void deleteOrchestrationTemplateCandidate(String vspId, Version version);
 
   Optional<ByteArrayInputStream> fetchZipFileByteArrayInputStream(String vspId,
index 22fe1dd..b72d684 100644 (file)
@@ -72,7 +72,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
         zusammenAdaptor.getElementByName(context, elementContext, null,
             ElementType.OrchestrationTemplateCandidate.name());
     if (candidateElement.isPresent()) {
-      if (VspZusammenUtil.hasEmptyData(candidateElement.get().getData())) {
+      if (VspZusammenUtil.isEmpty(candidateElement.get().getData())) {
         return null;
       }
       OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData();
index 26280ec..0c1317f 100644 (file)
@@ -33,6 +33,7 @@ import org.openecomp.sdc.versioning.dao.types.Version;
 
 import java.io.ByteArrayInputStream;
 import java.nio.ByteBuffer;
+import java.util.Collection;
 import java.util.Optional;
 
 import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
@@ -40,8 +41,8 @@ import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
 
 public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTemplateDao {
 
-  private static final Logger LOGGER = LoggerFactory.getLogger
-      (OrchestrationTemplateDaoZusammenImpl.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(
+      OrchestrationTemplateDaoZusammenImpl.class);
   private ZusammenAdaptor zusammenAdaptor;
 
   public OrchestrationTemplateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
@@ -106,27 +107,38 @@ public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTempla
     Optional<Element> orchestrationTemplateElement = zusammenAdaptor
         .getElementByName(context, elementContext, vspModel.get().getId(),
             ElementType.OrchestrationTemplate.name());
-    if (!orchestrationTemplateElement.isPresent()) {
+    if (orchestrationTemplateElement.isPresent() &&
+        VspZusammenUtil.hasEmptyData(orchestrationTemplateElement.get().getData())) {
       return orchestrationTemplate;
     }
 
-    if (!VspZusammenUtil.hasEmptyData(orchestrationTemplateElement.get().getData())) {
-      orchestrationTemplate.setContentData(
+    orchestrationTemplate.setContentData(
           ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.get().getData())));
+
+    Collection<Element> subElements = orchestrationTemplateElement.get().getSubElements();
+    if (subElements.isEmpty()) {
+      return orchestrationTemplate;
     }
 
-    Optional<Element> validationDataElement =
-        zusammenAdaptor.getElementByName(context, elementContext,
-            orchestrationTemplateElement.get().getElementId(),
-            ElementType.OrchestrationTemplateValidationData.name());
-    if (validationDataElement.isPresent()) {
-      orchestrationTemplate.setFileSuffix(validationDataElement.get().getInfo()
-          .getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
-      orchestrationTemplate.setFileName(validationDataElement.get().getInfo()
-          .getProperty(InfoPropertyName.FILE_NAME.getVal()));
-      if (!VspZusammenUtil.hasEmptyData(validationDataElement.get().getData())) {
-        orchestrationTemplate.setValidationData(
-            new String(FileUtils.toByteArray(validationDataElement.get().getData())));
+    for (Element element : subElements) {
+      Optional<Element> subElement = zusammenAdaptor.getElement(context,
+          elementContext, element.getElementId().toString());
+
+      if (subElement.get().getInfo().getName().equals(ElementType
+          .OrchestrationTemplateValidationData.name())) {
+        orchestrationTemplate.setFileSuffix(subElement.get().getInfo()
+            .getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
+        orchestrationTemplate.setFileName(subElement.get().getInfo()
+            .getProperty(InfoPropertyName.FILE_NAME.getVal()));
+        if (!VspZusammenUtil.hasEmptyData(subElement.get().getData())) {
+          orchestrationTemplate.setValidationData(
+              new String(FileUtils.toByteArray(subElement.get().getData())));
+        }
+      } else if (subElement.get().getInfo().getName().equals(ElementType
+          .OrchestrationTemplateStructure.name())) {
+        orchestrationTemplate.setFilesDataStructure(new String(FileUtils.toByteArray(subElement
+            .get().getData())));
+
       }
     }
     return orchestrationTemplate;
index d096b35..09fd948 100644 (file)
@@ -30,6 +30,19 @@ class VspZusammenUtil {
     return head;
   }
 
+  static boolean isEmpty(InputStream elementData) {
+    byte[] byteElementData;
+    if (Objects.isNull(elementData)) {
+      return true;
+    }
+    try {
+      byteElementData = IOUtils.toByteArray(elementData);
+    } catch (IOException e) {
+      return false;
+    }
+    return ArrayUtils.isEmpty(byteElementData);
+  }
+
   static boolean hasEmptyData(InputStream elementData) {
     String EMPTY_DATA = "{}";
     byte[] byteElementData;
index 18910e3..b962a79 100644 (file)
@@ -421,6 +421,29 @@ public class CandidateServiceImpl implements CandidateService {
     return baos.toByteArray();
   }
 
+  @Override
+  public byte[] getZipData(ByteBuffer contentData)
+      throws IOException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+    try (final ZipOutputStream zos = new ZipOutputStream(baos);
+         ZipInputStream zipStream = new ZipInputStream(
+             new ByteArrayInputStream(contentData.array()))) {
+      ZipEntry zipEntry;
+      while ((zipEntry = zipStream.getNextEntry()) != null) {
+        ZipEntry locZipEntry = new ZipEntry(zipEntry.getName());
+        zos.putNextEntry(locZipEntry);
+        byte[] buf = new byte[1024];
+        int len;
+        while ((len = zipStream.read(buf)) > 0) {
+          zos.write(buf, 0, (len < buf.length) ? len : buf.length);
+        }
+        zos.closeEntry();
+      }
+    }
+    return baos.toByteArray();
+  }
+
   @Override
   public Optional<List<ErrorMessage>> validateFileDataStructure(
       FilesDataStructure filesDataStructure) {