1 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
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;
12 import java.util.Collection;
14 import java.util.stream.Collectors;
17 public class ElementToLicenseAgreementConvertor extends ElementConvertor {
19 public LicenseAgreementEntity convert(Element element) {
20 if (element == null) {
23 return mapElementToLicenseAgreementEntity(element);
29 public LicenseAgreementEntity convert(ElementInfo elementInfo) {
30 if (elementInfo == null) {
33 return mapElementInfoToLicenseAgreementEntity(elementInfo);
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;
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;
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()));
67 private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) {
70 licenseAgreement.setName(info.getName());
71 licenseAgreement.setDescription(info.getDescription());
74 .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm")));
75 licenseAgreement.setRequirementsAndConstrains(
76 info.getProperty("requirementsAndConstrains"));
80 private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) {
81 return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")),
82 (String) licenseTerm.get("other"));