aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager
diff options
context:
space:
mode:
authorsheetalm <sheetal.mudholkar@amdocs.com>2018-01-03 19:42:55 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-01-04 11:31:19 +0000
commit56c19bc9a30d59b7a9893f39bba9450536500411 (patch)
treecae726618cfc09f1efb1552d62a10a57e660399a /openecomp-be/backend/openecomp-sdc-vendor-license-manager
parent5a4e534aa1581504aac9ec809940cc5c561667e0 (diff)
Fix issue in vendor-license.xml
If MRN is updated in feature group then update all linked EPs and Lkgs with new different versionUuId. This will generate new version in vendor-license.xml with updated MRN for EP and Lkgs Change-Id: Ib05d931397f24b8131471f423ca43af49b98df8b Issue-ID: SDC-870 Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java59
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java122
2 files changed, 167 insertions, 14 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,
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java
index b9eacc3e6f..d71bec6055 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java
@@ -1,24 +1,19 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.vendorlicense.impl;
import org.mockito.InjectMocks;
@@ -42,6 +37,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -50,12 +46,9 @@ import java.util.Set;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-/**
- * Created by KATYR on 4/10/2016
- */
-
public class FeatureGroupTest {
//JUnit Test Cases using Mockito
private static final Version VERSION01 = new Version(0, 1);
@@ -258,6 +251,107 @@ public class FeatureGroupTest {
.updateFeatureGroup(existingFG, addedEPs, removedEPs, addedLKGs, removedLKGs);
}
+ @Test
+ public void testUpdateFeatureGroupWithAddedEpsLkgs(){
+ FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
+
+ existingFG.setEntitlementPoolIds(new HashSet<String>());
+ existingFG.setLicenseKeyGroupIds(new HashSet<String>());
+ existingFG.setManufacturerReferenceNumber("MRN");
+
+ doReturn(existingFG).when(featureGroupDao).get(anyObject());
+
+ Set<String> removedEPs = new HashSet<>();
+ Set<String> addedEPs = new HashSet<>();
+
+ addedEPs.add(ep1_id);
+ addedEPs.add(ep2_id);
+ EntitlementPoolEntity ep1 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep1_id);
+ EntitlementPoolEntity ep2 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep2_id);
+ doReturn(ep1).when(entitlementPoolDao).get(ep1);
+ doReturn(ep2).when(entitlementPoolDao).get(ep2);
+
+ Set<String> removedLKGs = new HashSet<>();
+ Set<String> addedLKGs = new HashSet<>();
+
+ addedLKGs.add(lkg1_id);
+ addedLKGs.add(lkg2_id);
+ LicenseKeyGroupEntity lkg1 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg1_id);
+ LicenseKeyGroupEntity lkg2 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg2_id);
+ doReturn(lkg1).when(licenseKeyGroupDao).get(lkg1);
+ doReturn(lkg2).when(licenseKeyGroupDao).get(lkg2);
+
+ doNothing().when(vendorLicenseManagerImpl).updateUniqueName(anyObject(), anyObject(),
+ anyObject(),anyObject(), anyObject());
+
+ FeatureGroupEntity fg = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
+ fg.setManufacturerReferenceNumber("MRN_UPD");
+
+ vendorLicenseManagerImpl.updateFeatureGroup(fg,addedLKGs,removedLKGs, addedEPs,
+ removedEPs);
+
+ verify(vendorLicenseManagerImpl).addLicenseKeyGroupsToFeatureGroupsRef(addedLKGs,
+ fg);
+ verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(removedLKGs,
+ fg);
+ verify(vendorLicenseManagerImpl).addEntitlementPoolsToFeatureGroupsRef(addedEPs,fg);
+ verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(removedEPs,
+ fg);
+
+ verify(featureGroupDao)
+ .updateFeatureGroup(fg,addedEPs,removedEPs, addedLKGs, removedLKGs);
+
+ verify(entitlementPoolDao, times(2)).update(anyObject());
+ verify(licenseKeyGroupDao,times(2)).update(anyObject());
+ }
+
+ @Test
+ public void testUpdateFeatureGroupWithNoAddedEpsLkgs(){
+ FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
+
+ HashSet<String> epSet = new HashSet<String>(); epSet.add(ep1_id);
+ HashSet<String> lkgSet = new HashSet<String>(); lkgSet.add(lkg1_id);
+ existingFG.setEntitlementPoolIds(epSet);
+ existingFG.setLicenseKeyGroupIds(lkgSet);
+ existingFG.setManufacturerReferenceNumber("MRN");
+
+ doReturn(existingFG).when(featureGroupDao).get(anyObject());
+
+ EntitlementPoolEntity ep1 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep1_id);
+ doReturn(ep1).when(entitlementPoolDao).get(ep1);
+
+ LicenseKeyGroupEntity lkg1 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg1_id);
+ doReturn(lkg1).when(licenseKeyGroupDao).get(lkg1);
+
+ Set<String> removedEPs = new HashSet<>();
+ Set<String> addedEPs = new HashSet<>();
+ Set<String> removedLKGs = new HashSet<>();
+ Set<String> addedLKGs = new HashSet<>();
+
+ doNothing().when(vendorLicenseManagerImpl).updateUniqueName(anyObject(), anyObject(),
+ anyObject(),anyObject(), anyObject());
+
+ FeatureGroupEntity fg = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
+ fg.setManufacturerReferenceNumber("MRN_UPD");
+
+ vendorLicenseManagerImpl.updateFeatureGroup(fg,addedLKGs,removedLKGs, addedEPs,
+ removedEPs);
+
+ verify(vendorLicenseManagerImpl).addLicenseKeyGroupsToFeatureGroupsRef(addedLKGs,
+ fg);
+ verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(removedLKGs,
+ fg);
+ verify(vendorLicenseManagerImpl).addEntitlementPoolsToFeatureGroupsRef(addedEPs,fg);
+ verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(removedEPs,
+ fg);
+
+ verify(featureGroupDao)
+ .updateFeatureGroup(fg,addedEPs,removedEPs, addedLKGs, removedLKGs);
+
+ verify(entitlementPoolDao, times(1)).update(anyObject());
+ verify(licenseKeyGroupDao,times(1)).update(anyObject());
+ }
+
@Test
public void testGetFeatureGroup() {