diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services')
5 files changed, 644 insertions, 664 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/ManualVspDataCollectionService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/ManualVspDataCollectionService.java index 100425858f..73b9491e73 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/ManualVspDataCollectionService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/ManualVspDataCollectionService.java @@ -23,12 +23,12 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; @@ -57,10 +57,10 @@ import java.util.Optional; public class ManualVspDataCollectionService { - private static final VendorSoftwareProductDao vendorSoftwareProductDao = - VendorSoftwareProductDaoFactory.getInstance().createInterface(); private static final VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao = VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static final DeploymentFlavorDao deploymentFlavorDao = + DeploymentFlavorDaoFactory.getInstance().createInterface(); private static final ComputeDao computeDao = ComputeDaoFactory.getInstance().createInterface(); private static final ImageDao imageDao = @@ -75,16 +75,14 @@ public class ManualVspDataCollectionService { private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); - /** * Gets vendor name for the vsp. * * @param vspId the vsp id * @param version the version - * @param user the user * @return the release vendor name */ - public Optional<String> getReleaseVendor(String vspId, Version version, String user) { + public Optional<String> getReleaseVendor(String vspId, Version version) { String vendorName = null; VspDetails vspDetails = vendorSoftwareProductInfoDao.get(new VspDetails(vspId, version)); if (Objects.nonNull(vspDetails)) { @@ -98,14 +96,12 @@ public class ManualVspDataCollectionService { * * @param vspId the vsp id * @param version the version - * @param user the user * @return the allowed flavors */ - public Map<String, DeploymentFlavorModel> getAllowedFlavors(String vspId, Version version, - String user) { + public Map<String, DeploymentFlavorModel> getAllowedFlavors(String vspId, Version version) { Map<String, DeploymentFlavorModel> allowedFlavors = new HashMap<>(); Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); + deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { DeploymentFlavor deploymentFlavorCompositionData = @@ -129,13 +125,12 @@ public class ManualVspDataCollectionService { LicenseFlavor licenseFlavor = getLicenseFlavor(featureGroupId); deploymentFlavorModel.setLicense_flavor(licenseFlavor); //Get sp_part_number - Optional<String> partNumber = getPartNumber(vspVlmId, vlmVersion, featureGroupId, - user); + Optional<String> partNumber = getPartNumber(vspVlmId, vlmVersion, featureGroupId); partNumber.ifPresent(deploymentFlavorModel::setSp_part_number); //Gather and set Vendor Info String vendorModel = deploymentFlavorCompositionData.getModel(); Optional<VendorInfo> vendorInfo = getVendorInfo(vspVlmId, vendorModel, vlmVersion, - featureGroupId, user); + featureGroupId); vendorInfo.ifPresent(deploymentFlavorModel::setVendor_info); //Gather and set Compute info List<ComponentComputeAssociation> componentComputeAssociations = @@ -146,7 +141,7 @@ public class ManualVspDataCollectionService { String componentId = componentComputeAssociation.getComponentId(); String computeFlavorId = componentComputeAssociation.getComputeFlavorId(); Optional<ComputeFlavor> computeFlavor = - getComputeFlavor(vspId, version, componentId, computeFlavorId, user); + getComputeFlavor(vspId, version, componentId, computeFlavorId); computeFlavor.ifPresent(deploymentFlavorModel::setCompute_flavor); } } @@ -164,15 +159,13 @@ public class ManualVspDataCollectionService { * * @param vspId the vsp id * @param version the version - * @param user the user * @return the vsp component images */ public Map<String, List<MultiFlavorVfcImage>> getVspComponentImages(String vspId, - Version version, - String user) { + Version version) { Map<String, List<MultiFlavorVfcImage>> vspComponentImages = new HashMap<>(); Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); + deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); @@ -184,7 +177,7 @@ public class ManualVspDataCollectionService { componentComputeAssociations) { String componentId = componentComputeAssociation.getComponentId(); List<MultiFlavorVfcImage> componentImages = - getComponentImages(vspId, version, componentId, user); + getComponentImages(vspId, version, componentId); if (CollectionUtils.isNotEmpty(componentImages)) { vspComponentImages.put(componentId, componentImages); } @@ -199,13 +192,12 @@ public class ManualVspDataCollectionService { * * @param vspId the vsp id * @param version the version - * @param user the user * @return the vsp components */ - public Map<String, String> getVspComponents(String vspId, Version version, String user) { + public Map<String, String> getVspComponents(String vspId, Version version) { Map<String, String> componentIdNameMap = new HashMap<>(); Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); + deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); @@ -216,7 +208,7 @@ public class ManualVspDataCollectionService { for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { String componentId = componentComputeAssociation.getComponentId(); - Optional<String> componentName = getComponentName(vspId, version, componentId, user); + Optional<String> componentName = getComponentName(vspId, version, componentId); componentName.ifPresent(name -> componentIdNameMap.put(componentId, name)); } } @@ -229,13 +221,12 @@ public class ManualVspDataCollectionService { * * @param vspId the vsp id * @param version the version - * @param user the user * @return the vsp component nics */ - public Map<String, List<Nic>> getVspComponentNics(String vspId, Version version, String user) { + public Map<String, List<Nic>> getVspComponentNics(String vspId, Version version) { Map<String, List<Nic>> vspComponentNics = new HashMap<>(); Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); + deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { DeploymentFlavor deploymentFlavorCompositionData = @@ -247,7 +238,7 @@ public class ManualVspDataCollectionService { for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { String componentId = componentComputeAssociation.getComponentId(); - List<Nic> componentNics = getComponentNics(vspId, version, componentId, user); + List<Nic> componentNics = getComponentNics(vspId, version, componentId); if (CollectionUtils.isNotEmpty(componentNics)) { vspComponentNics.put(componentId, componentNics); } @@ -259,8 +250,7 @@ public class ManualVspDataCollectionService { return vspComponentNics; } - private List<Nic> getComponentNics(String vspId, Version version, String componentId, - String user) { + private List<Nic> getComponentNics(String vspId, Version version, String componentId) { List<Nic> componentNics = new ArrayList<>(); Collection<NicEntity> nics = nicDao.list(new NicEntity(vspId, version, componentId, null)); if (Objects.nonNull(nics)) { @@ -283,8 +273,8 @@ public class ManualVspDataCollectionService { } private Optional<String> getPartNumber(String vlmId, Version version, - String featureGroupId, String user) { - FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId, user); + String featureGroupId) { + FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); if (Objects.nonNull(featureGroup)) { return Optional.ofNullable(featureGroup.getFeatureGroup().getPartNumber()); } @@ -292,9 +282,9 @@ public class ManualVspDataCollectionService { } private Optional<VendorInfo> getVendorInfo(String vlmId, String vendorModel, Version version, - String featureGroupId, String user) { + String featureGroupId) { VendorInfo vendorInfo = null; - FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId, user); + FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); if (Objects.nonNull(featureGroup)) { //Process Feature group to get Manufacturer ref no. String manufacturerReferenceNumber = featureGroup.getEntityManufacturerReferenceNumber(); @@ -308,29 +298,28 @@ public class ManualVspDataCollectionService { } private Optional<ComputeFlavor> getComputeFlavor(String vspId, Version version, - String componentId, String computeFlavorId, - String user) { + String componentId, String computeFlavorId) { ComputeFlavor computeFlavor = null; ComputeEntity computeQuestionnaire = null; try { computeQuestionnaire = computeDao.getQuestionnaireData(vspId, version, componentId, computeFlavorId); } catch (Exception ex) { - log.debug("",ex); + log.debug("", ex); computeQuestionnaire = null; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, LoggerTragetServiceName.COLLECT_MANUAL_VSP_TOSCA_DATA, ErrorLevel.INFO.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), "Failed to get compute questionnaire : " + ex.getMessage()); } - if (computeQuestionnaire != null && Objects.nonNull(computeQuestionnaire)) { + if (Objects.nonNull(computeQuestionnaire)) { String computeQuestionnaireData = computeQuestionnaire.getQuestionnaireData(); if (Objects.nonNull(computeQuestionnaireData)) { Compute compute; try { compute = JsonUtil.json2Object(computeQuestionnaireData, Compute.class); } catch (Exception ex) { - log.debug("",ex); + log.debug("", ex); compute = null; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, LoggerTragetServiceName.COLLECT_MANUAL_VSP_TOSCA_DATA, ErrorLevel.INFO.name(), @@ -354,17 +343,15 @@ public class ManualVspDataCollectionService { return Optional.ofNullable(computeFlavor); } - private FeatureGroupModel getFeatureGroup(String vlmId, Version version, String featureGroupId, - String user) { + private FeatureGroupModel getFeatureGroup(String vlmId, Version version, String featureGroupId) { FeatureGroupEntity fgInput = new FeatureGroupEntity(); fgInput.setVendorLicenseModelId(vlmId); fgInput.setVersion(version); fgInput.setId(featureGroupId); - return vendorLicenseFacade.getFeatureGroupModel(fgInput, user); + return vendorLicenseFacade.getFeatureGroupModel(fgInput); } - private Optional<String> getComponentName(String vspId, Version version, String componentId, - String user) { + private Optional<String> getComponentName(String vspId, Version version, String componentId) { ComponentEntity componentEntity = componentDao.get(new ComponentEntity(vspId, version, componentId)); @@ -377,18 +364,16 @@ public class ManualVspDataCollectionService { } private List<MultiFlavorVfcImage> getComponentImages(String vspId, Version version, - String componentId, String user) { + String componentId) { List<MultiFlavorVfcImage> multiFlavorVfcImages = new ArrayList<>(); - MultiFlavorVfcImage multiFlavorVfcImage = null; + MultiFlavorVfcImage multiFlavorVfcImage; Collection<ImageEntity> componentImages = - vendorSoftwareProductDao.listImages(vspId, version, componentId); + imageDao.list(new ImageEntity(vspId, version, componentId, null)); if (Objects.nonNull(componentImages)) { for (ImageEntity componentImage : componentImages) { - String imageId = componentImage.getId(); - ImageEntity imageEntity = vendorSoftwareProductDao.getImage(vspId, version, componentId, - imageId); + ImageEntity imageEntity = imageDao.get(componentImage); ImageEntity imageQuestionnaireDataEntity = imageDao.getQuestionnaireData(vspId, version, - componentId, imageId); + componentId, componentImage.getId()); Image imageCompositionData = imageEntity.getImageCompositionData(); if (Objects.nonNull(imageEntity) && Objects.nonNull(imageQuestionnaireDataEntity) @@ -398,14 +383,14 @@ public class ManualVspDataCollectionService { imageDetails = JsonUtil.json2Object(imageQuestionnaireDataEntity .getQuestionnaireData(), ImageDetails.class); } catch (Exception ex) { - log.debug("",ex); + log.debug("", ex); imageDetails = null; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, LoggerTragetServiceName.COLLECT_MANUAL_VSP_TOSCA_DATA, ErrorLevel.INFO.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), "Unable to parse image questionnaire : " + ex.getMessage()); } - if (imageDetails != null && Objects.nonNull(imageDetails) + if (Objects.nonNull(imageDetails) && Objects.nonNull(imageDetails.getVersion())) { //Image version is used as a key for the image block //So excluding the population if questionnaire data is absent or invalid diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java index 19e48eceaa..6b57649308 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java @@ -47,8 +47,8 @@ import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplateErrorBui import org.openecomp.sdc.tosca.errors.ToscaMissingSubstitutionMappingForReqCapErrorBuilder; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; -import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; +import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java index 39534cf9b7..ab5ee6c64c 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java @@ -37,7 +37,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; @@ -78,14 +77,14 @@ import java.util.Set; public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager { private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR = - "COMPOSITION_ENTITY_DATA_MANAGER_ERR"; + "COMPOSITION_ENTITY_DATA_MANAGER_ERR"; private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG = - "Invalid input: %s may not be null"; + "Invalid input: %s may not be null"; private static final String MISSING_OR_INVALID_QUESTIONNAIRE_MSG = "Data is missing/invalid for this %s. Please refill and resubmit."; private static final Logger logger = - LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class); + LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class); private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private Map<CompositionEntityId, CompositionEntityData> entities = new HashMap<>(); @@ -99,14 +98,12 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa private ImageDao imageDao; private ComputeDao computeDao; private DeploymentFlavorDao deploymentFlavorDao; - private VendorSoftwareProductDao vendorSoftwareProductDao; public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, ComponentDao componentDao, NicDao nicDao, NetworkDao networkDao, ImageDao imageDao, ComputeDao computeDao, - DeploymentFlavorDao deploymentFlavorDao, - VendorSoftwareProductDao vendorSoftwareProductDao) { + DeploymentFlavorDao deploymentFlavorDao) { this.vspInfoDao = vspInfoDao; this.componentDao = componentDao; this.nicDao = nicDao; @@ -114,7 +111,6 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa this.imageDao = imageDao; this.computeDao = computeDao; this.deploymentFlavorDao = deploymentFlavorDao; - this.vendorSoftwareProductDao = vendorSoftwareProductDao; } /** @@ -133,27 +129,27 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa if (entity == null) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) - .build()); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); } if (schemaTemplateContext == null) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context")) - .build()); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context")) + .build()); } CompositionEntityValidationData validationData = - new CompositionEntityValidationData(entity.getType(), entity.getId()); + new CompositionEntityValidationData(entity.getType(), entity.getId()); String json = - schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData() - : entity.getQuestionnaireData(); + schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData() + : entity.getQuestionnaireData(); validationData.setErrors(JsonUtil.validate( - json == null ? JsonUtil.object2Json(new Object()) : json, - generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput))); + json == null ? JsonUtil.object2Json(new Object()) : json, + generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput))); mdcDataDebugMessage.debugExitMessage(null); return validationData; @@ -169,13 +165,13 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { if (entity == null) { throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) - .build()); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); } entities.put(entity.getCompositionEntityId(), - new CompositionEntityData(entity, schemaTemplateInput)); + new CompositionEntityData(entity, schemaTemplateInput)); } /** @@ -205,10 +201,10 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa @Override public void buildTrees() { Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData = - new HashMap<>(); + new HashMap<>(); entities.entrySet().forEach( - entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(), - entry.getValue().entity)); + entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(), + entry.getValue().entity)); } public Collection<CompositionEntityValidationData> getTrees() { @@ -259,14 +255,14 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa } Collection<CompositionEntityValidationData> subEntitiesValidationData = - entity.getSubEntitiesValidationData(); + entity.getSubEntitiesValidationData(); return !CollectionUtils.isEmpty(subEntitiesValidationData) && - checkForErrorsInChildren(subEntitiesValidationData); + checkForErrorsInChildren(subEntitiesValidationData); } private boolean checkForErrorsInChildren( - Collection<CompositionEntityValidationData> subEntitiesValidationData) { + Collection<CompositionEntityValidationData> subEntitiesValidationData) { boolean result = false; for (CompositionEntityValidationData subEntity : subEntitiesValidationData) { if (CollectionUtils.isNotEmpty(subEntity.getErrors())) { @@ -360,10 +356,10 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa //component.setId(CommonMethods.nextUuId()); will be set by the dao component.setQuestionnaireData( - new JsonSchemaDataGenerator( - generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, - null)) - .generateData()); + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, + null)) + .generateData()); componentDao.create(component); @@ -377,9 +373,9 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa //nic.setId(CommonMethods.nextUuId()); will be set by the dao nic.setQuestionnaireData( - new JsonSchemaDataGenerator( - generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null)) - .generateData()); + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null)) + .generateData()); nicDao.create(nic); @@ -412,28 +408,26 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa return treeAsList; } - public void getEntityListWithErrors(CompositionEntityValidationData entity, + private void getEntityListWithErrors(CompositionEntityValidationData entity, Set<CompositionEntityValidationData> compositionSet) { - Collection<CompositionEntityValidationData> childNodes = - entity.getSubEntitiesValidationData(); + if(CollectionUtils.isNotEmpty(entity.getErrors())){ + addNodeWithErrors(entity, compositionSet); + } - if (CollectionUtils.isEmpty(childNodes)) { + if (CollectionUtils.isEmpty(entity.getSubEntitiesValidationData())) { return; } - for (CompositionEntityValidationData child : childNodes) { - if (CollectionUtils.isNotEmpty(child.getErrors())) { - addNodeWithErrors(child, compositionSet); - } + for (CompositionEntityValidationData child : entity.getSubEntitiesValidationData()) { getEntityListWithErrors(child, compositionSet); } } - public void addNodeWithErrors(CompositionEntityValidationData node, + private void addNodeWithErrors(CompositionEntityValidationData node, Set<CompositionEntityValidationData> entitiesWithErrors) { CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node - .getEntityType(), node.getEntityId()); + .getEntityType(), node.getEntityId()); compositionNodeToAdd.setErrors(node.getErrors()); compositionNodeToAdd.setSubEntitiesValidationData(null); @@ -446,9 +440,9 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData - entity) { + entity) { for (Map.Entry<CompositionEntityId, CompositionEntityData> entityEntry : entities - .entrySet()) { + .entrySet()) { if (entityEntry.getKey().getId().equals(entity.getEntityId())) { return entityEntry.getValue(); } @@ -458,11 +452,11 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa private void updateValidationCompositionEntityName(Set<CompositionEntityValidationData> - compositionSet) { + compositionSet) { for (CompositionEntityValidationData entity : compositionSet) { String compositionData = getCompositionDataAsString(entity); if (entity.getEntityType().equals(CompositionEntityType.vsp) || - Objects.nonNull(compositionData)) { + Objects.nonNull(compositionData)) { entity.setEntityName(getEntityNameByEntityType(compositionData, entity)); } } @@ -497,8 +491,8 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa CompositionEntityData vspEntity = getCompositionEntityDataById(entity); VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity; VspDetails vspDetails = - vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(), - vspQuestionnaireEntity.getVersion())); + vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(), + vspQuestionnaireEntity.getVersion())); return vspDetails.getName(); } @@ -514,7 +508,7 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa if (hasChildren(node)) { Collection<CompositionEntityValidationData> subNodes = - new ArrayList<>(node.getSubEntitiesValidationData()); + new ArrayList<>(node.getSubEntitiesValidationData()); subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node)); node.setSubEntitiesValidationData(subNodes); @@ -543,14 +537,14 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa private void addValidationDataEntity( - Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData, - CompositionEntityId entityId, CompositionEntity entity) { + Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData, + CompositionEntityId entityId, CompositionEntity entity) { if (entitiesValidationData.containsKey(entityId)) { return; } CompositionEntityValidationData validationData = - new CompositionEntityValidationData(entity.getType(), entity.getId()); + new CompositionEntityValidationData(entity.getType(), entity.getId()); entitiesValidationData.put(entityId, validationData); CompositionEntityId parentEntityId = entityId.getParentId(); @@ -578,16 +572,16 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa if (node.getSubEntitiesValidationData() != null) { node.getSubEntitiesValidationData() - .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors)); + .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors)); } } private Collection<String> validateQuestionnaire(CompositionEntityData compositionEntityData) { logger.debug(String.format("validateQuestionnaire start: " + - "[entity.type]=%s, [entity.id]=%s, [entity.questionnaireString]=%s", - compositionEntityData.entity.getType().name(), - compositionEntityData.entity.getCompositionEntityId().toString(), - compositionEntityData.entity.getQuestionnaireData())); + "[entity.type]=%s, [entity.id]=%s, [entity.questionnaireString]=%s", + compositionEntityData.entity.getType().name(), + compositionEntityData.entity.getCompositionEntityId().toString(), + compositionEntityData.entity.getQuestionnaireData())); if (Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) || !JsonUtil.isValidJson(compositionEntityData.entity.getQuestionnaireData())) { @@ -596,20 +590,20 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa } return JsonUtil.validate( - compositionEntityData.entity.getQuestionnaireData() == null - ? JsonUtil.object2Json(new Object()) - : compositionEntityData.entity.getQuestionnaireData(), - getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire, - compositionEntityData.schemaTemplateInput)); + compositionEntityData.entity.getQuestionnaireData() == null + ? JsonUtil.object2Json(new Object()) + : compositionEntityData.entity.getQuestionnaireData(), + getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire, + compositionEntityData.schemaTemplateInput)); } private String getSchema(CompositionEntityType compositionEntityType, SchemaTemplateContext schemaTemplateContext, SchemaTemplateInput schemaTemplateInput) { return schemaTemplateInput == null - ? nonDynamicSchemas.computeIfAbsent(compositionEntityType, - k -> generateSchema(schemaTemplateContext, compositionEntityType, null)) - : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + ? nonDynamicSchemas.computeIfAbsent(compositionEntityType, + k -> generateSchema(schemaTemplateContext, compositionEntityType, null)) + : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput); } private static class CompositionEntityData { @@ -630,7 +624,7 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa CompositionEntityType compositionEntityType, SchemaTemplateInput schemaTemplateInput) { return SchemaGenerator - .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput); } @Override @@ -649,46 +643,33 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa image.setId(CommonMethods.nextUuId()); image.setQuestionnaireData( - new JsonSchemaDataGenerator(SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, null)) - .generateData()); + new JsonSchemaDataGenerator(SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, null)) + .generateData()); imageDao.create(image); mdcDataDebugMessage.debugExitMessage(null, null); return image; } - @Override - public ComputeEntity createCompute(ComputeEntity compute) { - mdcDataDebugMessage.debugEntryMessage("VSP id, component id", compute.getVspId(), - compute.getComponentId()); - - compute.setId(CommonMethods.nextUuId()); - compute.setQuestionnaireData( - new JsonSchemaDataGenerator(SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.compute, - null)).generateData()); - - computeDao.create(compute); - - mdcDataDebugMessage.debugExitMessage("VSP id, component id", compute.getVspId(), - compute.getComponentId()); - return compute; - } - public void saveComputesFlavorByComponent(String vspId, Version version, Component component, String componentId) { if (CollectionUtils.isNotEmpty(component.getCompute())) { for (ComputeData flavor : component.getCompute()) { ComputeEntity computeEntity = new ComputeEntity(vspId, version, componentId, null); computeEntity.setComputeCompositionData(flavor); - createCompute(computeEntity); + computeEntity.setQuestionnaireData( + new JsonSchemaDataGenerator(SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.compute, + null)).generateData()); + + computeDao.create(computeEntity); } } } public void saveImagesByComponent(String vspId, Version version, Component component, String - componentId) { + componentId) { if (CollectionUtils.isNotEmpty(component.getImages())) { for (Image img : component.getImages()) { ImageEntity imageEntity = new ImageEntity(vspId, version, componentId, null); diff --git a/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 b/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 640777e993..45746ed84e 100644 --- a/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 +++ b/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 @@ -72,577 +72,591 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; public class CandidateServiceImpl implements CandidateService { - protected static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + protected static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator(); - private ManifestCreator manifestCreator; - private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao; + private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator(); + private ManifestCreator manifestCreator; + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; - public CandidateServiceImpl(ManifestCreator manifestCreator, - OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao) { - this.manifestCreator = manifestCreator; - this.orchestrationTemplateCandidateDataDao = orchestrationTemplateCandidateDataDao; + public CandidateServiceImpl(ManifestCreator manifestCreator, + OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao) { + this.manifestCreator = manifestCreator; + this.orchestrationTemplateCandidateDao = orchestrationTemplateCandidateDao; - } + } - public CandidateServiceImpl() { - } + public CandidateServiceImpl() { + } - @Override - public Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream fileToUpload) { + @Override + public Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream fileToUpload) { - mdcDataDebugMessage.debugEntryMessage(null); + mdcDataDebugMessage.debugEntryMessage(null); - if (Objects.isNull(fileToUpload)) { - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); - } else { - try { - int available = fileToUpload.available(); - if (available == 0) { - mdcDataDebugMessage.debugExitMessage(null); - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); - } - } catch (IOException e) { - logger.debug(e.getMessage(), e); - mdcDataDebugMessage.debugExitMessage(null); - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); - } + if (Objects.isNull(fileToUpload)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } else { + try { + int available = fileToUpload.available(); + if (available == 0) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); } - + } catch (IOException e) { + logger.debug(e.getMessage(), e); mdcDataDebugMessage.debugExitMessage(null); - return Optional.empty(); + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } } - @Override - public Optional<ErrorMessage> validateRawZipData(byte[] uploadedFileData) { - if (Objects.isNull(uploadedFileData)) { - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); - } - return Optional.empty(); - } - - private String heatStructureTreeToFileDataStructure(HeatStructureTree tree, - FileContentHandler zipContentMap, - Map<String, List<ErrorMessage>> uploadErrors, - AnalyzedZipHeatFiles analyzedZipHeatFiles) - throws Exception { - FilesDataStructure structure = new FilesDataStructure(); - Set<String> usedEnvFiles = new HashSet<>(); - addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors, - analyzedZipHeatFiles); - handleOtherResources(tree, usedEnvFiles, structure); - FilesDataStructure fileDataStructureFromManifest = - createFileDataStructureFromManifest(zipContentMap.getFileContent - (SdcCommon.MANIFEST_NAME)); - List<String> structureArtifacts = structure.getArtifacts(); - structureArtifacts.addAll(fileDataStructureFromManifest.getArtifacts().stream().filter - (artifact -> isNotStrctureArtifact(structureArtifacts, artifact)).collect((Collectors.toList()))); - handleArtifactsFromTree(tree, structure); - - return JsonUtil.object2Json(structure); - } - - private boolean isNotStrctureArtifact(List<String> structureArtifacts, String artifact) { - return !structureArtifacts.contains(artifact); - } - - @Override - public OrchestrationTemplateCandidateData createCandidateDataEntity( - CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, - AnalyzedZipHeatFiles analyzedZipHeatFiles) throws Exception { - - - mdcDataDebugMessage.debugEntryMessage(null); - - FileContentHandler zipContentMap = candidateDataEntityTo.getContentMap(); - FilesDataStructure filesDataStructure; - String dataStructureJson; - - if (zipFileManifest != null) { - // create data structure from manifest - filesDataStructure = createFileDataStructureFromManifest(zipFileManifest); - Set<String> zipFileList = zipContentMap.getFileList(); - balanceManifestFilesWithZipFiles(filesDataStructure, - zipContentMap, analyzedZipHeatFiles); - Set<String> filesDataStructureFiles = getFlatFileNames(filesDataStructure); - filesDataStructure.getUnassigned().addAll(zipFileList.stream() - .filter(fileName -> (!filesDataStructureFiles.contains(fileName) && - !filesDataStructure.getNested().contains(fileName) && - !fileName.equals(SdcCommon.MANIFEST_NAME))) - .collect(Collectors.toList())); - dataStructureJson = JsonUtil.object2Json(filesDataStructure); - } else { - // create data structure from based on naming convention - dataStructureJson = - heatStructureTreeToFileDataStructure(candidateDataEntityTo.getTree(), zipContentMap, - candidateDataEntityTo.getErrors(), analyzedZipHeatFiles); - } + mdcDataDebugMessage.debugExitMessage(null); + return Optional.empty(); + } - mdcDataDebugMessage.debugExitMessage(null); - return new OrchestrationTemplateCandidateData( - ByteBuffer.wrap(candidateDataEntityTo.getUploadedFileData()), dataStructureJson); - } - - private void balanceManifestFilesWithZipFiles( - FilesDataStructure filesDataStructure, - FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) - throws Exception { - Set<String> zipFileList = fileContentHandler.getFileList(); - filesDataStructure.getNested().addAll(analyzedZipHeatFiles.getNestedFiles()); - List<Module> modules = filesDataStructure.getModules(); - if (CollectionUtils.isEmpty(modules)) { - return; - } + @Override + public Optional<ErrorMessage> validateRawZipData(byte[] uploadedFileData) { + if (Objects.isNull(uploadedFileData)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } + return Optional.empty(); + } + + private String heatStructureTreeToFileDataStructure(HeatStructureTree tree, + FileContentHandler zipContentMap, + Map<String, List<ErrorMessage>> uploadErrors, + AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + FilesDataStructure structure = new FilesDataStructure(); + Set<String> usedEnvFiles = new HashSet<>(); + addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors, + analyzedZipHeatFiles); + handleOtherResources(tree, usedEnvFiles, structure); + FilesDataStructure fileDataStructureFromManifest = + createFileDataStructureFromManifest(zipContentMap.getFileContent + (SdcCommon.MANIFEST_NAME)); + List<String> structureArtifacts = structure.getArtifacts(); + structureArtifacts.addAll(fileDataStructureFromManifest.getArtifacts().stream().filter + (artifact -> isNotStrctureArtifact(structureArtifacts, artifact)) + .collect((Collectors.toList()))); + handleArtifactsFromTree(tree, structure); + + return JsonUtil.object2Json(structure); + } + + private boolean isNotStrctureArtifact(List<String> structureArtifacts, String artifact) { + return !structureArtifacts.contains(artifact); + } - for (int i = 0; i < modules.size(); i++) { - Module module = modules.get(i); - if (!isFileExistInZipContains(zipFileList, module.getYaml())) { - addFileToUnassigned(filesDataStructure, zipFileList, module.getEnv()); - addFileToUnassigned(filesDataStructure, zipFileList, module.getVol()); - addFileToUnassigned(filesDataStructure, zipFileList, module.getVolEnv()); - modules.remove(i--); - } else if (Objects.nonNull(module.getVol()) && !zipFileList.contains(module.getVol())) { - module.setVol(null); - CollectionUtils - .addIgnoreNull(filesDataStructure.getUnassigned(), module.getVolEnv()); - } else { - if (filesDataStructure.getNested().contains(module.getYaml())) { - moveModuleFileToNested(filesDataStructure, i--, module); - } - } - } - } + @Override + public OrchestrationTemplateCandidateData createCandidateDataEntity( + CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, + AnalyzedZipHeatFiles analyzedZipHeatFiles) throws Exception { + + + mdcDataDebugMessage.debugEntryMessage(null); + + FileContentHandler zipContentMap = candidateDataEntityTo.getContentMap(); + FilesDataStructure filesDataStructure; + String dataStructureJson; + + if (zipFileManifest != null) { + // create data structure from manifest + filesDataStructure = createFileDataStructureFromManifest(zipFileManifest); + Set<String> zipFileList = zipContentMap.getFileList(); + balanceManifestFilesWithZipFiles(filesDataStructure, + zipContentMap, analyzedZipHeatFiles); + Set<String> filesDataStructureFiles = getFlatFileNames(filesDataStructure); + filesDataStructure.getUnassigned().addAll(zipFileList.stream() + .filter(fileName -> (!filesDataStructureFiles.contains(fileName) && + !filesDataStructure.getNested().contains(fileName) && + !fileName.equals(SdcCommon.MANIFEST_NAME))) + .collect(Collectors.toList())); + dataStructureJson = JsonUtil.object2Json(filesDataStructure); + } else { + // create data structure from based on naming convention + dataStructureJson = + heatStructureTreeToFileDataStructure(candidateDataEntityTo.getTree(), zipContentMap, + candidateDataEntityTo.getErrors(), analyzedZipHeatFiles); + } + + OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); + candidateData.setContentData(ByteBuffer.wrap(candidateDataEntityTo.getUploadedFileData())); + candidateData.setFilesDataStructure(dataStructureJson); + + mdcDataDebugMessage.debugExitMessage(null); + return candidateData; + } + + private void balanceManifestFilesWithZipFiles( + FilesDataStructure filesDataStructure, + FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + Set<String> zipFileList = fileContentHandler.getFileList(); + filesDataStructure.getNested().addAll(analyzedZipHeatFiles.getNestedFiles()); + List<Module> modules = filesDataStructure.getModules(); + if (CollectionUtils.isEmpty(modules)) { + return; + } + + for (int i = 0; i < modules.size(); i++) { + Module module = modules.get(i); + if (!isFileExistInZipContains(zipFileList, module.getYaml())) { + addFileToUnassigned(filesDataStructure, zipFileList, module.getEnv()); + addFileToUnassigned(filesDataStructure, zipFileList, module.getVol()); + addFileToUnassigned(filesDataStructure, zipFileList, module.getVolEnv()); + modules.remove(i--); + } else if (Objects.nonNull(module.getVol()) && !zipFileList.contains(module.getVol())) { + module.setVol(null); + CollectionUtils + .addIgnoreNull(filesDataStructure.getUnassigned(), module.getVolEnv()); + } else { + if (filesDataStructure.getNested().contains(module.getYaml())) { + moveModuleFileToNested(filesDataStructure, i--, module); + } + } + } + } + + private void addFileToUnassigned(FilesDataStructure filesDataStructure, Set<String> zipFileList, + String fileName) { + if (isFileExistInZipContains(zipFileList, fileName)) { + filesDataStructure.getUnassigned().add(fileName); + } + } + + private boolean isFileExistInZipContains(Set<String> zipFileList, String fileName) { + return Objects.nonNull(fileName) && zipFileList.contains(fileName); + } + + private void moveModuleFileToNested(FilesDataStructure filesDataStructure, int i, + Module module) { + if (!filesDataStructure.getNested().contains(module.getYaml())) { + filesDataStructure.getNested().add(module.getYaml()); + } + if (Objects.nonNull(module.getEnv())) { + filesDataStructure.getNested().add(module.getEnv()); + } + if (Objects.nonNull(module.getVol())) { + filesDataStructure.getNested().add(module.getVol()); + } + if (Objects.nonNull(module.getVolEnv())) { + filesDataStructure.getNested().add(module.getVolEnv()); + } + filesDataStructure.getModules().remove(i); + } + + private Set<String> getFlatFileNames(FilesDataStructure filesDataStructure) { + Set<String> fileNames = new HashSet<>(); + if (!CollectionUtils.isEmpty(filesDataStructure.getModules())) { + for (Module module : filesDataStructure.getModules()) { + CollectionUtils.addIgnoreNull(fileNames, module.getEnv()); + CollectionUtils.addIgnoreNull(fileNames, module.getVol()); + CollectionUtils.addIgnoreNull(fileNames, module.getVolEnv()); + CollectionUtils.addIgnoreNull(fileNames, module.getYaml()); + } + } + fileNames.addAll(filesDataStructure.getArtifacts().stream().collect(Collectors.toSet())); + fileNames.addAll(filesDataStructure.getNested().stream().collect(Collectors.toSet())); + fileNames.addAll(filesDataStructure.getUnassigned().stream().collect(Collectors.toSet())); + + return fileNames; + } + + private FilesDataStructure createFileDataStructureFromManifest(InputStream isManifestContent) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + ManifestContent manifestContent = + JsonUtil.json2Object(isManifestContent, ManifestContent.class); + FilesDataStructure structure = new FilesDataStructure(); + for (FileData fileData : manifestContent.getData()) { + if (Objects.nonNull(fileData.getType()) && + fileData.getType().equals(FileData.Type.HEAT)) { + Module module = new Module(); + module.setYaml(fileData.getFile()); + module.setIsBase(fileData.getBase()); + addHeatDependenciesToModule(module, fileData.getData()); + structure.getModules().add(module); + } else if (HeatFileAnalyzer.isYamlOrEnvFile(fileData.getFile()) && + !FileData.Type.isArtifact(fileData.getType())) { + structure.getUnassigned().add(fileData.getFile()); + } else { + structure.getArtifacts().add(fileData.getFile()); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + return structure; + } + + private void addHeatDependenciesToModule(Module module, List<FileData> data) { + if (CollectionUtils.isEmpty(data)) { + return; + } + + for (FileData fileData : data) { + if (fileData.getType().equals(FileData.Type.HEAT_ENV)) { + module.setEnv(fileData.getFile()); + } else if (fileData.getType().equals(FileData.Type.HEAT_VOL))// must be volume + { + module.setVol(fileData.getFile()); + if (!CollectionUtils.isEmpty(fileData.getData())) { + FileData volEnv = fileData.getData().get(0); + if (volEnv.getType().equals(FileData.Type.HEAT_ENV)) { + module.setVolEnv(volEnv.getFile()); + } else { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()) + .withMessage(Messages.ILLEGAL_MANIFEST.getErrorMessage()) + .withId(Messages.ILLEGAL_MANIFEST.getErrorMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); + } + } + } else { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()) + .withMessage(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) + .withId(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); + } + } + } - private void addFileToUnassigned(FilesDataStructure filesDataStructure, Set<String> zipFileList, - String fileName) { - if (isFileExistInZipContains(zipFileList, fileName)) { - filesDataStructure.getUnassigned().add(fileName); - } - } + @Override + public void updateCandidateUploadData(String vspId, Version version, + OrchestrationTemplateCandidateData uploadData) { + mdcDataDebugMessage.debugEntryMessage(null); - private boolean isFileExistInZipContains(Set<String> zipFileList, String fileName) { - return Objects.nonNull(fileName) && zipFileList.contains(fileName); - } + orchestrationTemplateCandidateDao.update(vspId, version, uploadData); - private void moveModuleFileToNested(FilesDataStructure filesDataStructure, int i, - Module module) { - if (!filesDataStructure.getNested().contains(module.getYaml())) { - filesDataStructure.getNested().add(module.getYaml()); - } - if (Objects.nonNull(module.getEnv())) { - filesDataStructure.getNested().add(module.getEnv()); - } - if (Objects.nonNull(module.getVol())) { - filesDataStructure.getNested().add(module.getVol()); - } - if (Objects.nonNull(module.getVolEnv())) { - filesDataStructure.getNested().add(module.getVolEnv()); - } - filesDataStructure.getModules().remove(i); - } - - private Set<String> getFlatFileNames(FilesDataStructure filesDataStructure) { - Set<String> fileNames = new HashSet<>(); - if (!CollectionUtils.isEmpty(filesDataStructure.getModules())) { - for (Module module : filesDataStructure.getModules()) { - CollectionUtils.addIgnoreNull(fileNames, module.getEnv()); - CollectionUtils.addIgnoreNull(fileNames, module.getVol()); - CollectionUtils.addIgnoreNull(fileNames, module.getVolEnv()); - CollectionUtils.addIgnoreNull(fileNames, module.getYaml()); - } - } - fileNames.addAll(filesDataStructure.getArtifacts().stream().collect(Collectors.toSet())); - fileNames.addAll(filesDataStructure.getNested().stream().collect(Collectors.toSet())); - fileNames.addAll(filesDataStructure.getUnassigned().stream().collect(Collectors.toSet())); - - return fileNames; - } - - private FilesDataStructure createFileDataStructureFromManifest(InputStream isManifestContent) { - - - mdcDataDebugMessage.debugEntryMessage(null); - - ManifestContent manifestContent = - JsonUtil.json2Object(isManifestContent, ManifestContent.class); - FilesDataStructure structure = new FilesDataStructure(); - for (FileData fileData : manifestContent.getData()) { - if (Objects.nonNull(fileData.getType()) && - fileData.getType().equals(FileData.Type.HEAT)) { - Module module = new Module(); - module.setYaml(fileData.getFile()); - module.setIsBase(fileData.getBase()); - addHeatDependenciesToModule(module, fileData.getData()); - structure.getModules().add(module); - } else if (HeatFileAnalyzer.isYamlOrEnvFile(fileData.getFile()) && - !FileData.Type.isArtifact(fileData.getType())) { - structure.getUnassigned().add(fileData.getFile()); - } else { - structure.getArtifacts().add(fileData.getFile()); - } - } + mdcDataDebugMessage.debugExitMessage(null); + } - mdcDataDebugMessage.debugExitMessage(null); - return structure; - } + @Override + public Optional<FilesDataStructure> getOrchestrationTemplateCandidateFileDataStructure( + String vspId, Version version) { - private void addHeatDependenciesToModule(Module module, List<FileData> data) { - if (CollectionUtils.isEmpty(data)) { - return; - } + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); - for (FileData fileData : data) { - if (fileData.getType().equals(FileData.Type.HEAT_ENV)) { - module.setEnv(fileData.getFile()); - } else if (fileData.getType().equals(FileData.Type.HEAT_VOL))// must be volume - { - module.setVol(fileData.getFile()); - if (!CollectionUtils.isEmpty(fileData.getData())) { - FileData volEnv = fileData.getData().get(0); - if (volEnv.getType().equals(FileData.Type.HEAT_ENV)) { - module.setVolEnv(volEnv.getFile()); - } else { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(Messages.ILLEGAL_MANIFEST.getErrorMessage()) - .withId(Messages.ILLEGAL_MANIFEST.getErrorMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); - } - } - } else { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) - .withId(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); - } - } - } + Optional<String> jsonFileDataStructure = + orchestrationTemplateCandidateDao.getStructure(vspId, version); - @Override - public void updateCandidateUploadData(OrchestrationTemplateCandidateData uploadData, - String itemId) { - mdcDataDebugMessage.debugEntryMessage(null); - orchestrationTemplateCandidateDataDao.update(itemId, uploadData); - mdcDataDebugMessage.debugExitMessage(null); + if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) { + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + return Optional + .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); + } else { + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + return Optional.empty(); } + } - @Override - public Optional<FilesDataStructure> getOrchestrationTemplateCandidateFileDataStructure( - String vspId, Version version) { - - mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); - - Optional<String> jsonFileDataStructure = - orchestrationTemplateCandidateDataDao.getStructure(vspId, version); + @Override + public void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version, + FilesDataStructure fileDataStructure) { + OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface() + .updateStructure(vspId, version, fileDataStructure); + } - if (jsonFileDataStructure.isPresent() - && JsonUtil.isValidJson(jsonFileDataStructure.get())) { - mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); - return Optional - .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); - } else { - mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); - return Optional.empty(); - } - } + @Override + public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidate(String vspId, + Version version) { + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); - @Override - public void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version, - FilesDataStructure fileDataStructure) { - OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface() - .updateStructure(vspId, version, fileDataStructure); - } + return orchestrationTemplateCandidateDao.get(vspId, version); + } - @Override - public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidate(String vspId, - Version version) { - mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); - mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + @Override + public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidateInfo(String vspId, + Version version) { + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); - return orchestrationTemplateCandidateDataDao.get(vspId, version); - } + return orchestrationTemplateCandidateDao.getInfo(vspId, version); + } @Override public String createManifest(VspDetails vspDetails, FilesDataStructure structure) { - mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); - - Optional<ManifestContent> manifest = manifestCreator.createManifest(vspDetails, structure); - if (!manifest.isPresent()) { - throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); - } + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); - mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); - return JsonUtil.object2Json(manifest.get()); - } - - @Override - public Optional<ManifestContent> createManifest(VspDetails vspDetails, - FileContentHandler fileContentHandler, - AnalyzedZipHeatFiles analyzedZipHeatFiles) { - - - mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); - - mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); - return manifestCreator.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles); - } - - @Override - public Optional<ByteArrayInputStream> fetchZipFileByteArrayInputStream(String vspId, - OrchestrationTemplateCandidateData candidateDataEntity, - String manifest, - OnboardingTypesEnum type, - Map<String, List<ErrorMessage>> uploadErrors) { - byte[] file; - ByteArrayInputStream byteArrayInputStream = null; - try { - file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId, type); - byteArrayInputStream = new ByteArrayInputStream( - Objects.isNull(file) ? candidateDataEntity.getContentData().array() - : file); - } catch (IOException e) { - ErrorMessage errorMessage = - new ErrorMessage(ErrorLevel.ERROR, - Messages.CANDIDATE_PROCESS_FAILED.getErrorMessage()); - logger.error(errorMessage.getMessage(), e); - ErrorsUtil - .addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, errorMessage, uploadErrors); - } - return Optional.ofNullable(byteArrayInputStream); - } - - @Override - public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId, - OnboardingTypesEnum type) - throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - try (final ZipOutputStream zos = new ZipOutputStream(baos); - ZipInputStream zipStream = new ZipInputStream( - new ByteArrayInputStream(contentData.array()))) { - ZipEntry zipEntry; - boolean manifestWritten = false; - while ((zipEntry = zipStream.getNextEntry()) != null) { - if (!zipEntry.getName().equalsIgnoreCase(SdcCommon.MANIFEST_NAME)) { - ZipEntry loc_ze = new ZipEntry(zipEntry.getName()); - zos.putNextEntry(loc_ze); - byte[] buf = new byte[1024]; - int len; - while ((len = zipStream.read(buf)) > 0) { - zos.write(buf, 0, (len < buf.length) ? len : buf.length); - } - } else { - manifestWritten = true; - writeManifest(manifest, type, zos); - } - zos.closeEntry(); - } - if (!manifestWritten) { - writeManifest(manifest, type, zos); - zos.closeEntry(); - } - } - return baos.toByteArray(); + Optional<ManifestContent> manifest = manifestCreator.createManifest(vspDetails, structure); + if (!manifest.isPresent()) { + throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); } - @Override - public Optional<List<ErrorMessage>> validateFileDataStructure( - FilesDataStructure filesDataStructure) { - return candidateServiceValidator.validateFileDataStructure(filesDataStructure); - } + mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); + return JsonUtil.object2Json(manifest.get()); + } - private void writeManifest(String manifest, - OnboardingTypesEnum type, - ZipOutputStream zos) throws IOException { - - if(isManifestNeedsToGetWritten(type)){ - return; - } - - zos.putNextEntry(new ZipEntry(SdcCommon.MANIFEST_NAME)); - try (InputStream manifestStream = new ByteArrayInputStream( - manifest.getBytes(StandardCharsets.UTF_8))) { - byte[] buf = new byte[1024]; - int len; - while ((len = (manifestStream.read(buf))) > 0) { - zos.write(buf, 0, (len < buf.length) ? len : buf.length); - } - } - } + @Override + public Optional<ManifestContent> createManifest(VspDetails vspDetails, + FileContentHandler fileContentHandler, + AnalyzedZipHeatFiles analyzedZipHeatFiles) { - private boolean isManifestNeedsToGetWritten(OnboardingTypesEnum type) { - return type.equals(OnboardingTypesEnum.CSAR); - } - private void handleArtifactsFromTree(HeatStructureTree tree, FilesDataStructure structure) { + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); - if (Objects.isNull(tree) || Objects.isNull(tree.getArtifacts())) { - return; - } - - if (CollectionUtils.isNotEmpty(tree.getArtifacts())) { - structure.getArtifacts().addAll( - tree.getArtifacts() - .stream() - .map(Artifact::getFileName) - .filter(fileName -> !structure.getArtifacts().contains(fileName)) - .collect(Collectors.toList())); - } - } + mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); + return manifestCreator.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles); + } - private void handleOtherResources(HeatStructureTree tree, Set<String> usedEnvFiles, - FilesDataStructure structure) { - Set<HeatStructureTree> others = tree.getOther(); - if (Objects.isNull(others)) { - return; - } + @Override + public Optional<ByteArrayInputStream> fetchZipFileByteArrayInputStream(String vspId, + OrchestrationTemplateCandidateData candidateDataEntity, + String manifest, + OnboardingTypesEnum type, + Map<String, List<ErrorMessage>> uploadErrors) { + byte[] file; + ByteArrayInputStream byteArrayInputStream = null; + try { + file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId, type); + byteArrayInputStream = new ByteArrayInputStream( + Objects.isNull(file) ? candidateDataEntity.getContentData().array() + : file); + } catch (IOException e) { + ErrorMessage errorMessage = + new ErrorMessage(ErrorLevel.ERROR, + Messages.CANDIDATE_PROCESS_FAILED.getErrorMessage()); + logger.error(errorMessage.getMessage(), e); + ErrorsUtil + .addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, errorMessage, uploadErrors); + } + return Optional.ofNullable(byteArrayInputStream); + } - List<String> artifacts = new ArrayList<>(); - List<String> unassigned = new ArrayList<>(); - for (HeatStructureTree other : others) { - if (HeatFileAnalyzer.isYamlOrEnvFile(other.getFileName())) { - if (isEnvFileUsedByHeatFile(usedEnvFiles, other)) { - continue; - } - unassigned.add(other.getFileName()); - } else { - artifacts.add(other.getFileName()); - } - handleArtifactsFromTree(other, structure); + @Override + public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId, + OnboardingTypesEnum type) + throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + try (final ZipOutputStream zos = new ZipOutputStream(baos); + ZipInputStream zipStream = new ZipInputStream( + new ByteArrayInputStream(contentData.array()))) { + ZipEntry zipEntry; + boolean manifestWritten = false; + while ((zipEntry = zipStream.getNextEntry()) != null) { + if (!zipEntry.getName().equalsIgnoreCase(SdcCommon.MANIFEST_NAME)) { + ZipEntry loc_ze = new ZipEntry(zipEntry.getName()); + zos.putNextEntry(loc_ze); + byte[] buf = new byte[1024]; + int len; + while ((len = zipStream.read(buf)) > 0) { + zos.write(buf, 0, (len < buf.length) ? len : buf.length); + } + } else { + manifestWritten = true; + writeManifest(manifest, type, zos); } - structure.getArtifacts().addAll(artifacts); - structure.getUnassigned().addAll(unassigned); + zos.closeEntry(); + } + if (!manifestWritten) { + writeManifest(manifest, type, zos); + zos.closeEntry(); + } } + return baos.toByteArray(); + } - private boolean isEnvFileUsedByHeatFile(Set<String> usedEnvFiles, HeatStructureTree other) { - if (HeatFileAnalyzer.isEnvFile(other.getFileName())) { - if (usedEnvFiles.contains(other.getFileName())) { - return true; - } - } - return false; - } - - private void addHeatsToFileDataStructure(HeatStructureTree tree, Set<String> usedEnvFiles, - FilesDataStructure structure, - Map<String, List<ErrorMessage>> uploadErrors, - AnalyzedZipHeatFiles analyzedZipHeatFiles) - throws Exception { - List<Module> modules = new ArrayList<>(); - Set<HeatStructureTree> heatsSet = tree.getHeat(); - if (Objects.isNull(heatsSet)) { - return; - } - for (HeatStructureTree heat : heatsSet) { - if (isFileBaseFile(heat.getFileName())) { - handleSingleHeat(structure, modules, heat, uploadErrors); - } else if (isFileModuleFile(heat.getFileName(), - analyzedZipHeatFiles.getModuleFiles())) { - handleSingleHeat(structure, modules, heat, uploadErrors); - } else { - structure.getUnassigned().add(heat.getFileName()); - addNestedToFileDataStructure(heat, structure); - } - if (!Objects.isNull(heat.getEnv())) { - usedEnvFiles.add(heat.getEnv() == null ? null : heat.getEnv().getFileName()); - } - } - structure.setModules(modules); - + @Override + public Optional<List<ErrorMessage>> validateFileDataStructure( + FilesDataStructure filesDataStructure) { + return candidateServiceValidator.validateFileDataStructure(filesDataStructure); + } + + private void writeManifest(String manifest, + OnboardingTypesEnum type, + ZipOutputStream zos) throws IOException { + + if (isManifestNeedsToGetWritten(type)) { + return; + } + + zos.putNextEntry(new ZipEntry(SdcCommon.MANIFEST_NAME)); + try (InputStream manifestStream = new ByteArrayInputStream( + manifest.getBytes(StandardCharsets.UTF_8))) { + byte[] buf = new byte[1024]; + int len; + while ((len = (manifestStream.read(buf))) > 0) { + zos.write(buf, 0, (len < buf.length) ? len : buf.length); + } + } + } + + private boolean isManifestNeedsToGetWritten(OnboardingTypesEnum type) { + return type.equals(OnboardingTypesEnum.CSAR); + } + + private void handleArtifactsFromTree(HeatStructureTree tree, FilesDataStructure structure) { + + if (Objects.isNull(tree) || Objects.isNull(tree.getArtifacts())) { + return; + } + + if (CollectionUtils.isNotEmpty(tree.getArtifacts())) { + structure.getArtifacts().addAll( + tree.getArtifacts() + .stream() + .map(Artifact::getFileName) + .filter(fileName -> !structure.getArtifacts().contains(fileName)) + .collect(Collectors.toList())); + } + } + + private void handleOtherResources(HeatStructureTree tree, Set<String> usedEnvFiles, + FilesDataStructure structure) { + Set<HeatStructureTree> others = tree.getOther(); + if (Objects.isNull(others)) { + return; + } + + List<String> artifacts = new ArrayList<>(); + List<String> unassigned = new ArrayList<>(); + for (HeatStructureTree other : others) { + if (HeatFileAnalyzer.isYamlOrEnvFile(other.getFileName())) { + if (isEnvFileUsedByHeatFile(usedEnvFiles, other)) { + continue; + } + unassigned.add(other.getFileName()); + } else { + artifacts.add(other.getFileName()); + } + handleArtifactsFromTree(other, structure); + } + structure.getArtifacts().addAll(artifacts); + structure.getUnassigned().addAll(unassigned); + } + + private boolean isEnvFileUsedByHeatFile(Set<String> usedEnvFiles, HeatStructureTree other) { + if (HeatFileAnalyzer.isEnvFile(other.getFileName())) { + if (usedEnvFiles.contains(other.getFileName())) { + return true; + } + } + return false; + } + + private void addHeatsToFileDataStructure(HeatStructureTree tree, Set<String> usedEnvFiles, + FilesDataStructure structure, + Map<String, List<ErrorMessage>> uploadErrors, + AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + List<Module> modules = new ArrayList<>(); + Set<HeatStructureTree> heatsSet = tree.getHeat(); + if (Objects.isNull(heatsSet)) { + return; + } + for (HeatStructureTree heat : heatsSet) { + if (isFileBaseFile(heat.getFileName())) { + handleSingleHeat(structure, modules, heat, uploadErrors); + } else if (isFileModuleFile(heat.getFileName(), + analyzedZipHeatFiles.getModuleFiles())) { + handleSingleHeat(structure, modules, heat, uploadErrors); + } else { + structure.getUnassigned().add(heat.getFileName()); + addNestedToFileDataStructure(heat, structure); + } + if (!Objects.isNull(heat.getEnv())) { + usedEnvFiles.add(heat.getEnv() == null ? null : heat.getEnv().getFileName()); + } } + structure.setModules(modules); - private boolean isFileModuleFile(String fileName, Set<String> modulesFileNames) { - return modulesFileNames.contains(fileName); - } + } - private boolean isFileBaseFile(String fileName) { - return manifestCreator.isFileBaseFile(fileName); - } + private boolean isFileModuleFile(String fileName, Set<String> modulesFileNames) { + return modulesFileNames.contains(fileName); + } - private void handleSingleHeat(FilesDataStructure structure, List<Module> modules, - HeatStructureTree heat, - Map<String, List<ErrorMessage>> uploadErrors) { + private boolean isFileBaseFile(String fileName) { + return manifestCreator.isFileBaseFile(fileName); + } + private void handleSingleHeat(FilesDataStructure structure, List<Module> modules, + HeatStructureTree heat, + Map<String, List<ErrorMessage>> uploadErrors) { - mdcDataDebugMessage.debugEntryMessage(null); - Module module = new Module(); - module.setYaml(heat.getFileName()); - module.setIsBase(heat.getBase()); - addNestedToFileDataStructure(heat, structure); - Set<HeatStructureTree> volumeSet = heat.getVolume(); - int inx = 0; - if (Objects.nonNull(volumeSet)) { - handleVolumes(module, volumeSet, structure, inx, uploadErrors); - } - handleEnv(module, heat, false, structure); - modules.add(module); + mdcDataDebugMessage.debugEntryMessage(null); - mdcDataDebugMessage.debugExitMessage(null); + Module module = new Module(); + module.setYaml(heat.getFileName()); + module.setIsBase(heat.getBase()); + addNestedToFileDataStructure(heat, structure); + Set<HeatStructureTree> volumeSet = heat.getVolume(); + int inx = 0; + if (Objects.nonNull(volumeSet)) { + handleVolumes(module, volumeSet, structure, inx, uploadErrors); } + handleEnv(module, heat, false, structure); + modules.add(module); - private void handleVolumes(Module module, Set<HeatStructureTree> volumeSet, - FilesDataStructure structure, int inx, - Map<String, List<ErrorMessage>> uploadErrors) { + mdcDataDebugMessage.debugExitMessage(null); + } + private void handleVolumes(Module module, Set<HeatStructureTree> volumeSet, + FilesDataStructure structure, int inx, + Map<String, List<ErrorMessage>> uploadErrors) { - mdcDataDebugMessage.debugEntryMessage(null); - for (HeatStructureTree volume : volumeSet) { - if (inx++ > 0) { - ErrorsUtil.addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.WARNING, - Messages.MORE_THEN_ONE_VOL_FOR_HEAT.getErrorMessage()), uploadErrors); - break; - } - handleArtifactsFromTree(volume, structure); - module.setVol(volume.getFileName()); - handleEnv(module, volume, true, structure); - addNestedToFileDataStructure(volume, structure); - } + mdcDataDebugMessage.debugEntryMessage(null); - mdcDataDebugMessage.debugExitMessage(null); + for (HeatStructureTree volume : volumeSet) { + if (inx++ > 0) { + ErrorsUtil.addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.WARNING, + Messages.MORE_THEN_ONE_VOL_FOR_HEAT.getErrorMessage()), uploadErrors); + break; + } + handleArtifactsFromTree(volume, structure); + module.setVol(volume.getFileName()); + handleEnv(module, volume, true, structure); + addNestedToFileDataStructure(volume, structure); } - private void handleEnv(Module module, HeatStructureTree tree, boolean isVolEnv, - FilesDataStructure structure) { + mdcDataDebugMessage.debugExitMessage(null); + } + private void handleEnv(Module module, HeatStructureTree tree, boolean isVolEnv, + FilesDataStructure structure) { - mdcDataDebugMessage.debugEntryMessage(null); - if (Objects.nonNull(tree.getEnv())) { - if (isVolEnv) { - module.setVolEnv(tree.getEnv().getFileName()); - } else { - module.setEnv(tree.getEnv().getFileName()); - } - handleArtifactsFromTree(tree.getEnv(), structure); - } + mdcDataDebugMessage.debugEntryMessage(null); - mdcDataDebugMessage.debugExitMessage(null); + if (Objects.nonNull(tree.getEnv())) { + if (isVolEnv) { + module.setVolEnv(tree.getEnv().getFileName()); + } else { + module.setEnv(tree.getEnv().getFileName()); + } + handleArtifactsFromTree(tree.getEnv(), structure); } - private void addNestedToFileDataStructure(HeatStructureTree heat, - FilesDataStructure structure) { - Set<HeatStructureTree> nestedSet = heat.getNested(); - if (Objects.isNull(nestedSet)) { - return; - } - for (HeatStructureTree nested : nestedSet) { - if (structure.getNested().contains(nested.getFileName())) { - continue; - } - structure.getNested().add(nested.getFileName()); - if (CollectionUtils.isNotEmpty(nested.getArtifacts())) { - handleArtifactsFromTree(nested, structure); - } - addNestedToFileDataStructure(nested, structure); - } + mdcDataDebugMessage.debugExitMessage(null); + } + + private void addNestedToFileDataStructure(HeatStructureTree heat, + FilesDataStructure structure) { + Set<HeatStructureTree> nestedSet = heat.getNested(); + if (Objects.isNull(nestedSet)) { + return; + } + for (HeatStructureTree nested : nestedSet) { + if (structure.getNested().contains(nested.getFileName())) { + continue; + } + structure.getNested().add(nested.getFileName()); + if (CollectionUtils.isNotEmpty(nested.getArtifacts())) { + handleArtifactsFromTree(nested, structure); + } + addNestedToFileDataStructure(nested, structure); } + } } diff --git a/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/ManifestCreatorNamingConventionImpl.java b/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/ManifestCreatorNamingConventionImpl.java index eed575ff02..ce18097701 100644 --- a/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/ManifestCreatorNamingConventionImpl.java +++ b/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/ManifestCreatorNamingConventionImpl.java @@ -68,7 +68,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { addArtifactsToManifestFileDataList(filesDataStructure, fileDataList); ManifestContent manifestContent = createManifest(vspDetails, fileDataList); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return Optional.of(manifestContent); } @@ -76,7 +76,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { FilesDataStructure filesDataStructure, List<FileData> fileDataList) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) { for (String nested : filesDataStructure.getNested()) { @@ -84,7 +84,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } @Override @@ -168,7 +168,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { FilesDataStructure filesDataStructure, List<FileData> fileDataList) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); Collection<String> forArtifacts = CollectionUtils .union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); @@ -178,14 +178,14 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } private void addModulesToManifestFileDataList( FilesDataStructure filesDataStructure, List<FileData> fileDataList) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (CollectionUtils.isNotEmpty(filesDataStructure.getModules())) { for (Module module : filesDataStructure.getModules()) { @@ -197,7 +197,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } private void addEnv(Module module, FileData fileData) { |