diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java')
-rw-r--r-- | openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java index ac7379615f..5d5c0076e3 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java @@ -16,7 +16,9 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.apache.commons.collections.CollectionUtils; import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -53,6 +55,7 @@ import org.openecomp.sdc.versioning.dao.types.Version; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Collection; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -271,10 +274,66 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools, addedLicenseKeyGroups, removedLicenseKeyGroups); + updateEpLkgOnMrnChange(featureGroup, addedLicenseKeyGroups, addedEntitlementPools, retrieved); + mdcDataDebugMessage.debugExitMessage(VLM_ID_FG_ID, featureGroup .getVendorLicenseModelId(), featureGroup.getId()); } + /** + * If MRN is updated in feature group then update all linked EPs and Lkgs with new versionUuId + * @param featureGroup - Feature Group entity which is requested for update + * @param addedLicenseKeyGroups - LicenseKeyGroups added with Feature Group + * @param addedEntitlementPools - EntitlementPools added with Feature Group + * @param retrieved - Feature Group entity fetched from database + */ + private void updateEpLkgOnMrnChange(FeatureGroupEntity featureGroup, + Set<String> addedLicenseKeyGroups, + Set<String> addedEntitlementPools, + FeatureGroupEntity retrieved) { + if (Objects.nonNull(retrieved.getManufacturerReferenceNumber()) + && !retrieved.getManufacturerReferenceNumber().equals(featureGroup + .getManufacturerReferenceNumber())) { + if (CollectionUtils.isEmpty(addedEntitlementPools)) { + updateEntitlementPool(featureGroup, retrieved.getEntitlementPoolIds()); + } else { + updateEntitlementPool(featureGroup, addedEntitlementPools); + } + + if (CollectionUtils.isEmpty(addedLicenseKeyGroups)) { + updateLicenseKeyGroup(featureGroup, retrieved.getLicenseKeyGroupIds()); + } else { + updateLicenseKeyGroup(featureGroup, addedLicenseKeyGroups); + } + } + } + + private void updateEntitlementPool(FeatureGroupEntity featureGroup, + Set<String> entitlementPoolIds) { + for (String epId: entitlementPoolIds) { + final EntitlementPoolEntity entitlementPoolEntity = entitlementPoolDao + .get(new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup + .getVersion(), epId)); + if (Objects.nonNull(entitlementPoolEntity)) { + entitlementPoolEntity.setVersionUuId(CommonMethods.nextUuId()); + entitlementPoolDao.update(entitlementPoolEntity); + } + } + } + + private void updateLicenseKeyGroup(FeatureGroupEntity featureGroup, + Set<String> licenseKeyGroupIds) { + for (String lkgId: licenseKeyGroupIds) { + final LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao + .get(new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion(), lkgId)); + if (Objects.nonNull(licenseKeyGroupEntity)) { + licenseKeyGroupEntity.setVersionUuId(CommonMethods.nextUuId()); + licenseKeyGroupDao.update(licenseKeyGroupEntity); + } + } + } + @Override public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) { mdcDataDebugMessage.debugEntryMessage(VLM_ID_FG_ID, |