1 package org.openecomp.sdc.healing.healers;
3 import org.apache.commons.collections4.CollectionUtils;
4 import org.openecomp.sdc.common.utils.SdcCommon;
5 import org.openecomp.sdc.healing.interfaces.Healer;
6 import org.openecomp.sdc.logging.api.Logger;
7 import org.openecomp.sdc.logging.api.LoggerFactory;
8 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
9 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
10 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
11 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
12 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
13 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
14 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
17 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
18 import org.openecomp.sdc.versioning.dao.types.Version;
19 import org.openecomp.sdc.versioning.types.VersionInfo;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.Objects;
25 import java.util.Optional;
28 * Created by TALIO on 7/3/2017.
30 public class VlmVersionHealer implements Healer {
31 private static final VendorLicenseFacade vendorLicenseFacade =
32 VendorLicenseFacadeFactory.getInstance().createInterface();
33 private static final VendorSoftwareProductInfoDao vspInfoDao =
34 VendorSoftwareProductInfoDaoFactory.getInstance().createInterface();
35 private static final LicenseAgreementDao licenseAgreementDao =
36 LicenseAgreementDaoFactory.getInstance().createInterface();
37 private static final Logger logger =
38 LoggerFactory.getLogger(VlmVersionHealer.class);
41 public Object heal(Map<String, Object> healingParams) throws Exception {
42 String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
43 Version version = (Version) healingParams.get(SdcCommon.VERSION);
44 String user = (String) healingParams.get(SdcCommon.USER);
46 VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
47 VersionedVendorLicenseModel vendorLicenseModel;
49 if(!Objects.isNull(vspDetails.getVlmVersion())) {
50 return Optional.empty();
56 vendorLicenseFacade.getVendorLicenseModel(vspDetails.getVendorId(), null, user);
57 } catch (Exception e){
59 logger.debug("No Vlm was found for Vsp " + vspDetails.getName());
60 return Optional.empty();
63 VendorLicenseModelEntity vlm = vendorLicenseModel.getVendorLicenseModel();
64 String vlmId = vlm.getId();
65 Version vlmVersion = getLatestFinalVlmVersion(vendorLicenseModel.getVersionInfo());
67 List<LicenseAgreementEntity> laList =
69 licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, vlmVersion, null)));
72 vspDetails.setVlmVersion(vlmVersion);
74 if(CollectionUtils.isNotEmpty(laList)) {
75 vspDetails.setLicenseAgreement(laList.get(0).getId());
76 vspDetails.setFeatureGroups(new ArrayList<>(laList.get(0).getFeatureGroupIds()));
79 vspInfoDao.update(vspDetails);
84 private Version getLatestFinalVlmVersion(VersionInfo versionInfo){
85 return versionInfo.getActiveVersion().isFinal() ? versionInfo.getActiveVersion()
86 : versionInfo.getLatestFinalVersion();