diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java | 507 |
1 files changed, 216 insertions, 291 deletions
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 818d772db4..d97b8c8c4d 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 @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.facade.impl; import static org.openecomp.sdc.common.errors.ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID; @@ -71,337 +70,263 @@ import org.openecomp.sdc.versioning.types.ItemStatus; public class VendorLicenseFacadeImpl implements VendorLicenseFacade { - private static final VendorLicenseModelDao - vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface(); - private static final LicenseAgreementDao - licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface(); - private static final FeatureGroupDao featureGroupDao = - FeatureGroupDaoFactory.getInstance().createInterface(); - private static final EntitlementPoolDao - entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface(); - private static final LicenseKeyGroupDao - licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); - private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface(); - private static final UniqueValueUtil uniqueValueUtil = new UniqueValueUtil - (UniqueValueDaoFactory.getInstance().createInterface()); - private static final ErrorCode USED_VLM_NOT_EXIST_ERROR = - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(FIELD_VALIDATION_ERROR_ERR_ID) - .withMessage("The supplied vendor does not exist").build(); - 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 therefore can not be used").build(); - - - /** - * Instantiates a new Vendor license facade. - */ - public VendorLicenseFacadeImpl() { - vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - limitDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - } - - @Override - public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) { - FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup); - VersioningUtil - .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); - - return retrieved; - } - - @Override - public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) { - FeatureGroupEntity retrieved = getFeatureGroup(featureGroup); - - FeatureGroupModel featureGroupModel = new FeatureGroupModel(); - featureGroupModel.setFeatureGroup(retrieved); - - for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) { - featureGroupModel.getLicenseKeyGroups().add(licenseKeyGroupDao.get( - new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(), - licenseKeyGroupId))); + private static final VendorLicenseModelDao vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface(); + private static final LicenseAgreementDao licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface(); + private static final FeatureGroupDao featureGroupDao = FeatureGroupDaoFactory.getInstance().createInterface(); + private static final EntitlementPoolDao entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface(); + private static final LicenseKeyGroupDao licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); + private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface(); + private static final UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + private static final ErrorCode USED_VLM_NOT_EXIST_ERROR = new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(FIELD_VALIDATION_ERROR_ERR_ID).withMessage("The supplied vendor does not exist").build(); + 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 therefore can not be used").build(); + + /** + * Instantiates a new Vendor license facade. + */ + public VendorLicenseFacadeImpl() { + vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + limitDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); } - for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) { - featureGroupModel.getEntitlementPools().add(entitlementPoolDao.get( - new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(), - entitlementPoolId))); - } - - return featureGroupModel; - } - - @Override - public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version, - String licenseAgreementId) { - LicenseAgreementEntity retrieved = - getLicenseAgreement(vlmId, version, licenseAgreementId); - - LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel(); - licenseAgreementModel.setLicenseAgreement(retrieved); - for (String featureGroupId : retrieved.getFeatureGroupIds()) { - licenseAgreementModel.getFeatureGroups().add(featureGroupDao - .get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId))); + @Override + public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) { + FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup); + VersioningUtil.validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); + return retrieved; } - return licenseAgreementModel; - } - - @Override - public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) { - entitlementPool.setVersionUuId(CommonMethods.nextUuId()); - uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, - entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId(), - entitlementPool.getName()); - entitlementPoolDao.create(entitlementPool); - return entitlementPool; - } - - @Override - public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) { - EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool); - VersioningUtil - .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); - if (retrieved.equals(entitlementPool)) { - return; + @Override + public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) { + FeatureGroupEntity retrieved = getFeatureGroup(featureGroup); + FeatureGroupModel featureGroupModel = new FeatureGroupModel(); + featureGroupModel.setFeatureGroup(retrieved); + for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) { + featureGroupModel.getLicenseKeyGroups().add( + licenseKeyGroupDao.get(new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(), licenseKeyGroupId))); + } + for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) { + featureGroupModel.getEntitlementPools().add( + entitlementPoolDao.get(new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(), entitlementPoolId))); + } + return featureGroupModel; } - uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, - retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - entitlementPool.setVersionUuId(CommonMethods.nextUuId()); - entitlementPoolDao.update(entitlementPool); - } - - @Override - public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) { - return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, version, null)); - } - - @Override - public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) { - return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, version, null)); - } - @Override - public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) { - LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup); - if (retrieved.equals(licenseKeyGroup)) { - return; + @Override + public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version, String licenseAgreementId) { + LicenseAgreementEntity retrieved = getLicenseAgreement(vlmId, version, licenseAgreementId); + LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel(); + licenseAgreementModel.setLicenseAgreement(retrieved); + for (String featureGroupId : retrieved.getFeatureGroupIds()) { + licenseAgreementModel.getFeatureGroups().add(featureGroupDao.get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId))); + } + return licenseAgreementModel; } - licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId())); - VersioningUtil - .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); - uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, - retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - licenseKeyGroupDao.update(licenseKeyGroup); - } - @Override - public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) { - licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId()); - uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, - licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId(), - licenseKeyGroup.getName()); - licenseKeyGroupDao.create(licenseKeyGroup); - return licenseKeyGroup; - } - - @Override - public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) { - VendorLicenseModelEntity vendorLicenseModel = - vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlmId, version)); - if (vendorLicenseModel == null) { - throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build()); + @Override + public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) { + entitlementPool.setVersionUuId(CommonMethods.nextUuId()); + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId(), entitlementPool.getName()); + entitlementPoolDao.create(entitlementPool); + return entitlementPool; } - return vendorLicenseModel; - } - @Override - public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) { - VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(), - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion(), - null), - featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); - - uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, - licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId(), - licenseAgreement.getName()); - - licenseAgreementDao.create(licenseAgreement); - uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, - licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId(), - licenseAgreement.getName()); - if (licenseAgreement.getFeatureGroupIds() != null) { - for (String addedFgId : licenseAgreement.getFeatureGroupIds()) { - featureGroupDao.addReferencingLicenseAgreement( - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion(), - addedFgId), licenseAgreement.getId()); - } + @Override + public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) { + EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool); + VersioningUtil.validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); + if (retrieved.equals(entitlementPool)) { + return; + } + uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, retrieved.getName(), entitlementPool.getName(), + entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + entitlementPool.setVersionUuId(CommonMethods.nextUuId()); + entitlementPoolDao.update(entitlementPool); } - return licenseAgreement; - } - @Override - public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) { - VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(), - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), - null), - licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); - VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(), - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), - null), - entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE); - uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, - featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId(), - featureGroup.getName()); - - featureGroupDao.create(featureGroup); - uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, - featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId(), - featureGroup.getName()); + @Override + public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) { + return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, version, null)); + } - if (featureGroup.getLicenseKeyGroupIds() != null) { - for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) { - licenseKeyGroupDao.addReferencingFeatureGroup( - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), addedLkgId), - featureGroup.getId()); - } + @Override + public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) { + return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, version, null)); } - if (featureGroup.getEntitlementPoolIds() != null) { - for (String addedEpId : featureGroup.getEntitlementPoolIds()) { - entitlementPoolDao.addReferencingFeatureGroup( - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), addedEpId), featureGroup.getId()); - } + @Override + public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) { + LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup); + if (retrieved.equals(licenseKeyGroup)) { + return; + } + licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId())); + VersioningUtil.validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); + uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, retrieved.getName(), licenseKeyGroup.getName(), + licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + licenseKeyGroupDao.update(licenseKeyGroup); } - return featureGroup; - } - @Override - public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) { - return featureGroupDao.list(new FeatureGroupEntity(vlmId, version, null)); - } + @Override + public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) { + licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId()); + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId(), licenseKeyGroup.getName()); + licenseKeyGroupDao.create(licenseKeyGroup); + return licenseKeyGroup; + } + @Override + public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) { + VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlmId, version)); + if (vendorLicenseModel == null) { + throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build()); + } + return vendorLicenseModel; + } - @Override - public Collection<ErrorCode> validateLicensingData(String vlmId, Version version, - String licenseAgreementId, - Collection<String> featureGroupIds) { + @Override + public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) { + VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(), + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), null), featureGroupDao, + VendorLicenseModelEntity.ENTITY_TYPE); + uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId(), licenseAgreement.getName()); + licenseAgreementDao.create(licenseAgreement); + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId(), licenseAgreement.getName()); + if (licenseAgreement.getFeatureGroupIds() != null) { + for (String addedFgId : licenseAgreement.getFeatureGroupIds()) { + featureGroupDao.addReferencingLicenseAgreement( + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), addedFgId), + licenseAgreement.getId()); + } + } + return licenseAgreement; + } - List<ErrorCode> errorMessages = new ArrayList<>(); + @Override + public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) { + VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(), + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), null), licenseKeyGroupDao, + VendorLicenseModelEntity.ENTITY_TYPE); + VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(), + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), null), entitlementPoolDao, + VendorLicenseModelEntity.ENTITY_TYPE); + uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId(), featureGroup.getName()); + featureGroupDao.create(featureGroup); + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId(), featureGroup.getName()); + if (featureGroup.getLicenseKeyGroupIds() != null) { + for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) { + licenseKeyGroupDao.addReferencingFeatureGroup( + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), addedLkgId), featureGroup.getId()); + } + } + if (featureGroup.getEntitlementPoolIds() != null) { + for (String addedEpId : featureGroup.getEntitlementPoolIds()) { + entitlementPoolDao.addReferencingFeatureGroup( + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), addedEpId), featureGroup.getId()); + } + } + return featureGroup; + } - try { - getLicenseAgreement(vlmId, version, licenseAgreementId); - } catch (CoreException exception) { - errorMessages.add(exception.code()); + @Override + public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) { + return featureGroupDao.list(new FeatureGroupEntity(vlmId, version, null)); } - for (String featureGroupId : featureGroupIds) { - try { - FeatureGroupEntity featureGroup = - getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId)); - if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) { - errorMessages.add(new VersionableSubEntityNotFoundErrorBuilder( - featureGroup.getEntityType(), - featureGroupId, - LicenseAgreementEntity.ENTITY_TYPE, - licenseAgreementId, - version).build()); + @Override + public Collection<ErrorCode> validateLicensingData(String vlmId, Version version, String licenseAgreementId, Collection<String> featureGroupIds) { + List<ErrorCode> errorMessages = new ArrayList<>(); + try { + getLicenseAgreement(vlmId, version, licenseAgreementId); + } catch (CoreException exception) { + errorMessages.add(exception.code()); } - } catch (CoreException exception) { - errorMessages.add(exception.code()); - } + for (String featureGroupId : featureGroupIds) { + try { + FeatureGroupEntity featureGroup = getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId)); + if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) { + errorMessages.add( + new VersionableSubEntityNotFoundErrorBuilder(featureGroup.getEntityType(), featureGroupId, LicenseAgreementEntity.ENTITY_TYPE, + licenseAgreementId, version).build()); + } + } catch (CoreException exception) { + errorMessages.add(exception.code()); + } + } + return errorMessages; } - return errorMessages; - } - @Override public Optional<ErrorCode> 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) - : isDraftVlm(vlm, version) - ? Optional.of(USED_VLM_IS_DRAFT_ERROR) - : Optional.empty(); + return vlm == null ? Optional.of(USED_VLM_NOT_EXIST_ERROR) : ItemStatus.ARCHIVED == vlm.getStatus() ? Optional.of(USED_VLM_ARCHIVE_ERROR) + : isDraftVlm(vlm, version) ? Optional.of(USED_VLM_IS_DRAFT_ERROR) : Optional.empty(); } - private boolean isDraftVlm(Item vlm, Version version) { - return (version == null && isVlmWithoutCertifiedVersions(vlm)) || - (version != null && VersionStatus.Draft.equals(version.getStatus())); - } + private boolean isDraftVlm(Item vlm, Version version) { + return (version == null && isVlmWithoutCertifiedVersions(vlm)) || (version != null && VersionStatus.Draft.equals(version.getStatus())); + } - private boolean isVlmWithoutCertifiedVersions(Item vlm) { + private boolean isVlmWithoutCertifiedVersions(Item vlm) { Integer numOfCertifiedVersions = vlm.getVersionStatusCounters().get(VersionStatus.Certified); return numOfCertifiedVersions == null || numOfCertifiedVersions < 1; } @Override - public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version, - String licenseAgreementId) { - LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId); - LicenseAgreementEntity retrieved = licenseAgreementDao.get(input); - VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE); - return retrieved; - } - - @Override - public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) { - return limitDao.list(new LimitEntity(vlmId, version, epLkgId, null)); - } - - @Override - public LimitEntity createLimit(LimitEntity limit) { - limitDao.create(limit); - return limit; - } + public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version, String licenseAgreementId) { + LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId); + LicenseAgreementEntity retrieved = licenseAgreementDao.get(input); + VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE); + return retrieved; + } - @Override - public void updateLimit(LimitEntity limit) { - limitDao.update(limit); - } + @Override + public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) { + return limitDao.list(new LimitEntity(vlmId, version, epLkgId, null)); + } - @Override - public void validate(String vendorLicenseModelId, Version version) { - Collection<String> allFeatureGroupEntities = new HashSet<>(); - Collection<LicenseAgreementEntity> licenseAgreements = licenseAgreementDao - .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null)); + @Override + public LimitEntity createLimit(LimitEntity limit) { + limitDao.create(limit); + return limit; + } - if (CollectionUtils.isNotEmpty(licenseAgreements)) { - licenseAgreements.forEach(licenseAgreement -> { - if (CollectionUtils.isEmpty(licenseAgreement.getFeatureGroupIds())) { - throw new CoreException( - new SubmitUncompletedLicenseModelErrorBuilder( - SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build()); - } - allFeatureGroupEntities.addAll(licenseAgreement.getFeatureGroupIds()); - }); + @Override + public void updateLimit(LimitEntity limit) { + limitDao.update(limit); + } - allFeatureGroupEntities.forEach(fg -> { - FeatureGroupEntity featureGroupEntity = - featureGroupDao.get(new FeatureGroupEntity(vendorLicenseModelId, version, fg)); - if (CollectionUtils.isEmpty(featureGroupEntity.getEntitlementPoolIds())) { - throw new CoreException( - new SubmitUncompletedLicenseModelErrorBuilder( - SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build()); + @Override + public void validate(String vendorLicenseModelId, Version version) { + Collection<String> allFeatureGroupEntities = new HashSet<>(); + Collection<LicenseAgreementEntity> licenseAgreements = licenseAgreementDao + .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null)); + if (CollectionUtils.isNotEmpty(licenseAgreements)) { + licenseAgreements.forEach(licenseAgreement -> { + if (CollectionUtils.isEmpty(licenseAgreement.getFeatureGroupIds())) { + throw new CoreException(new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build()); + } + allFeatureGroupEntities.addAll(licenseAgreement.getFeatureGroupIds()); + }); + allFeatureGroupEntities.forEach(fg -> { + FeatureGroupEntity featureGroupEntity = featureGroupDao.get(new FeatureGroupEntity(vendorLicenseModelId, version, fg)); + if (CollectionUtils.isEmpty(featureGroupEntity.getEntitlementPoolIds())) { + throw new CoreException(new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build()); + } + }); } - }); } - } - - } |