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.LicenseKeyGroupEntity;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.stream.Collectors;
21 * Created by ayalaben on 4/24/2017
23 public class LKGConvertor {
25 private static Logger logger = LoggerFactory.getLogger(LKGConvertor.class);
26 private static Set<String> compLKGLoaded = new HashSet<>();
28 public static CollaborationElement[] convertLKGToElement(LicenseKeyGroupEntity licenseKeyGroupEntity) {
29 CollaborationElement[] elements;
30 List<String> lkgNamespace = getLKGNamespace(licenseKeyGroupEntity);
33 String lkgsEntityId = StructureElement.LicenseKeyGroups.name();
34 String uniqueId = licenseKeyGroupEntity.getVendorLicenseModelId() + "_" + licenseKeyGroupEntity.getVersion().toString();
36 if (compLKGLoaded.contains(uniqueId)) {
37 elements = new CollaborationElement[1];
39 compLKGLoaded.add(uniqueId);
40 elements = new CollaborationElement[2];
41 elements[index] = ElementHandler.getElementEntity(
42 licenseKeyGroupEntity.getVendorLicenseModelId(), licenseKeyGroupEntity.getVersion().toString(), lkgsEntityId, lkgNamespace,
43 ElementHandler.getStructuralElementInfo(StructureElement.LicenseKeyGroups.name()), null, null, null);
47 lkgNamespace.add(lkgsEntityId);
49 elements[index] = ElementHandler.getElementEntity(
50 licenseKeyGroupEntity.getVendorLicenseModelId(), licenseKeyGroupEntity.getVersion().toString(), licenseKeyGroupEntity.getId(), lkgNamespace,
51 getLKGInfo(licenseKeyGroupEntity), licenseKeyGroupEntity.getReferencingFeatureGroups().stream().map(rel ->
52 VlmZusammenUtil.createRelation( RelationType.LicenseKeyGroupToReferencingFeatureGroup, rel))
53 .collect(Collectors.toList()), null, null);
58 private static Info getLKGInfo(LicenseKeyGroupEntity licenseKeyGroupEntity) {
60 Info info = new Info();
61 info.setName(licenseKeyGroupEntity.getName());
62 info.setDescription(licenseKeyGroupEntity.getDescription());
63 info.addProperty("LicenseKeyType", licenseKeyGroupEntity.getType());
64 info.addProperty("operational_scope", licenseKeyGroupEntity.getOperationalScope());
69 private static List<String> getLKGNamespace(LicenseKeyGroupEntity LKGEntity) {
70 return ElementHandler.getElementPath("");
73 public static ElementEntityContext convertLKGToElementContext(LicenseKeyGroupEntity licenseKeyGroupEntity) {
75 return new ElementEntityContext("GLOBAL_USER", new
76 ElementContext(licenseKeyGroupEntity.getVendorLicenseModelId(), licenseKeyGroupEntity.getVersion().toString()));