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