fix incorrect dependency
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / LicenseAgreementConvertor.java
1 package org.openecomp.core.migration.convertors;
2
3 import com.amdocs.zusammen.datatypes.item.ElementContext;
4 import com.amdocs.zusammen.datatypes.item.Info;
5 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
6 import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
7 import org.openecomp.core.migration.store.ElementHandler;
8 import org.openecomp.sdc.logging.api.Logger;
9 import org.openecomp.sdc.logging.api.LoggerFactory;
10 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.RelationType;
11 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.StructureElement;
12 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil;
13 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
14
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Set;
18 import java.util.stream.Collectors;
19
20 /**
21  * Created by ayalaben on 4/25/2017
22  */
23 public class LicenseAgreementConvertor {
24
25     private static Logger logger = LoggerFactory.getLogger(LicenseAgreementConvertor.class);
26     private static Set<String> LicenseAgreementsLoaded = new HashSet<>();
27
28     public static ElementEntityContext convertLicenseAgreementToElementContext(LicenseAgreementEntity licenseAgreementEntity) {
29
30         return new ElementEntityContext("GLOBAL_USER", new
31                 ElementContext(licenseAgreementEntity.getVendorLicenseModelId(), licenseAgreementEntity.getVersion().toString()));
32     }
33
34
35     public static CollaborationElement[] convertLicenseAgreementToElement(LicenseAgreementEntity licenseAgreementEntity) {
36 //        printMessage(logger, "source LicenseAgreementEntity -> " + licenseAgreementEntity.toString());
37         CollaborationElement[] elements;
38         List<String> featureGroupNamespace = getLicenseAgreementNamespace(licenseAgreementEntity);
39
40         int index = 0;
41         String featureGroupsEntityId = StructureElement.LicenseAgreements.name();
42         String uniqueId = licenseAgreementEntity.getVendorLicenseModelId() + "_" + licenseAgreementEntity.getVersion().toString();
43
44         if (LicenseAgreementsLoaded.contains(uniqueId)) {
45             elements = new CollaborationElement[1];
46         } else {
47             LicenseAgreementsLoaded.add(uniqueId);
48             elements = new CollaborationElement[2];
49             elements[index] = ElementHandler.getElementEntity(
50                     licenseAgreementEntity.getVendorLicenseModelId(), licenseAgreementEntity.getVersion().toString(),
51                     featureGroupsEntityId, featureGroupNamespace,
52                     ElementHandler.getStructuralElementInfo(StructureElement.LicenseAgreements.name()),
53                     null, null, null);
54             index++;
55         }
56
57         featureGroupNamespace.add(featureGroupsEntityId);
58
59         elements[index] = ElementHandler.getElementEntity(
60                 licenseAgreementEntity.getVendorLicenseModelId(), licenseAgreementEntity.getVersion().toString(),
61                 licenseAgreementEntity.getId(), featureGroupNamespace, getLicenseAgreementInfo(licenseAgreementEntity),
62                 licenseAgreementEntity.getFeatureGroupIds().stream().map(rel ->
63                     VlmZusammenUtil.createRelation( RelationType.LicenseAgreementToFeatureGroup, rel))
64                         .collect(Collectors.toList()), null, null);
65
66         return elements;
67     }
68
69     private static Info getLicenseAgreementInfo(LicenseAgreementEntity licenseAgreement) {
70
71         Info info = new Info();
72         info.setName(licenseAgreement.getName());
73         info.setDescription(licenseAgreement.getDescription());
74         info.addProperty("licenseTerm", licenseAgreement.getLicenseTerm());
75         info.addProperty("requirementsAndConstrains", licenseAgreement.getRequirementsAndConstrains());
76
77         return info;
78     }
79
80     private static List<String> getLicenseAgreementNamespace(LicenseAgreementEntity licenseAgreement) {
81         return ElementHandler.getElementPath("");
82     }
83
84 }