[SDC-29] Amdocs OnBoard 1707 initial commit.
[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 = new CollaborationElement[4];
59     List<String> vspNamespace = getVspNamespace(vspInformation);
60
61
62     String vspEntityId = StructureElement.General.name();
63
64     vspElements[0] = ElementHandler.getElementEntity(
65         vspInformation.getId(), vspInformation.getVersion().toString(),
66         vspEntityId,
67         vspNamespace,
68         getVspGeneralInfo(vspInformation),
69         null,
70         null,
71         null);
72
73     String vspOrchestrationTemplateEntityId = StructureElement.OrchestrationTemplate.name();
74     vspElements[1] = ElementHandler.getElementEntity(
75         vspInformation.getId(), vspInformation.getVersion().toString(),
76         vspOrchestrationTemplateEntityId,
77         vspNamespace,
78         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateEntityId),
79         null,
80         null,
81         null);
82
83
84     vspNamespace.add(vspOrchestrationTemplateEntityId);
85
86     String vspOrchestrationTemplateValidationDataEntityId = StructureElement.OrchestrationTemplateValidationData.name();
87     vspElements[2] = ElementHandler.getElementEntity(
88         vspInformation.getId(), vspInformation.getVersion().toString(),
89         vspOrchestrationTemplateValidationDataEntityId,
90         vspNamespace,
91         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateValidationDataEntityId),
92         null,
93         null,
94         vspInformation.getValidationData()!= null?vspInformation.getValidationData().getBytes()
95             :null);
96
97     String vspOrchestrationTemplateContentEntityId = StructureElement.OrchestrationTemplateContent.name();
98     vspElements[3] = ElementHandler.getElementEntity(
99         vspInformation.getId(), vspInformation.getVersion().toString(),
100         vspOrchestrationTemplateContentEntityId,
101         vspNamespace,
102         ElementHandler.getStructuralElementInfo(vspOrchestrationTemplateContentEntityId),
103         null,
104         null,
105         vspInformation.getContentData()!= null?vspInformation.getContentData().array()
106             :null);
107
108     return vspElements;
109   }
110
111   private static Info getVspGeneralInfo(VspInformation vspInformation) {
112
113
114     Info info = new Info();
115     info.setName(StructureElement.General.name());
116     info.addProperty("name", vspInformation.getName());
117     info.addProperty("description", vspInformation.getDescription());
118     info.addProperty("category", vspInformation.getCategory());
119     info.addProperty("subCategory", vspInformation.getSubCategory());
120     info.addProperty("vendorId", vspInformation.getVendorId());
121     info.addProperty("vendorName", vspInformation.getVendorName());
122     if (vspInformation.getVlmVersion() != null) {
123       info.addProperty("vendorVersion", vspInformation.getVlmVersion().toString());
124     }
125     info.addProperty("featureGroups", vspInformation.getFeatureGroups());
126     info.addProperty("licenseAgreement", vspInformation.getLicenseAgreement());
127     String oldVersion = vspInformation.getIsOldVersion() == null? "1702":"1610";
128     info.addProperty("oldVersion", oldVersion);
129     return info;
130   }
131
132   private static List<String> getVspNamespace(VspInformation vspEntity) {
133     return ElementHandler.getElementPath("");
134   }
135
136   public static ElementEntityContext convertVspToElementContext(VspInformation vspEntity) {
137
138     return new ElementEntityContext("GLOBAL_USER", new
139         ElementContext(vspEntity.getId(), vspEntity.getVersion().toString()));
140   }
141 }