diff options
author | Michael Lando <ml636r@att.com> | 2017-08-10 18:21:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-08-10 18:21:36 +0000 |
commit | ce07d7cd59425944f85d0fef5126ebeef731bc7b (patch) | |
tree | a0d8bb991aa164e01eb930b23f34d9e27999602a /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main | |
parent | 46f9fd57f24428f6a6fd0d290b0463e188975231 (diff) | |
parent | 644017cb3edd5b7a077a634ffd5daf2fee6bc088 (diff) |
Merge "[SDC] OnBoard with enabled tests and features"
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main')
5 files changed, 83 insertions, 66 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/ImageErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/ImageErrorBuilder.java index 24883b5c13..9ac6e1b1bb 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/ImageErrorBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/ImageErrorBuilder.java @@ -19,6 +19,8 @@ public class ImageErrorBuilder { private static final String IMAGE_HEAT_READONLY_ATTR_MSG = "Update of attribute %s not allowed " + "for VSP onboarded via HEAT."; + private static final String VFC_IMAGE_DUPLICATE_VERSION_MSG = "Invalid request, Image with version %s" + + " already exists for component with ID %s."; /** @@ -35,6 +37,18 @@ public class ImageErrorBuilder { } /** + * Gets duplicate image version error builder. + * + * @return the duplicate image version error builder + */ + public static ErrorCode getDuplicateImageVersionErrorBuilder(String version, String componentId) { + ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + builder.withId(DUPLICATE_IMAGE_VERSION_NOT_ALLOWED); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_VERSION_MSG, version, componentId )); + return builder.build(); + } + /** * Gets image name format error builder. * * @return the image name format error builder diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java index cd102ebb1d..fc5857bb59 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java @@ -385,27 +385,20 @@ public class ComputeManagerImpl implements ComputeManager { } } - private void validateVfcCompute(ComputeEntity compute, Collection<ComputeEntity> vfcComputeList, String event) { - if(!compute.getComputeCompositionData().getName().matches(VendorSoftwareProductConstants.NAME_PATTERN)) - { - ErrorCode errorCode = ComputeErrorBuilder.getComputeNameFormatErrorBuilder( - VendorSoftwareProductConstants.NAME_PATTERN); - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - event, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); - throw new CoreException(errorCode); - } - - if (isComputeNameDuplicate(vfcComputeList,compute.getComputeCompositionData().getName(), compute.getId())) { - ErrorCode errorCode = DuplicateComputeInComponentErrorBuilder.getDuplicateComputeNameErrorBuilder(compute - .getComputeCompositionData().getName(), compute.getComponentId()); + private void validateVfcCompute(ComputeEntity compute, Collection<ComputeEntity> vfcComputeList, + String event) { + if (isComputeNameDuplicate(vfcComputeList,compute.getComputeCompositionData().getName(), + compute.getId())) { + ErrorCode errorCode = DuplicateComputeInComponentErrorBuilder + .getDuplicateComputeNameErrorBuilder(compute.getComputeCompositionData().getName(), + compute.getComponentId()); - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - event, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + event, ErrorLevel.ERROR.name(), + errorCode.id(),errorCode.message()); - throw new CoreException(errorCode); - } + throw new CoreException(errorCode); + } } private boolean isComputeNameDuplicate(Collection<ComputeEntity> computes, String name, String computeId) { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java index 2e964458d5..5bf144e77e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java @@ -111,17 +111,6 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager { private void validateDeploymentFlavor(DeploymentFlavorEntity deploymentFlavorEntity, String user, Version activeVersion) { - if(!deploymentFlavorEntity.getDeploymentFlavorCompositionData().getModel().matches(VendorSoftwareProductConstants.NAME_PATTERN)) - { - ErrorCode errorCode = DeploymentFlavorErrorBuilder.getDeploymentFlavorNameFormatErrorBuilder( - VendorSoftwareProductConstants.NAME_PATTERN); - - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_NIC, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); - - throw new CoreException(errorCode); - } //Validation for unique model. Collection<DeploymentFlavorEntity> listDeploymentFlavors = listDeploymentFlavors(deploymentFlavorEntity.getVspId(), @@ -367,17 +356,6 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager { updateDeploymentFlavorErrorBuilder.message()); throw new CoreException(updateDeploymentFlavorErrorBuilder); } - else { - if(!deploymentFlavorEntity.getDeploymentFlavorCompositionData().getModel().matches(VendorSoftwareProductConstants.NAME_PATTERN)) - { - ErrorCode errorCode = DeploymentFlavorErrorBuilder.getDeploymentFlavorNameFormatErrorBuilder( - VendorSoftwareProductConstants.NAME_PATTERN); - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_DEPLOYMENT_FLAVOR, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); - throw new CoreException(errorCode); - } - } //deploymentFlavorEntity.setVersion(activeVersion); DeploymentFlavorEntity retrieved = getDeploymentFlavor(deploymentFlavorEntity.getVspId(), deploymentFlavorEntity.getVersion(), diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java index 6a8f9e0c45..b54570f13c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java @@ -36,6 +36,7 @@ import org.openecomp.sdc.versioning.VersioningUtil; import org.openecomp.sdc.versioning.dao.types.Version; import java.util.Collection; +import java.util.stream.Collectors; public class ImageManagerImpl implements ImageManager { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); @@ -296,11 +297,51 @@ public class ImageManagerImpl implements ImageManager { } } + if(!isImageVersionUnique(vspId, version, componentId, imageId, image, user)) + { + ErrorCode errorCode = ImageErrorBuilder.getDuplicateImageVersionErrorBuilder(image + .getVersion(), componentId); + + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), + errorCode.id(),errorCode.message()); + + throw new CoreException(errorCode); + } + imageDao.updateQuestionnaireData(vspId, version, componentId, imageId, questionnaireData); mdcDataDebugMessage.debugExitMessage("VSP id, component id, imageId", vspId, componentId, imageId); } + private boolean isImageVersionUnique(String vspId, Version version, String componentId, String imageId, + ImageDetails image, String user) + { + boolean isPresent = true; + if(image!=null && image.getVersion()!=null) + { + Collection<ImageEntity> imageEntities = imageDao.list(new ImageEntity(vspId, version, componentId, null)); + if(CollectionUtils.isNotEmpty(imageEntities)) + { + imageEntities = imageEntities.stream().filter(imageEntity -> image.getVersion().trim().equalsIgnoreCase( + getImageVersion(vspId, version, componentId, imageEntity, user)) + && !imageEntity.getId().equals(imageId)).collect(Collectors.toList()); + + isPresent = CollectionUtils.isEmpty(imageEntities); + } + } + + return isPresent; + } + + private String getImageVersion(String vspId, Version version, String componentId, ImageEntity imageEntity, String user) + { + QuestionnaireResponse imageQuestionnaire = getImageQuestionnaire(vspId, version, + componentId, imageEntity.getId(), user); + ImageDetails imageDetails = JsonUtil.json2Object(imageQuestionnaire.getData(), ImageDetails.class); + + return imageDetails==null?null:imageDetails.getVersion()!=null?imageDetails.getVersion().trim():null; + } private ImageEntity getImageEntity(String vspId, Version version, String componentId, String imageId) { //validateComponentId(vspId,version,componentId); @@ -322,19 +363,8 @@ public class ImageManagerImpl implements ImageManager { return false; } - private void validateVfcImage(boolean isManual, ImageEntity image, Collection<ImageEntity> vfcImageList, String event) { - if(isManual && !image.getImageCompositionData().getFileName().matches(VendorSoftwareProductConstants.NAME_PATTERN)) - { - ErrorCode errorCode = ImageErrorBuilder.getImageNameFormatErrorBuilder( - VendorSoftwareProductConstants.NAME_PATTERN); - - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - event, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); - - throw new CoreException(errorCode); - } - + private void validateVfcImage(boolean isManual, ImageEntity image, + Collection<ImageEntity> vfcImageList, String event) { if (isImageNameDuplicate(vfcImageList,image.getImageCompositionData().getFileName())) { ErrorCode errorCode = ImageErrorBuilder.getDuplicateImageNameErrorBuilder(image .getImageCompositionData().getFileName(), image.getComponentId()); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 89246376e4..de33ce8cfb 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -136,6 +136,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -747,21 +748,22 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private void updateDeploymentFlavor(VspDetails vspDetails, String user) { final List<String> featureGroups = vspDetails.getFeatureGroups(); if (featureGroups != null && !featureGroups.isEmpty() ) { - /*final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - listDeploymentFlavors(vspDetails.getId(), vspDetails.getVersion(), user);*/ - final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails .getVersion(), null)); - for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { - final String featureGroupId = - deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId(); - if ( !featureGroups.contains(featureGroupId)) { - DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); - deploymentFlavorCompositionData.setFeatureGroupId(null); - vendorSoftwareProductDao.updateDeploymentFlavor(deploymentFlavorEntity); - } + if (Objects.nonNull(deploymentFlavorEntities)) { + deploymentFlavorEntities.forEach(deploymentFlavorEntity -> { + final String featureGroupId = + deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId(); + if ( !featureGroups.contains(featureGroupId)) { + DeploymentFlavor deploymentFlavorCompositionData = + deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + deploymentFlavorCompositionData.setFeatureGroupId(null); + deploymentFlavorEntity.setDeploymentFlavorCompositionData + (deploymentFlavorCompositionData); + vendorSoftwareProductDao.updateDeploymentFlavor(deploymentFlavorEntity); + } + }); } } } |