76e35b56c4353e8076d0124897a61a5b87466128
[sdc.git] /
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.plugin.statestore.cassandra.dao.types.ElementEntityContext;
6 import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
7 import org.openecomp.core.migration.store.ElementHandler;
8 import org.openecomp.core.model.types.ServiceArtifact;
9 import org.openecomp.core.utilities.file.FileUtils;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementPropertyName;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementType;
12 import org.openecomp.sdc.model.impl.zusammen.StructureElement;
13
14
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Set;
18
19 /**
20  * @author katyr
21  * @since April 23, 2017
22  */
23
24 public class VspServiceArtifactConvertor 
25 {
26     private static Set<String> serviceArtifactsLoaded = new HashSet<>();
27  
28
29
30   public static CollaborationElement[] convertServiceArtifactToElement(ServiceArtifact serviceArtifact) {
31
32     CollaborationElement[] serviceArtifactElements;
33     List<String> serviceArtifactNamespace = getServiceArtifactNamespace();
34
35     int index = 0;
36     String serviceArtifactsEntityId = StructureElement.Artifacts.name();
37     String uniqueId = serviceArtifact.getVspId()+"_"+serviceArtifact.getVersion().toString();
38     if (serviceArtifactsLoaded.contains(uniqueId)) {
39       serviceArtifactElements = new CollaborationElement[1];
40     } else {
41       serviceArtifactsLoaded.add(uniqueId);
42       serviceArtifactElements = new CollaborationElement[2];
43       serviceArtifactElements[index] = ElementHandler.getElementEntity(
44           serviceArtifact.getVspId(), serviceArtifact.getVersion().toString(), serviceArtifactsEntityId,
45           serviceArtifactNamespace,
46           ElementHandler.getStructuralElementInfo(StructureElement.Artifacts.name()),
47           null,
48           null,
49           null);
50       index++;
51     }
52
53     serviceArtifactNamespace.add(serviceArtifactsEntityId);
54     String elementId = serviceArtifact.getVspId()+"_"+serviceArtifact.getVersion().toString()
55         +"_"+serviceArtifact.getName();
56     serviceArtifactElements[index] = ElementHandler.getElementEntity(
57         serviceArtifact.getVspId(), serviceArtifact.getVersion().toString(), elementId,
58         serviceArtifactNamespace,
59         getServiceArtifactInfo(serviceArtifact),
60         null,
61         null,
62         FileUtils.toByteArray(serviceArtifact.getContent()));
63
64     return serviceArtifactElements;
65   }
66
67   private static Info getServiceArtifactInfo(ServiceArtifact serviceArtifactEntity) {
68     Info info = new Info();
69     info.setName(serviceArtifactEntity.getName());
70     info.addProperty("type", org.openecomp.sdc.model.impl.zusammen.ElementType.Artifact.name());
71
72     return info;
73   }
74
75   private static List<String> getServiceArtifactNamespace() {
76     return ElementHandler.getElementPath(StructureElement.ServiceModel.name());
77   }
78
79   public static ElementEntityContext convertServiceArtifactToElementContext(ServiceArtifact
80                                                                                 serviceArtifactEntity) {
81
82     return new ElementEntityContext("GLOBAL_USER", new
83         ElementContext(serviceArtifactEntity.getVspId(), serviceArtifactEntity.getVersion().toString()));
84   }
85
86 }