fix incorrect dependency
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / ComponentConvertor.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.ComponentEntity;
15
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
20 /**
21  * @author katyr
22  * @since April 23, 2017
23  */
24
25 public class ComponentConvertor {
26
27   private static Set<String> componentsLoaded = new HashSet<>();
28   private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);
29
30   public static CollaborationElement[] convertComponentToElement(ComponentEntity componentEntity) {
31
32     CollaborationElement[] componentElements;
33     List<String> componentNamespace = getComponentNamespace();
34
35     int index = 0;
36     String componentsEntityId = StructureElement.Components.name();
37     String uniqueId = componentEntity.getVspId()+"_"+componentEntity.getVersion().toString();
38     if (componentsLoaded.contains(uniqueId)) {
39 //      printMessage(logger, "Components structural elements exist for component " +
40 //          componentEntity.getId());
41       componentElements = new CollaborationElement[2];
42     } else {
43       componentsLoaded.add(uniqueId);
44 //      printMessage(logger, "Creating Components structural elements for component " +
45 //          componentEntity.getId());
46       componentElements = new CollaborationElement[3];
47       componentElements[index] = ElementHandler.getElementEntity(
48           componentEntity.getVspId(), componentEntity.getVersion().toString(), componentsEntityId,
49           componentNamespace,
50           ElementHandler.getStructuralElementInfo(StructureElement.Components.name()),
51           null,
52           null,
53           null);
54       index++;
55     }
56
57     componentNamespace.add(componentsEntityId);
58     componentElements[index] = ElementHandler.getElementEntity(
59         componentEntity.getVspId(), componentEntity.getVersion().toString(),
60         componentEntity.getId(),
61         componentNamespace,
62         getComponentInfo(componentEntity),
63         null,
64         null,
65         (componentEntity.getCompositionData() != null) ? componentEntity.getCompositionData().getBytes()
66             : null);
67     index++;
68
69     componentNamespace.add(componentEntity.getId());
70     componentElements[index] = ElementHandler.getElementEntity(
71         componentEntity.getVspId(), componentEntity.getVersion().toString(),StructureElement.Questionnaire.name() + "_" + componentEntity.getId(),
72         componentNamespace,
73         ElementHandler.getStructuralElementInfo(StructureElement.Questionnaire.name()),
74         null,
75         null,
76         (componentEntity.getQuestionnaireData() != null) ? componentEntity.getQuestionnaireData().getBytes()
77             : null);
78
79     return componentElements;
80   }
81
82   private static Info getComponentInfo(ComponentEntity componentEntity) {
83     Info info = new Info();
84     info.addProperty(ElementPropertyName.type.name(), ElementType.Component);
85     info.addProperty(ElementPropertyName.compositionData.name(),
86         componentEntity.getCompositionData());
87
88     return info;
89   }
90
91   private static List<String> getComponentNamespace() {
92     return ElementHandler.getElementPath();
93   }
94
95   public static ElementEntityContext convertComponentToElementContext(
96       ComponentEntity componentEntity) {
97
98     return new ElementEntityContext("GLOBAL_USER", new
99         ElementContext(componentEntity.getVspId(), componentEntity.getVersion().toString()));
100   }
101
102 }