1 package org.openecomp.core.migration.convertors;
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;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.stream.Collectors;
21 * Created by ayalaben on 4/25/2017
23 public class LicenseAgreementConvertor {
25 private static Logger logger = LoggerFactory.getLogger(LicenseAgreementConvertor.class);
26 private static Set<String> LicenseAgreementsLoaded = new HashSet<>();
28 public static ElementEntityContext convertLicenseAgreementToElementContext(LicenseAgreementEntity licenseAgreementEntity) {
30 return new ElementEntityContext("GLOBAL_USER", new
31 ElementContext(licenseAgreementEntity.getVendorLicenseModelId(), licenseAgreementEntity.getVersion().toString()));
35 public static CollaborationElement[] convertLicenseAgreementToElement(LicenseAgreementEntity licenseAgreementEntity) {
36 // printMessage(logger, "source LicenseAgreementEntity -> " + licenseAgreementEntity.toString());
37 CollaborationElement[] elements;
38 List<String> featureGroupNamespace = getLicenseAgreementNamespace(licenseAgreementEntity);
41 String featureGroupsEntityId = StructureElement.LicenseAgreements.name();
42 String uniqueId = licenseAgreementEntity.getVendorLicenseModelId() + "_" + licenseAgreementEntity.getVersion().toString();
44 if (LicenseAgreementsLoaded.contains(uniqueId)) {
45 elements = new CollaborationElement[1];
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()),
57 featureGroupNamespace.add(featureGroupsEntityId);
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);
69 private static Info getLicenseAgreementInfo(LicenseAgreementEntity licenseAgreement) {
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());
80 private static List<String> getLicenseAgreementNamespace(LicenseAgreementEntity licenseAgreement) {
81 return ElementHandler.getElementPath("");