fix incorrect dependency
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / LKGConvertor.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.LicenseKeyGroupEntity;
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/24/2017
22  */
23 public class LKGConvertor {
24
25     private static Logger logger = LoggerFactory.getLogger(LKGConvertor.class);
26     private static Set<String> compLKGLoaded = new HashSet<>();
27
28     public static CollaborationElement[] convertLKGToElement(LicenseKeyGroupEntity licenseKeyGroupEntity) {
29         CollaborationElement[] elements;
30         List<String> lkgNamespace = getLKGNamespace(licenseKeyGroupEntity);
31
32         int index = 0;
33         String lkgsEntityId = StructureElement.LicenseKeyGroups.name();
34         String uniqueId = licenseKeyGroupEntity.getVendorLicenseModelId() + "_" + licenseKeyGroupEntity.getVersion().toString();
35
36         if (compLKGLoaded.contains(uniqueId)) {
37             elements = new CollaborationElement[1];
38         } else {
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);
44             index++;
45         }
46
47         lkgNamespace.add(lkgsEntityId);
48
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);
54
55         return elements;
56     }
57
58     private static Info getLKGInfo(LicenseKeyGroupEntity licenseKeyGroupEntity) {
59
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());
65
66         return info;
67     }
68
69     private static List<String> getLKGNamespace(LicenseKeyGroupEntity LKGEntity) {
70         return ElementHandler.getElementPath("");
71     }
72
73     public static ElementEntityContext convertLKGToElementContext(LicenseKeyGroupEntity licenseKeyGroupEntity) {
74
75         return new ElementEntityContext("GLOBAL_USER", new
76                 ElementContext(licenseKeyGroupEntity.getVendorLicenseModelId(), licenseKeyGroupEntity.getVersion().toString()));
77     }
78
79 }