2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
22 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
23 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
24 import com.amdocs.zusammen.datatypes.item.Info;
25 import com.amdocs.zusammen.datatypes.item.Relation;
26 import org.openecomp.convertor.ElementConvertor;
27 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
28 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
29 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
30 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
32 import java.util.Collection;
33 import java.util.HashSet;
34 import java.util.List;
37 import java.util.stream.Collectors;
39 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
42 public class ElementToEntitlementPoolConvertor extends ElementConvertor {
44 public EntitlementPoolEntity convert(Element element) {
45 if (element == null) {
48 return mapElementToEntitlementPoolEntity(element);
52 public EntitlementPoolEntity convert(ElementInfo elementInfo) {
53 if (elementInfo == null) {
56 return mapElementInfoToEntitlementPoolEntity(elementInfo);
59 private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) {
60 EntitlementPoolEntity entitlementPool =
61 new EntitlementPoolEntity();
62 entitlementPool.setId(element.getElementId().getValue());
63 mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo());
64 mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations());
65 return entitlementPool;
68 private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) {
69 EntitlementPoolEntity entitlementPool =
70 new EntitlementPoolEntity();
71 entitlementPool.setId(elementInfo.getId().getValue());
72 mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo());
73 mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations());
74 return entitlementPool;
77 private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) {
78 entitlementPool.setName(info.getName());
79 entitlementPool.setDescription(info.getDescription());
80 entitlementPool.setVersionUuId(info.getProperty("version_uuid"));
81 entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
82 String thresholdUnit = info.getProperty("threshold_unit");
84 .setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
85 entitlementPool.setIncrements(info.getProperty("increments"));
86 entitlementPool.setOperationalScope(
87 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
88 entitlementPool.setStartDate(info.getProperty("startDate"));
89 entitlementPool.setExpiryDate(info.getProperty("expiryDate"));
90 entitlementPool.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
93 private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool,
94 Collection<Relation> relations) {
95 if (relations != null && relations.size() > 0) {
97 .setReferencingFeatureGroups(relations.stream().map(relation -> relation
98 .getEdge2().getElementId().getValue()).collect(Collectors.toSet()));
102 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
103 Map<String, Object> operationalScope) {
104 if (operationalScope == null || operationalScope.isEmpty()) {
108 Set<OperationalScope> choices = new HashSet<>();
109 ((List<String>) operationalScope.get("choices")).
110 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
112 Object other = operationalScope.get("other");
113 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);