aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/MibConvertor.java
blob: 88b9dce95f21ab4dcf1ade8340a260b2b7bfdb38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.openecomp.core.migration.convertors;

import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
import org.openecomp.core.migration.MigrationMain;
import org.openecomp.core.migration.store.ElementHandler;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementType;
import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.MibEntity;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MibConvertor {
  private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);

  private static Set<String> compMibLoaded = new HashSet<>();


  public static CollaborationElement[] convertMibToElement(MibEntity mibEntity) {
    CollaborationElement[] elements;
    List<String> mibNamespace = getMibNamespace(mibEntity);

    int index = 0;
    String mibsEntityId = StructureElement.Mibs.name() + "_" + mibEntity.getComponentId();
    if (compMibLoaded.contains(mibsEntityId)) {
      elements = new CollaborationElement[1];
    } else {
      compMibLoaded.add(mibsEntityId);
      elements = new CollaborationElement[2];
      elements[index++] = ElementHandler.getElementEntity(
          mibEntity.getVspId(), mibEntity.getVersion().toString(), mibsEntityId, mibNamespace,
          ElementHandler.getStructuralElementInfo(StructureElement.Mibs.name()), null, null, null);
    }

    mibNamespace.add(mibsEntityId);
    elements[index] = ElementHandler.getElementEntity(
        mibEntity.getVspId(), mibEntity.getVersion().toString(), mibEntity.getId(), mibNamespace,
        getMibInfo(mibEntity), null, null, mibEntity.getArtifact().array());

    return elements;
  }

  private static Info getMibInfo(MibEntity mibEntity) {
    Info info = new Info();
    info.setName(mibEntity.getType().toString());
    info.getProperties().put("name", mibEntity.getArtifactName());
    return info;
  }

  private static List<String> getMibNamespace(MibEntity mibEntity) {
    return ElementHandler.getElementPath(StructureElement.Components.name(), mibEntity
        .getComponentId());
  }

  public static ElementEntityContext convertMibToElementContext(MibEntity mibEntity) {

    return new ElementEntityContext("GLOBAL_USER", new
        ElementContext(mibEntity.getVspId(), mibEntity.getVersion().toString()));
  }
}