blob: 6a82d8fa491494736358158073f41a0ed8e415a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package org.openecomp.sdc.healing.healers;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.healing.interfaces.Healer;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.versioning.dao.types.Version;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Created by TALIO on 7/3/2017.
*/
public class VlmVersionHealer implements Healer {
private static final VendorLicenseFacade vendorLicenseFacade =
VendorLicenseFacadeFactory.getInstance().createInterface();
private static final VendorSoftwareProductInfoDao vspInfoDao =
VendorSoftwareProductInfoDaoFactory.getInstance().createInterface();
private static final LicenseAgreementDao licenseAgreementDao =
LicenseAgreementDaoFactory.getInstance().createInterface();
private static final Logger logger =
LoggerFactory.getLogger(VlmVersionHealer.class);
@Override
public Object heal(Map<String, Object> healingParams) throws Exception {
String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
Version version = (Version) healingParams.get(SdcCommon.VERSION);
String user = (String) healingParams.get(SdcCommon.USER);
VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
VersionedVendorLicenseModel vendorLicenseModel;
if(!Objects.isNull(vspDetails.getVlmVersion())) {
return Optional.empty();
}
try{
vendorLicenseModel =
vendorLicenseFacade.getVendorLicenseModel(vspDetails.getVendorId(), null, user);
} catch (Exception e){
logger.debug("No Vlm was found for Vsp " + vspDetails.getName());
return Optional.empty();
}
VendorLicenseModelEntity vlm = vendorLicenseModel.getVendorLicenseModel();
String vlmId = vlm.getId();
Version vlmVersion = vlm.getVersion();
List<LicenseAgreementEntity> laList =
new ArrayList<>(
licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, vlmVersion, null)));
vspDetails.setVlmVersion(vlmVersion);
vspDetails.setLicenseAgreement(laList.get(0).getId());
vspDetails.setFeatureGroups(new ArrayList<>(laList.get(0).getFeatureGroupIds()));
vspInfoDao.update(vspDetails);
return vspDetails;
}
}
|