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.ChoiceOrOther;
28 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
29 import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm;
31 import java.util.Collection;
33 import java.util.stream.Collectors;
36 public class ElementToLicenseAgreementConvertor extends ElementConvertor {
38 public LicenseAgreementEntity convert(Element element) {
39 if (element == null) {
42 return mapElementToLicenseAgreementEntity(element);
48 public LicenseAgreementEntity convert(ElementInfo elementInfo) {
49 if (elementInfo == null) {
52 return mapElementInfoToLicenseAgreementEntity(elementInfo);
57 private LicenseAgreementEntity mapElementToLicenseAgreementEntity(Element element) {
58 LicenseAgreementEntity licenseAgreement =
59 new LicenseAgreementEntity();
60 licenseAgreement.setId(element.getElementId().getValue());
61 mapInfoToLicenseAgreementEntity(licenseAgreement, element.getInfo());
62 mapRelationsToLicenseAgreementEntity(licenseAgreement, element.getRelations());
63 return licenseAgreement;
67 private LicenseAgreementEntity mapElementInfoToLicenseAgreementEntity(ElementInfo elementInfo) {
68 LicenseAgreementEntity licenseAgreement =
69 new LicenseAgreementEntity();
70 licenseAgreement.setId( elementInfo.getId().getValue());
71 mapInfoToLicenseAgreementEntity(licenseAgreement, elementInfo.getInfo());
72 mapRelationsToLicenseAgreementEntity(licenseAgreement, elementInfo.getRelations());
73 return licenseAgreement;
76 private void mapRelationsToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreementEntity,
77 Collection<Relation> relations) {
78 if (relations != null && relations.size() > 0) {
79 licenseAgreementEntity.setFeatureGroupIds(relations.stream()
80 .map(relation -> relation.getEdge2().getElementId().getValue())
81 .collect(Collectors.toSet()));
86 private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) {
89 licenseAgreement.setName(info.getName());
90 licenseAgreement.setDescription(info.getDescription());
93 .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm")));
94 licenseAgreement.setRequirementsAndConstrains(
95 info.getProperty("requirementsAndConstrains"));
99 private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) {
100 return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")),
101 (String) licenseTerm.get("other"));