[sdc] update code of sdc
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / VspInformationConvertor.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.datatypes.item.ItemVersionData;
6 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
7 import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
8 import org.openecomp.core.migration.loaders.VspInformation;
9 import org.openecomp.core.migration.store.ElementHandler;
10 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
12
13 import java.util.List;
14
15 public class VspInformationConvertor {
16
17   public static ItemVersionData getItemVersionData(
18       VspInformation vspInformation) {
19     Info info = new Info();
20     info.setName("main version");
21     ItemVersionData itemVersionData = new ItemVersionData();
22     itemVersionData.setInfo(info);
23     return itemVersionData;
24   }
25
26   public static Info getVspInfo(VspInformation vspInformation) {
27
28     Info info = new Info();
29     info.setName(vspInformation.getName());
30     info.setDescription(vspInformation.getDescription());
31     info.addProperty("type", "vsp");
32     addVspDetailsToInfo(info, vspInformation);
33     return info;
34   }
35
36   private static List<String> getVspNamespace(VendorLicenseModelEntity vlmEntity) {
37     return ElementHandler.getElementPath("");
38   }
39
40   private static void addVspDetailsToInfo(Info info, VspInformation vspInformation) {
41     info.addProperty("name", vspInformation.getName());
42     info.addProperty("description", vspInformation.getDescription());
43     info.addProperty("category", vspInformation.getCategory());
44     info.addProperty("subCategory", vspInformation.getSubCategory());
45     info.addProperty("vendorId", vspInformation.getVendorId());
46     info.addProperty("vendorName", vspInformation.getVendorName());
47     if (vspInformation.getVlmVersion() != null) {
48       info.addProperty("vendorVersion", vspInformation.getVlmVersion().toString());
49     }
50     info.addProperty("featureGroups", vspInformation.getFeatureGroups());
51     info.addProperty("licenseAgreement", vspInformation.getLicenseAgreement());
52     String oldVersion = vspInformation.getIsOldVersion() == null? "1702":"1610";
53     info.addProperty("oldVersion", oldVersion);
54   }
55
56   public static CollaborationElement[] convertVspToElement(VspInformation vspInformation) {
57
58     CollaborationElement[] vspElements;
59     if(vspInformation.getQuestionnaireData() == null){
60       vspElements = new CollaborationElement[4];
61     }else{
62       vspElements = new CollaborationElement[5];
63     }
64
65     int index=0;
66
67     List<String> vspNamespace = getVspNamespace(vspInformation);
68
69
70     String vspEntityId = StructureElement.General.name();
71
72     vspElements[index] = ElementHandler.getElementEntity(
73         vspInformation.getId(), vspInformation.getVersion().toString(),
74         vspEntityId,
75         vspNamespace,
76         getVspGeneralInfo(vspInformation),
77         null,
78         null,
79         null);
80
81     index++;
82     String vspOrchestrationTemplateEntityId = StructureElement.OrchestrationTemplate.name();
83     vspElements[index] = ElementHandler.getElementEntity(
84         vspInformation.getId(), vspInformation.getVersion().toString(),
85         vspOrchestrationTemplateEntityId,
86         vspNamespace,
87         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateEntityId),
88         null,
89         null,
90         null);
91
92     if(vspInformation.getQuestionnaireData()!= null) {
93       index++;
94       String vspQuestionnaireEntityId = StructureElement.Questionnaire.name();
95       vspElements[index] = ElementHandler.getElementEntity(
96           vspInformation.getId(), vspInformation.getVersion().toString(),
97           vspQuestionnaireEntityId,
98           vspNamespace,
99           ElementHandler.getStructuralElementInfo(vspQuestionnaireEntityId),
100           null,
101           null,
102           vspInformation.getQuestionnaireData().getBytes() != null ? vspInformation
103               .getQuestionnaireData().getBytes() : null);
104     }
105     vspNamespace.add(vspOrchestrationTemplateEntityId);
106     index++;
107     String vspOrchestrationTemplateValidationDataEntityId = StructureElement.OrchestrationTemplateValidationData.name();
108     vspElements[index] = ElementHandler.getElementEntity(
109         vspInformation.getId(), vspInformation.getVersion().toString(),
110         vspOrchestrationTemplateValidationDataEntityId,
111         vspNamespace,
112         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateValidationDataEntityId),
113         null,
114         null,
115         vspInformation.getValidationData()!= null?vspInformation.getValidationData().getBytes()
116             :null);
117     index++;
118     String vspOrchestrationTemplateContentEntityId = StructureElement.OrchestrationTemplateContent.name();
119     vspElements[index] = ElementHandler.getElementEntity(
120         vspInformation.getId(), vspInformation.getVersion().toString(),
121         vspOrchestrationTemplateContentEntityId,
122         vspNamespace,
123         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateContentEntityId),
124         null,
125         null,
126         vspInformation.getContentData()!= null?vspInformation.getContentData().array()
127             :null);
128
129     return vspElements;
130   }
131
132   private static Info getVspGeneralInfo(VspInformation vspInformation) {
133
134
135     Info info = new Info();
136     info.setName(StructureElement.General.name());
137     info.addProperty("name", vspInformation.getName());
138     info.addProperty("description", vspInformation.getDescription());
139     info.addProperty("category", vspInformation.getCategory());
140     info.addProperty("subCategory", vspInformation.getSubCategory());
141     info.addProperty("vendorId", vspInformation.getVendorId());
142     info.addProperty("vendorName", vspInformation.getVendorName());
143     if (vspInformation.getVlmVersion() != null) {
144       info.addProperty("vendorVersion", vspInformation.getVlmVersion().toString());
145     }
146     info.addProperty("featureGroups", vspInformation.getFeatureGroups());
147     info.addProperty("licenseAgreement", vspInformation.getLicenseAgreement());
148     String oldVersion = vspInformation.getIsOldVersion() == null? "1702":"1610";
149     info.addProperty("oldVersion", oldVersion);
150     return info;
151   }
152
153   private static List<String> getVspNamespace(VspInformation vspEntity) {
154     return ElementHandler.getElementPath("");
155   }
156
157   public static ElementEntityContext convertVspToElementContext(VspInformation vspEntity) {
158
159     return new ElementEntityContext("GLOBAL_USER", new
160         ElementContext(vspEntity.getId(), vspEntity.getVersion().toString()));
161   }
162 }