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.*;
29 import java.util.stream.Collectors;
30 import java.util.Collection;
31 import java.util.HashSet;
32 import java.util.List;
37 import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger;
40 public class ElementToLicenseKeyGroupConvertor extends ElementConvertor {
42 public LicenseKeyGroupEntity convert(Element element) {
43 if (element == null) {
46 return mapElementToLicenseKeyGroupEntity(element);
51 public LicenseKeyGroupEntity convert(ElementInfo elementInfo) {
52 if (elementInfo == null) {
55 return mapElementInfoToLicenseKeyGroupEntity(elementInfo);
59 private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity(
61 LicenseKeyGroupEntity licenseKeyGroup =
62 new LicenseKeyGroupEntity();
63 licenseKeyGroup.setId(element.getElementId().getValue());
64 mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo());
65 mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations());
66 return licenseKeyGroup;
70 private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) {
71 LicenseKeyGroupEntity licenseKeyGroup =
72 new LicenseKeyGroupEntity();
73 licenseKeyGroup.setId(elementInfo.getId().getValue());
75 mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo());
76 mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations());
77 return licenseKeyGroup;
80 private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) {
81 licenseKeyGroup.setName(info.getName());
82 licenseKeyGroup.setDescription(info.getDescription());
83 licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid"));
84 licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType")));
85 licenseKeyGroup.setOperationalScope(
86 getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope")));
87 licenseKeyGroup.setStartDate(info.getProperty("startDate"));
88 licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate"));
90 String thresholdUnit = info.getProperty("thresholdUnits");
92 .setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit));
94 licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue")));
95 licenseKeyGroup.setIncrements(info.getProperty("increments"));
96 licenseKeyGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
99 private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
100 Collection<Relation> relations) {
101 if (relations != null && relations.size() > 0) {
103 .setReferencingFeatureGroups((relations.stream().map(relation -> relation
104 .getEdge2().getElementId().getValue()).collect(Collectors.toSet())));
108 private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(
109 Map<String, Object> operationalScope) {
110 if (operationalScope == null || operationalScope.isEmpty()) {
114 Set<OperationalScope> choices = new HashSet<>();
115 ((List<String>) operationalScope.get("choices")).
116 forEach(choice -> choices.add(OperationalScope.valueOf(choice)));
118 Object other = operationalScope.get("other");
119 return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other);