88b9dce95f21ab4dcf1ade8340a260b2b7bfdb38
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / MibConvertor.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.ElementType;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.MibEntity;
14
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Set;
18
19 public class MibConvertor {
20   private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);
21
22   private static Set<String> compMibLoaded = new HashSet<>();
23
24
25   public static CollaborationElement[] convertMibToElement(MibEntity mibEntity) {
26     CollaborationElement[] elements;
27     List<String> mibNamespace = getMibNamespace(mibEntity);
28
29     int index = 0;
30     String mibsEntityId = StructureElement.Mibs.name() + "_" + mibEntity.getComponentId();
31     if (compMibLoaded.contains(mibsEntityId)) {
32       elements = new CollaborationElement[1];
33     } else {
34       compMibLoaded.add(mibsEntityId);
35       elements = new CollaborationElement[2];
36       elements[index++] = ElementHandler.getElementEntity(
37           mibEntity.getVspId(), mibEntity.getVersion().toString(), mibsEntityId, mibNamespace,
38           ElementHandler.getStructuralElementInfo(StructureElement.Mibs.name()), null, null, null);
39     }
40
41     mibNamespace.add(mibsEntityId);
42     elements[index] = ElementHandler.getElementEntity(
43         mibEntity.getVspId(), mibEntity.getVersion().toString(), mibEntity.getId(), mibNamespace,
44         getMibInfo(mibEntity), null, null, mibEntity.getArtifact().array());
45
46     return elements;
47   }
48
49   private static Info getMibInfo(MibEntity mibEntity) {
50     Info info = new Info();
51     info.setName(mibEntity.getType().toString());
52     info.getProperties().put("name", mibEntity.getArtifactName());
53     return info;
54   }
55
56   private static List<String> getMibNamespace(MibEntity mibEntity) {
57     return ElementHandler.getElementPath(StructureElement.Components.name(), mibEntity
58         .getComponentId());
59   }
60
61   public static ElementEntityContext convertMibToElementContext(MibEntity mibEntity) {
62
63     return new ElementEntityContext("GLOBAL_USER", new
64         ElementContext(mibEntity.getVspId(), mibEntity.getVersion().toString()));
65   }
66 }