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.impl.zusammen.RelationType;
28 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
30 import java.util.Collection;
31 import java.util.HashSet;
35 public class ElementToFeatureGroupConvertor extends ElementConvertor {
37 public FeatureGroupEntity convert(Element element) {
38 if (element == null) {
41 return mapElementToFeatureGroupEntity(element);
46 public FeatureGroupEntity convert(ElementInfo elementInfo) {
47 if (elementInfo == null) {
50 return mapElementInfoToFeatureGroupEntity(elementInfo);
55 private FeatureGroupEntity mapElementToFeatureGroupEntity(Element element) {
56 FeatureGroupEntity featureGroup =
57 new FeatureGroupEntity();
58 featureGroup.setId(element.getElementId().getValue());
59 mapInfoToFeatureGroup(featureGroup, element.getInfo());
60 mapRelationsToFeatureGroup(featureGroup, element.getRelations());
65 private FeatureGroupEntity mapElementInfoToFeatureGroupEntity(ElementInfo elementInfo) {
66 FeatureGroupEntity featureGroup = new FeatureGroupEntity();
67 featureGroup.setId(elementInfo.getId().getValue());
68 mapInfoToFeatureGroup(featureGroup, elementInfo.getInfo());
69 mapRelationsToFeatureGroup(featureGroup, elementInfo.getRelations());
73 private void mapInfoToFeatureGroup(FeatureGroupEntity featureGroup, Info info) {
74 featureGroup.setName(info.getName());
75 featureGroup.setDescription(info.getDescription());
76 featureGroup.setPartNumber(info.getProperty("partNumber"));
77 featureGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber"));
80 private void mapRelationsToFeatureGroup(FeatureGroupEntity featureGroup,
81 Collection<Relation> relations) {
82 Set<String> entitlementPoolIds = new HashSet<>();
83 Set<String> licenseAgreements = new HashSet<>();
84 Set<String> licenseKeyGroupIds = new HashSet<>();
86 if (relations != null) {
87 for (Relation relation : relations) {
88 if (RelationType.FeatureGroupToEntitlmentPool.name().equals(relation.getType())) {
89 entitlementPoolIds.add(relation.getEdge2().getElementId().getValue());
90 } else if (RelationType.FeatureGroupToLicenseKeyGroup.name().equals(relation.getType())) {
91 licenseKeyGroupIds.add(relation.getEdge2().getElementId().getValue());
92 } else if (RelationType.FeatureGroupToReferencingLicenseAgreement.name()
93 .equals(relation.getType())) {
94 licenseAgreements.add(relation.getEdge2().getElementId().getValue());
98 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
99 featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);
100 featureGroup.setReferencingLicenseAgreements(licenseAgreements);