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.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;
16 import java.util.HashSet;
17 import java.util.List;
22 * @since April 23, 2017
25 public class ComponentConvertor {
27 private static Set<String> componentsLoaded = new HashSet<>();
28 private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);
30 public static CollaborationElement[] convertComponentToElement(ComponentEntity componentEntity) {
32 CollaborationElement[] componentElements;
33 List<String> componentNamespace = getComponentNamespace();
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];
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,
50 ElementHandler.getStructuralElementInfo(StructureElement.Components.name()),
57 componentNamespace.add(componentsEntityId);
58 componentElements[index] = ElementHandler.getElementEntity(
59 componentEntity.getVspId(), componentEntity.getVersion().toString(),
60 componentEntity.getId(),
62 getComponentInfo(componentEntity),
65 (componentEntity.getCompositionData() != null) ? componentEntity.getCompositionData().getBytes()
69 componentNamespace.add(componentEntity.getId());
70 componentElements[index] = ElementHandler.getElementEntity(
71 componentEntity.getVspId(), componentEntity.getVersion().toString(),StructureElement.Questionnaire.name() + "_" + componentEntity.getId(),
73 ElementHandler.getStructuralElementInfo(StructureElement.Questionnaire.name()),
76 (componentEntity.getQuestionnaireData() != null) ? componentEntity.getQuestionnaireData().getBytes()
79 return componentElements;
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());
91 private static List<String> getComponentNamespace() {
92 return ElementHandler.getElementPath();
95 public static ElementEntityContext convertComponentToElementContext(
96 ComponentEntity componentEntity) {
98 return new ElementEntityContext("GLOBAL_USER", new
99 ElementContext(componentEntity.getVspId(), componentEntity.getVersion().toString()));