Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-core / src / main / java / org / openecomp / sdc / vendorlicense / dao / impl / zusammen / convertor / ElementToLicenseAgreementConvertor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
21
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;
30
31 import java.util.Collection;
32 import java.util.Map;
33 import java.util.stream.Collectors;
34
35
36 public class ElementToLicenseAgreementConvertor extends ElementConvertor {
37   @Override
38   public LicenseAgreementEntity convert(Element element) {
39     if (element == null) {
40       return null;
41     }
42     return mapElementToLicenseAgreementEntity(element);
43
44   }
45
46
47   @Override
48   public LicenseAgreementEntity convert(ElementInfo elementInfo) {
49     if (elementInfo == null) {
50       return null;
51     }
52     return mapElementInfoToLicenseAgreementEntity(elementInfo);
53
54   }
55
56
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;
64   }
65
66
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;
74   }
75
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()));
82     }
83
84   }
85
86   private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) {
87
88
89     licenseAgreement.setName(info.getName());
90     licenseAgreement.setDescription(info.getDescription());
91
92     licenseAgreement
93         .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm")));
94     licenseAgreement.setRequirementsAndConstrains(
95         info.getProperty("requirementsAndConstrains"));
96
97   }
98
99   private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) {
100     return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")),
101         (String) licenseTerm.get("other"));
102   }
103
104
105 }