[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / EntitlementPoolConvertor.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.vendorlicense.dao.impl.zusammen.RelationType;
9 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.StructureElement;
10 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil;
11 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
12
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16 import java.util.stream.Collectors;
17
18 /**
19  * Created by ayalaben on 4/24/2017
20  */
21 public class EntitlementPoolConvertor {
22
23   private static Set<String> EntitlementPoolsLoaded = new HashSet<>();
24
25   public static ElementEntityContext convertEntitlementPoolToElementContext(
26       EntitlementPoolEntity entitlementPoolEntity) {
27
28     return new ElementEntityContext("GLOBAL_USER", new
29         ElementContext(entitlementPoolEntity.getVendorLicenseModelId(),
30         entitlementPoolEntity.getVersion().toString()));
31   }
32
33   public static CollaborationElement[] convertEntitlementPoolToElement(
34       EntitlementPoolEntity entitlementPoolEntity) {
35 //    printMessage(logger, "source EntitlementPoolEntity -> " + entitlementPoolEntity.toString());
36     CollaborationElement[] elements;
37     List<String> entitlementPoolNamespace = getEntitlementPoolNamespace(entitlementPoolEntity);
38
39     int index = 0;
40     String entitlememtPoolsEntityId = StructureElement.EntitlementPools.name();
41     String uniqueId = entitlementPoolEntity.getVendorLicenseModelId() + "_" +
42         entitlementPoolEntity.getVersion().toString();
43
44     if (EntitlementPoolsLoaded.contains(uniqueId)) {
45       elements = new CollaborationElement[1];
46     } else {
47       EntitlementPoolsLoaded.add(uniqueId);
48       elements = new CollaborationElement[2];
49       elements[index] = ElementHandler.getElementEntity(
50           entitlementPoolEntity.getVendorLicenseModelId(),
51           entitlementPoolEntity.getVersion().toString(),
52           entitlememtPoolsEntityId, entitlementPoolNamespace,
53               ElementHandler.getStructuralElementInfo(StructureElement.EntitlementPools.name()),
54           null, null, null);
55       index++;
56     }
57
58     entitlementPoolNamespace.add(entitlememtPoolsEntityId);
59
60     elements[index] = ElementHandler.getElementEntity(
61         entitlementPoolEntity.getVendorLicenseModelId(),
62         entitlementPoolEntity.getVersion().toString(),
63         entitlementPoolEntity.getId(), entitlementPoolNamespace,
64         getEntitelementPoolInfo(entitlementPoolEntity),
65         entitlementPoolEntity.getReferencingFeatureGroups().stream().map(rel ->
66             VlmZusammenUtil
67                 .createRelation( RelationType.EntitlmentPoolToReferencingFeatureGroup, rel))
68             .collect(Collectors.toList()), null, null);
69
70     return elements;
71   }
72
73   private static Info getEntitelementPoolInfo(EntitlementPoolEntity entitlementPool) {
74
75     Info info = new Info();
76     info.setName(entitlementPool.getName());
77     info.setDescription(entitlementPool.getDescription());
78     info.addProperty("thresholdValue", entitlementPool.getThresholdValue());
79     info.addProperty("threshold_unit", entitlementPool.getThresholdUnit());
80     info.addProperty("entitlement_metric", entitlementPool.getEntitlementMetric());
81     info.addProperty("increments", entitlementPool.getIncrements());
82     info.addProperty("aggregation_func", entitlementPool.getAggregationFunction());
83     info.addProperty("operational_scope", entitlementPool.getOperationalScope());
84     info.addProperty("EntitlementTime", entitlementPool.getTime());
85     info.addProperty("manufacturerReferenceNumber",
86         entitlementPool.getManufacturerReferenceNumber());
87     return info;
88   }
89
90   private static List<String> getEntitlementPoolNamespace(
91       EntitlementPoolEntity entitlementPoolEntity) {
92     return ElementHandler.getElementPath("");
93   }
94
95 }