From 5e5d239283077beefc07e0891ebb76bbb5a3e906 Mon Sep 17 00:00:00 2001 From: ayalaben Date: Tue, 16 Oct 2018 18:13:22 +0300 Subject: VSP submit doesn't validate vlm version Change-Id: If98f41c186b330e7f17e51ef88c6b5e91121f2c9 Issue-ID: SDC-1843 Signed-off-by: ayalaben --- .../impl/VendorSoftwareProductManagerImpl.java | 2 +- .../vendorlicense/facade/VendorLicenseFacade.java | 2 +- .../facade/impl/VendorLicenseFacadeImpl.java | 25 ++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) 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 56ea8daa53..df2e098be7 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 @@ -499,7 +499,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private Collection validateLicensingData(VspDetails vspDetails) { if (vspDetails.getVendorId() != null) { - Optional errorCode = vendorLicenseFacade.validateVendorForUsage(vspDetails.getVendorId()); + Optional errorCode = vendorLicenseFacade.validateVendorForUsage(vspDetails.getVendorId(),vspDetails.getVlmVersion()); if (errorCode.isPresent()) { return Collections.singleton(errorCode.get()); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/facade/VendorLicenseFacade.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/facade/VendorLicenseFacade.java index 42a4699d96..d25a18909e 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/facade/VendorLicenseFacade.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/facade/VendorLicenseFacade.java @@ -70,7 +70,7 @@ public interface VendorLicenseFacade { String licenseAgreementId, Collection featureGroupIds); - Optional validateVendorForUsage(String vlmId); + Optional validateVendorForUsage(String vlmId, Version version); void validate(String vendorLicenseModelId, Version version); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java index 5b39a79c89..50772a3de3 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java @@ -64,6 +64,7 @@ import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.ItemManagerFactory; import org.openecomp.sdc.versioning.VersioningUtil; import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder; import org.openecomp.sdc.versioning.types.Item; import org.openecomp.sdc.versioning.types.ItemStatus; @@ -89,6 +90,10 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { private static final ErrorCode USED_VLM_ARCHIVE_ERROR = new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(FIELD_VALIDATION_ERROR_ERR_ID) .withMessage("The supplied vendor is archived and therefore cannot be used").build(); + private static final ErrorCode USED_VLM_IS_DRAFT_ERROR = + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(FIELD_VALIDATION_ERROR_ERR_ID) + .withMessage("The supplied vendor version is draft and therefor can not be used").build(); + /** * Instantiates a new Vendor license facade. @@ -324,13 +329,21 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { } @Override - public Optional validateVendorForUsage(String vlmId) { + public Optional validateVendorForUsage(String vlmId, Version version) { Item vlm = ItemManagerFactory.getInstance().createInterface().get(vlmId); - return vlm == null - ? Optional.of(USED_VLM_NOT_EXIST_ERROR) - : ItemStatus.ARCHIVED == vlm.getStatus() - ? Optional.of(USED_VLM_ARCHIVE_ERROR) - : Optional.empty(); + if(vlm == null) { + return Optional.of(USED_VLM_NOT_EXIST_ERROR); + } + + if (ItemStatus.ARCHIVED == vlm.getStatus()){ + return Optional.of(USED_VLM_ARCHIVE_ERROR); + } + + if(VersionStatus.Draft.equals(version.getStatus())){ + return Optional.of(USED_VLM_IS_DRAFT_ERROR); + } + + return Optional.empty(); } @Override -- cgit 1.2.3-korg