From 47db64bab2f9555e9e2c7da243d6e0ddcbda4fd8 Mon Sep 17 00:00:00 2001 From: shrikantawachar Date: Mon, 9 Jul 2018 18:53:28 +0530 Subject: Enhance MRN in EP & LKG Enhance MRN in EP & LKG , handling healing , unit tests Change-Id: I60b9ec73bfcdd9a53aa507c6401deab372fdcf58 Issue-ID: SDC-1485 Signed-off-by: shrikantawachar --- .../main/resources/entityHealingConfiguration.json | 3 + .../healers/ManufacturerReferenceNumberHealer.java | 106 +++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java (limited to 'openecomp-be/lib/openecomp-healing-lib') diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json index d8f6986a73..a70c4afc6b 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json @@ -12,6 +12,9 @@ "vlm": { "structure": [ "org.openecomp.sdc.healing.healers.OwnerHealer" + ], + "data": [ + "org.openecomp.sdc.healing.healers.ManufacturerReferenceNumberHealer" ] } } \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java new file mode 100644 index 0000000000..237e4bf55b --- /dev/null +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java @@ -0,0 +1,106 @@ +/* + * Copyright © 2016-2018 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. + */ + +package org.openecomp.sdc.healing.healers; + +import org.openecomp.sdc.healing.interfaces.Healer; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; + +public class ManufacturerReferenceNumberHealer implements Healer { + + private static final String manufacturerReferenceNumber = "MRN"; + private VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance() + .createInterface(); + private static final FeatureGroupDao featureGroupDao = + FeatureGroupDaoFactory.getInstance().createInterface(); + + @Override + public boolean isHealingNeeded(String itemId, Version version) { + return Objects.isNull(vendorLicenseFacade.listEntitlementPools + (itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true : + false; + } + + @Override + public void heal(String itemId, Version version) throws Exception { + + healEntitlementPools(itemId, version); + healLicenseKeyGroups(itemId, version); + healFeatureGroups(itemId, version); + } + + private void healEntitlementPools(String itemId, Version version) { + Collection entitlementPoolEntities = vendorLicenseFacade + .listEntitlementPools(itemId, version); + + for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) { + Set referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups(); + + if (referencingFeatureGroup.size() == 1) { + entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version, + referencingFeatureGroup)); + } else { + entitlementPoolEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); + } + vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity); + } + } + + private void healLicenseKeyGroups(String itemId, Version version) { + Collection licenseKeyGroupEntities = vendorLicenseFacade + .listLicenseKeyGroups(itemId, version); + + for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { + Set referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups(); + if (referencingFeatureGroup.size() == 1) { + licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version, + referencingFeatureGroup)); + } else { + licenseKeyGroupEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); + } + vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity); + } + } + + private String getMRN(String itemId, Version + version, Set referencingFeatureGroup) { + FeatureGroupEntity featureGroupEntity = vendorLicenseFacade.getFeatureGroup(new + FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next())); + return featureGroupEntity.getManufacturerReferenceNumber(); + } + + private void healFeatureGroups(String itemId, Version version) { + + Collection featureGroupEntities = vendorLicenseFacade.listFeatureGroups + (itemId, version); + + for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) { + featureGroupEntity.setManufacturerReferenceNumber(""); + featureGroupDao.update(featureGroupEntity); + } + } +} -- cgit 1.2.3-korg