Add collaboration feature
[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 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
2
3 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
4 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
5 import com.amdocs.zusammen.datatypes.item.Info;
6 import com.amdocs.zusammen.datatypes.item.Relation;
7 import org.openecomp.convertor.ElementConvertor;
8 import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther;
9 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
10 import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm;
11
12 import java.util.Collection;
13 import java.util.Map;
14 import java.util.stream.Collectors;
15
16
17 public class ElementToLicenseAgreementConvertor extends ElementConvertor {
18   @Override
19   public LicenseAgreementEntity convert(Element element) {
20     if (element == null) {
21       return null;
22     }
23     return mapElementToLicenseAgreementEntity(element);
24
25   }
26
27
28   @Override
29   public LicenseAgreementEntity convert(ElementInfo elementInfo) {
30     if (elementInfo == null) {
31       return null;
32     }
33     return mapElementInfoToLicenseAgreementEntity(elementInfo);
34
35   }
36
37
38   private LicenseAgreementEntity mapElementToLicenseAgreementEntity(Element element) {
39     LicenseAgreementEntity licenseAgreement =
40         new LicenseAgreementEntity();
41     licenseAgreement.setId(element.getElementId().getValue());
42     mapInfoToLicenseAgreementEntity(licenseAgreement, element.getInfo());
43     mapRelationsToLicenseAgreementEntity(licenseAgreement, element.getRelations());
44     return licenseAgreement;
45   }
46
47
48   private LicenseAgreementEntity mapElementInfoToLicenseAgreementEntity(ElementInfo elementInfo) {
49     LicenseAgreementEntity licenseAgreement =
50         new LicenseAgreementEntity();
51     licenseAgreement.setId( elementInfo.getId().getValue());
52     mapInfoToLicenseAgreementEntity(licenseAgreement, elementInfo.getInfo());
53     mapRelationsToLicenseAgreementEntity(licenseAgreement, elementInfo.getRelations());
54     return licenseAgreement;
55   }
56
57   private void mapRelationsToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreementEntity,
58                                                     Collection<Relation> relations) {
59     if (relations != null && relations.size() > 0) {
60       licenseAgreementEntity.setFeatureGroupIds(relations.stream()
61           .map(relation -> relation.getEdge2().getElementId().getValue())
62           .collect(Collectors.toSet()));
63     }
64
65   }
66
67   private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) {
68
69
70     licenseAgreement.setName(info.getName());
71     licenseAgreement.setDescription(info.getDescription());
72
73     licenseAgreement
74         .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm")));
75     licenseAgreement.setRequirementsAndConstrains(
76         info.getProperty("requirementsAndConstrains"));
77
78   }
79
80   private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) {
81     return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")),
82         (String) licenseTerm.get("other"));
83   }
84
85
86 }