[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / NicConvertor.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.MigrationMain;
8 import org.openecomp.core.migration.store.ElementHandler;
9 import org.openecomp.sdc.logging.api.Logger;
10 import org.openecomp.sdc.logging.api.LoggerFactory;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementPropertyName;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementType;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
15
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
20 public class NicConvertor {
21
22
23   private static Set<String> compNicLoaded = new HashSet<>();
24   private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);
25
26
27
28   public static CollaborationElement[] convertNicToElement(NicEntity nicEntity) {
29
30     CollaborationElement[] nicElements;
31     List<String> nicNamespace = getNicNamespace(nicEntity);
32
33     int index = 0;
34     String nicsEntityId = StructureElement.Nics.name() + "_" + nicEntity.getComponentId();
35     if (compNicLoaded.contains(nicsEntityId)) {
36 //      printMessage(logger, "Nics structural element exists for nic " +
37 //          nicEntity.getId());
38       nicElements = new CollaborationElement[2];
39     } else {
40 //      printMessage(logger, "Creating Nics structural element for nic " +
41 //          nicEntity.getId());
42       compNicLoaded.add(nicsEntityId);
43       nicElements = new CollaborationElement[3];
44       nicElements[index] = ElementHandler.getElementEntity(
45           nicEntity.getVspId(), nicEntity.getVersion().toString(), nicsEntityId,
46           nicNamespace,
47           ElementHandler.getStructuralElementInfo(StructureElement.Nics.name()),
48           null,
49           null,
50           null);
51       index++;
52     }
53
54     nicNamespace.add(nicsEntityId);
55     nicElements[index] = ElementHandler.getElementEntity(
56         nicEntity.getVspId(), nicEntity.getVersion().toString(), nicEntity.getId(),
57         nicNamespace,
58         getNicInfo(nicEntity),
59         null,
60         null,
61         nicEntity.getCompositionData().getBytes());
62     index++;
63
64     nicNamespace.add(nicEntity.getId());
65     nicElements[index] = ElementHandler.getElementEntity(
66         nicEntity.getVspId(), nicEntity.getVersion().toString(),StructureElement.Questionnaire.name() + "_" + nicEntity.getId(),
67         nicNamespace,
68         ElementHandler.getStructuralElementInfo(StructureElement.Questionnaire.name()),
69         null,
70         null,
71         (nicEntity.getQuestionnaireData() != null) ? nicEntity.getQuestionnaireData().getBytes()
72             : null);
73     return nicElements;
74   }
75
76   private static Info getNicInfo(NicEntity nicEntity) {
77     Info info = new Info();
78     info.addProperty(ElementPropertyName.type.name(), ElementType.Nic);
79     info.addProperty(ElementPropertyName.compositionData.name(), nicEntity.getCompositionData());
80     return info;
81   }
82
83   private static List<String> getNicNamespace(NicEntity nicEntity) {
84     return ElementHandler.getElementPath(StructureElement.Components.name(), nicEntity
85         .getComponentId());
86   }
87
88   public static ElementEntityContext convertNicToElementContext(NicEntity nicEntity) {
89
90     return new ElementEntityContext("GLOBAL_USER", new
91         ElementContext(nicEntity.getVspId(), nicEntity.getVersion().toString()));
92   }
93
94
95 }