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.EntitlementPoolType;
29 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
30 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
31 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
33 import java.util.Collection;
34 import java.util.HashSet;
35 import java.util.List;
38 import java.util.stream.Collectors;
40 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
43 public class ElementToEntitlementPoolConvertor extends ElementConvertor {
45 public EntitlementPoolEntity convert(Element element) {
46 if (element == null) {
49 return mapElementToEntitlementPoolEntity(element);
53 public EntitlementPoolEntity convert(ElementInfo elementInfo) {
54 if (elementInfo == null) {
57 return mapElementInfoToEntitlementPoolEntity(elementInfo);
60 private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) {
61 EntitlementPoolEntity entitlementPool =
62 new EntitlementPoolEntity();
63 entitlementPool.setId(element.getElementId().getValue());
64 mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo());
65 mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations());
66 return entitlementPool;
69 private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) {
70 EntitlementPoolEntity entitlementPool =
71 new EntitlementPoolEntity();
72 entitlementPool.setId(elementInfo.getId().getValue());
73 mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo());
74 mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations());
75 return entitlementPool;
78 private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) {
79 entitlementPool.setName(info.getName());
80 entitlementPool.setDescription(info.getDescription());
81 entitlementPool.setVersionUuId(info.getProperty("version_uuid"));
82 entitlementPool.setType(EntitlementPoolType.permissiveValueOf(info.getProperty("EntitlementPoolType")));
83 entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
84 String thresholdUnit = info.getProperty("threshold_unit");
86 .setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
87 entitlementPool.setIncrements(info.getProperty("increments"));
88 entitlementPool.setOperationalScope(
89 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
90 entitlementPool.setStartDate(info.getProperty("startDate"));
91 entitlementPool.setExpiryDate(info.getProperty("expiryDate"));
92 entitlementPool.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
95 private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool,
96 Collection<Relation> relations) {
97 if (relations != null && relations.size() > 0) {
99 .setReferencingFeatureGroups(relations.stream().map(relation -> relation
100 .getEdge2().getElementId().getValue()).collect(Collectors.toSet()));
104 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
105 Map<String, Object> operationalScope) {
106 if (operationalScope == null || operationalScope.isEmpty()) {
110 Set<OperationalScope> choices = new HashSet<>();
111 ((List<String>) operationalScope.get("choices")).
112 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
114 Object other = operationalScope.get("other");
115 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);