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 final VendorLicenseFacade vendorLicenseFacade;
37 private final FeatureGroupDao featureGroupDao;
39 public ManufacturerReferenceNumberHealer() {
40 this(VendorLicenseFacadeFactory.getInstance().createInterface(), FeatureGroupDaoFactory
41 .getInstance().createInterface());
44 public ManufacturerReferenceNumberHealer(VendorLicenseFacade vendorLicenseFacade,
45 FeatureGroupDao featureGroupDao) {
46 this.vendorLicenseFacade = vendorLicenseFacade;
47 this.featureGroupDao = featureGroupDao;
51 public boolean isHealingNeeded(String itemId, Version version) {
52 return Objects.isNull(vendorLicenseFacade.listEntitlementPools
53 (itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true :
58 public void heal(String itemId, Version version) throws Exception {
60 healEntitlementPools(itemId, version);
61 healLicenseKeyGroups(itemId, version);
62 healFeatureGroups(itemId, version);
65 private void healEntitlementPools(String itemId, Version version) {
66 Collection<EntitlementPoolEntity> entitlementPoolEntities = vendorLicenseFacade
67 .listEntitlementPools(itemId, version);
69 for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
70 Set<String> referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups();
72 if (referencingFeatureGroup.size() == 1) {
73 entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
74 referencingFeatureGroup));
76 entitlementPoolEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
78 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
82 private void healLicenseKeyGroups(String itemId, Version version) {
83 Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = vendorLicenseFacade
84 .listLicenseKeyGroups(itemId, version);
86 for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
87 Set<String> referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups();
88 if (referencingFeatureGroup.size() == 1) {
89 licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
90 referencingFeatureGroup));
92 licenseKeyGroupEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
94 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
98 private String getMRN(String itemId, Version
99 version, Set<String> referencingFeatureGroup) {
100 FeatureGroupEntity featureGroupEntity = vendorLicenseFacade.getFeatureGroup(new
101 FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next()));
102 return featureGroupEntity.getManufacturerReferenceNumber();
105 private void healFeatureGroups(String itemId, Version version) {
107 Collection<FeatureGroupEntity> featureGroupEntities = vendorLicenseFacade.listFeatureGroups
110 for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
111 featureGroupEntity.setManufacturerReferenceNumber(null);
112 featureGroupDao.update(featureGroupEntity);