aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/migration/1702_to_1707_zusammen/src/main/java/org/openecomp/core/migration/convertors/VspInformationConvertor.java
blob: 59fba5f066221f71530d4b9b314113a14a199945 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package org.openecomp.core.migration.convertors;

import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
import org.openecomp.core.migration.loaders.VspInformation;
import org.openecomp.core.migration.store.ElementHandler;
import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;

import java.util.List;

public class VspInformationConvertor {

  public static ItemVersionData getItemVersionData(
      VspInformation vspInformation) {
    Info info = new Info();
    info.setName("main version");
    ItemVersionData itemVersionData = new ItemVersionData();
    itemVersionData.setInfo(info);
    return itemVersionData;
  }

  public static Info getVspInfo(VspInformation vspInformation) {

    Info info = new Info();
    info.setName(vspInformation.getName());
    info.setDescription(vspInformation.getDescription());
    info.addProperty("type", "vsp");
    addVspDetailsToInfo(info, vspInformation);
    return info;
  }

  private static List<String> getVspNamespace(VendorLicenseModelEntity vlmEntity) {
    return ElementHandler.getElementPath("");
  }

  private static void addVspDetailsToInfo(Info info, VspInformation vspInformation) {
    info.addProperty("name", vspInformation.getName());
    info.addProperty("description", vspInformation.getDescription());
    info.addProperty("category", vspInformation.getCategory());
    info.addProperty("subCategory", vspInformation.getSubCategory());
    info.addProperty("vendorId", vspInformation.getVendorId());
    info.addProperty("vendorName", vspInformation.getVendorName());
    if (vspInformation.getVlmVersion() != null) {
      info.addProperty("vendorVersion", vspInformation.getVlmVersion().toString());
    }
    info.addProperty("featureGroups", vspInformation.getFeatureGroups());
    info.addProperty("licenseAgreement", vspInformation.getLicenseAgreement());
    String oldVersion = vspInformation.getIsOldVersion() == null? "1702":"1610";
    info.addProperty("oldVersion", oldVersion);
  }

  public static CollaborationElement[] convertVspToElement(VspInformation vspInformation) {

    CollaborationElement[] vspElements;
    if(vspInformation.getQuestionnaireData() == null){
      vspElements = new CollaborationElement[4];
    }else{
      vspElements = new CollaborationElement[5];
    }

    int index=0;

    List<String> vspNamespace = getVspNamespace(vspInformation);


    String vspEntityId = StructureElement.General.name();

    vspElements[index] = ElementHandler.getElementEntity(
        vspInformation.getId(), vspInformation.getVersion().toString(),
        vspEntityId,
        vspNamespace,
        getVspGeneralInfo(vspInformation),
        null,
        null,
        null);

    index++;
    String vspOrchestrationTemplateEntityId = StructureElement.OrchestrationTemplate.name();
    vspElements[index] = ElementHandler.getElementEntity(
        vspInformation.getId(), vspInformation.getVersion().toString(),
        vspOrchestrationTemplateEntityId,
        vspNamespace,
        ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateEntityId),
        null,
        null,
        null);

    if(vspInformation.getQuestionnaireData()!= null) {
      index++;
      String vspQuestionnaireEntityId = StructureElement.Questionnaire.name();
      vspElements[index] = ElementHandler.getElementEntity(
          vspInformation.getId(), vspInformation.getVersion().toString(),
          vspQuestionnaireEntityId,
          vspNamespace,
          ElementHandler.getStructuralElementInfo(vspQuestionnaireEntityId),
          null,
          null,
          vspInformation.getQuestionnaireData().getBytes() != null ? vspInformation
              .getQuestionnaireData().getBytes() : null);
    }
    vspNamespace.add(vspOrchestrationTemplateEntityId);
    index++;
    String vspOrchestrationTemplateValidationDataEntityId = StructureElement.OrchestrationTemplateValidationData.name();
    vspElements[index] = ElementHandler.getElementEntity(
        vspInformation.getId(), vspInformation.getVersion().toString(),
        vspOrchestrationTemplateValidationDataEntityId,
        vspNamespace,
        ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateValidationDataEntityId),
        null,
        null,
        vspInformation.getValidationData()!= null?vspInformation.getValidationData().getBytes()
            :null);
    index++;
    String vspOrchestrationTemplateContentEntityId = StructureElement.OrchestrationTemplateContent.name();
    vspElements[index] = ElementHandler.getElementEntity(
        vspInformation.getId(), vspInformation.getVersion().toString(),
        vspOrchestrationTemplateContentEntityId,
        vspNamespace,
        ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateContentEntityId),
        null,
        null,
        vspInformation.getContentData()!= null?vspInformation.getContentData().array()
            :null);

    return vspElements;
  }

  private static Info getVspGeneralInfo(VspInformation vspInformation) {


    Info info = new Info();
    info.setName(StructureElement.General.name());
    info.addProperty("name", vspInformation.getName());
    info.addProperty("description", vspInformation.getDescription());
    info.addProperty("category", vspInformation.getCategory());
    info.addProperty("subCategory", vspInformation.getSubCategory());
    info.addProperty("vendorId", vspInformation.getVendorId());
    info.addProperty("vendorName", vspInformation.getVendorName());
    if (vspInformation.getVlmVersion() != null) {
      info.addProperty("vendorVersion", vspInformation.getVlmVersion().toString());
    }
    info.addProperty("featureGroups", vspInformation.getFeatureGroups());
    info.addProperty("licenseAgreement", vspInformation.getLicenseAgreement());
    String oldVersion = vspInformation.getIsOldVersion() == null? "1702":"1610";
    info.addProperty("oldVersion", oldVersion);
    return info;
  }

  private static List<String> getVspNamespace(VspInformation vspEntity) {
    return ElementHandler.getElementPath("");
  }

  public static ElementEntityContext convertVspToElementContext(VspInformation vspEntity) {

    return new ElementEntityContext("GLOBAL_USER", new
        ElementContext(vspEntity.getId(), vspEntity.getVersion().toString()));
  }
}