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.LicenseKeyGroupEntity;
9 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType;
10 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
11 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
12 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.List;
19 import java.util.stream.Collectors;
21 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
24 public class ElementToLicenseKeyGroupConvertor extends ElementConvertor {
26 public LicenseKeyGroupEntity convert(Element element) {
27 if (element == null) {
30 return mapElementToLicenseKeyGroupEntity(element);
35 public LicenseKeyGroupEntity convert(ElementInfo elementInfo) {
36 if (elementInfo == null) {
39 return mapElementInfoToLicenseKeyGroupEntity(elementInfo);
43 private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity(
45 LicenseKeyGroupEntity licenseKeyGroup =
46 new LicenseKeyGroupEntity();
47 licenseKeyGroup.setId(element.getElementId().getValue());
48 mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo());
49 mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations());
50 return licenseKeyGroup;
54 private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) {
55 LicenseKeyGroupEntity licenseKeyGroup =
56 new LicenseKeyGroupEntity();
57 licenseKeyGroup.setId(elementInfo.getId().getValue());
59 mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo());
60 mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations());
61 return licenseKeyGroup;
64 private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) {
65 licenseKeyGroup.setName(info.getName());
66 licenseKeyGroup.setDescription(info.getDescription());
67 licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid"));
68 licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType")));
69 licenseKeyGroup.setOperationalScope(
70 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
71 licenseKeyGroup.setStartDate(info.getProperty("startDate"));
72 licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate"));
74 String thresholdUnit = info.getProperty("thresholdUnits");
76 .setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
78 licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
79 licenseKeyGroup.setIncrements(info.getProperty("increments"));
82 private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
83 Collection<Relation> relations) {
84 if (relations != null && relations.size() > 0) {
86 .setReferencingFeatureGroups((relations.stream().map(relation -> relation
87 .getEdge2().getElementId().getValue()).collect(Collectors.toSet())));
91 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
92 Map<String, Object> operationalScope) {
93 if (operationalScope == null || operationalScope.isEmpty()) {
97 Set<OperationalScope> choices = new HashSet<>();
98 ((List<String>) operationalScope.get("choices")).
99 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
101 Object other = operationalScope.get("other");
102 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);