2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.healing.healers;
19 import org.openecomp.sdc.healing.interfaces.Healer;
20 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
21 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
22 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
23 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
24 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
25 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
26 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
27 import org.openecomp.sdc.versioning.dao.types.Version;
29 import java.util.Collection;
30 import java.util.Objects;
33 public class ManufacturerReferenceNumberHealer implements Healer {
35 private static final String MANUFACTURER_REFERENCE_NUMBER = "MRN";
36 private VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance()
38 private static final FeatureGroupDao featureGroupDao =
39 FeatureGroupDaoFactory.getInstance().createInterface();
42 public boolean isHealingNeeded(String itemId, Version version) {
43 return Objects.isNull(vendorLicenseFacade.listEntitlementPools
44 (itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true :
49 public void heal(String itemId, Version version) throws Exception {
51 healEntitlementPools(itemId, version);
52 healLicenseKeyGroups(itemId, version);
53 healFeatureGroups(itemId, version);
56 private void healEntitlementPools(String itemId, Version version) {
57 Collection<EntitlementPoolEntity> entitlementPoolEntities = vendorLicenseFacade
58 .listEntitlementPools(itemId, version);
60 for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
61 Set<String> referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups();
63 if (referencingFeatureGroup.size() == 1) {
64 entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
65 referencingFeatureGroup));
67 entitlementPoolEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
69 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
73 private void healLicenseKeyGroups(String itemId, Version version) {
74 Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = vendorLicenseFacade
75 .listLicenseKeyGroups(itemId, version);
77 for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
78 Set<String> referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups();
79 if (referencingFeatureGroup.size() == 1) {
80 licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
81 referencingFeatureGroup));
83 licenseKeyGroupEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
85 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
89 private String getMRN(String itemId, Version
90 version, Set<String> referencingFeatureGroup) {
91 FeatureGroupEntity featureGroupEntity = vendorLicenseFacade.getFeatureGroup(new
92 FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next()));
93 return featureGroupEntity.getManufacturerReferenceNumber();
96 private void healFeatureGroups(String itemId, Version version) {
98 Collection<FeatureGroupEntity> featureGroupEntities = vendorLicenseFacade.listFeatureGroups
101 for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
102 featureGroupEntity.setManufacturerReferenceNumber(null);
103 featureGroupDao.update(featureGroupEntity);