aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/NicConvertor.java
blob: b17e68c0e54841cd1f9bb32d6ac7376e96ace252 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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.ElementPropertyName;
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.NicEntity;

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

public class NicConvertor {


  private static Set<String> compNicLoaded = new HashSet<>();
  private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);



  public static CollaborationElement[] convertNicToElement(NicEntity nicEntity) {

    CollaborationElement[] nicElements;
    List<String> nicNamespace = getNicNamespace(nicEntity);

    int index = 0;
    String nicsEntityId = StructureElement.Nics.name() + "_" + nicEntity.getComponentId();
    if (compNicLoaded.contains(nicsEntityId)) {
//      printMessage(logger, "Nics structural element exists for nic " +
//          nicEntity.getId());
      nicElements = new CollaborationElement[2];
    } else {
//      printMessage(logger, "Creating Nics structural element for nic " +
//          nicEntity.getId());
      compNicLoaded.add(nicsEntityId);
      nicElements = new CollaborationElement[3];
      nicElements[index] = ElementHandler.getElementEntity(
          nicEntity.getVspId(), nicEntity.getVersion().toString(), nicsEntityId,
          nicNamespace,
          ElementHandler.getStructuralElementInfo(StructureElement.Nics.name()),
          null,
          null,
          null);
      index++;
    }

    nicNamespace.add(nicsEntityId);
    nicElements[index] = ElementHandler.getElementEntity(
        nicEntity.getVspId(), nicEntity.getVersion().toString(), nicEntity.getId(),
        nicNamespace,
        getNicInfo(nicEntity),
        null,
        null,
        nicEntity.getCompositionData().getBytes());
    index++;

    nicNamespace.add(nicEntity.getId());
    nicElements[index] = ElementHandler.getElementEntity(
        nicEntity.getVspId(), nicEntity.getVersion().toString(),StructureElement.Questionnaire.name() + "_" + nicEntity.getId(),
        nicNamespace,
        ElementHandler.getStructuralElementInfo(StructureElement.Questionnaire.name()),
        null,
        null,
        (nicEntity.getQuestionnaireData() != null) ? nicEntity.getQuestionnaireData().getBytes()
            : null);
    return nicElements;
  }

  private static Info getNicInfo(NicEntity nicEntity) {
    Info info = new Info();
    info.addProperty(ElementPropertyName.type.name(), ElementType.Nic);
    info.addProperty(ElementPropertyName.compositionData.name(), nicEntity.getCompositionData());
    return info;
  }

  private static List<String> getNicNamespace(NicEntity nicEntity) {
    return ElementHandler.getElementPath(StructureElement.Components.name(), nicEntity
        .getComponentId());
  }

  public static ElementEntityContext convertNicToElementContext(NicEntity nicEntity) {

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


}