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.EntitlementPoolEntity;
9 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
10 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
11 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
13 import java.util.Collection;
14 import java.util.HashSet;
15 import java.util.List;
18 import java.util.stream.Collectors;
20 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
23 public class ElementToEntitlementPoolConvertor extends ElementConvertor {
25 public EntitlementPoolEntity convert(Element element) {
26 if (element == null) {
29 return mapElementToEntitlementPoolEntity(element);
33 public EntitlementPoolEntity convert(ElementInfo elementInfo) {
34 if (elementInfo == null) {
37 return mapElementInfoToEntitlementPoolEntity(elementInfo);
40 private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) {
41 EntitlementPoolEntity entitlementPool =
42 new EntitlementPoolEntity();
43 entitlementPool.setId(element.getElementId().getValue());
44 mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo());
45 mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations());
46 return entitlementPool;
49 private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) {
50 EntitlementPoolEntity entitlementPool =
51 new EntitlementPoolEntity();
52 entitlementPool.setId(elementInfo.getId().getValue());
53 mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo());
54 mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations());
55 return entitlementPool;
58 private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) {
59 entitlementPool.setName(info.getName());
60 entitlementPool.setDescription(info.getDescription());
61 entitlementPool.setVersionUuId(info.getProperty("version_uuid"));
62 entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
63 String thresholdUnit = info.getProperty("threshold_unit");
65 .setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
66 entitlementPool.setIncrements(info.getProperty("increments"));
67 entitlementPool.setOperationalScope(
68 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
69 entitlementPool.setStartDate(info.getProperty("startDate"));
70 entitlementPool.setExpiryDate(info.getProperty("expiryDate"));
73 private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool,
74 Collection<Relation> relations) {
75 if (relations != null && relations.size() > 0) {
77 .setReferencingFeatureGroups(relations.stream().map(relation -> relation
78 .getEdge2().getElementId().getValue()).collect(Collectors.toSet()));
82 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
83 Map<String, Object> operationalScope) {
84 if (operationalScope == null || operationalScope.isEmpty()) {
88 Set<OperationalScope> choices = new HashSet<>();
89 ((List<String>) operationalScope.get("choices")).
90 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
92 Object other = operationalScope.get("other");
93 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);