1 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
3 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
4 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
5 import com.amdocs.zusammen.datatypes.item.Info;
6 import com.amdocs.zusammen.datatypes.item.Relation;
7 import org.openecomp.convertor.ElementConvertor;
8 import org.openecomp.sdc.vendorlicense.dao.types.*;
10 import java.util.stream.Collectors;
11 import java.util.Collection;
12 import java.util.HashSet;
13 import java.util.List;
18 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
21 public class ElementToLicenseKeyGroupConvertor extends ElementConvertor {
23 public LicenseKeyGroupEntity convert(Element element) {
24 if (element == null) {
27 return mapElementToLicenseKeyGroupEntity(element);
32 public LicenseKeyGroupEntity convert(ElementInfo elementInfo) {
33 if (elementInfo == null) {
36 return mapElementInfoToLicenseKeyGroupEntity(elementInfo);
40 private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity(
42 LicenseKeyGroupEntity licenseKeyGroup =
43 new LicenseKeyGroupEntity();
44 licenseKeyGroup.setId(element.getElementId().getValue());
45 mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo());
46 mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations());
47 return licenseKeyGroup;
51 private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) {
52 LicenseKeyGroupEntity licenseKeyGroup =
53 new LicenseKeyGroupEntity();
54 licenseKeyGroup.setId(elementInfo.getId().getValue());
56 mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo());
57 mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations());
58 return licenseKeyGroup;
61 private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) {
62 licenseKeyGroup.setName(info.getName());
63 licenseKeyGroup.setDescription(info.getDescription());
64 licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid"));
65 licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType")));
66 licenseKeyGroup.setOperationalScope(
67 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
68 licenseKeyGroup.setStartDate(info.getProperty("startDate"));
69 licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate"));
71 String thresholdUnit = info.getProperty("thresholdUnits");
73 .setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
75 licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
76 licenseKeyGroup.setIncrements(info.getProperty("increments"));
77 licenseKeyGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
80 private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
81 Collection<Relation> relations) {
82 if (relations != null && relations.size() > 0) {
84 .setReferencingFeatureGroups((relations.stream().map(relation -> relation
85 .getEdge2().getElementId().getValue()).collect(Collectors.toSet())));
89 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
90 Map<String, Object> operationalScope) {
91 if (operationalScope == null || operationalScope.isEmpty()) {
95 Set<OperationalScope> choices = new HashSet<>();
96 ((List<String>) operationalScope.get("choices")).
97 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
99 Object other = operationalScope.get("other");
100 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);