1 package org.openecomp.core.migration.convertors;
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;
15 import java.util.HashSet;
16 import java.util.List;
21 * @since April 23, 2017
24 public class VspServiceArtifactConvertor
26 private static Set<String> serviceArtifactsLoaded = new HashSet<>();
30 public static CollaborationElement[] convertServiceArtifactToElement(ServiceArtifact serviceArtifact) {
32 CollaborationElement[] serviceArtifactElements;
33 List<String> serviceArtifactNamespace = getServiceArtifactNamespace();
36 String serviceArtifactsEntityId = StructureElement.Artifacts.name();
37 String uniqueId = serviceArtifact.getVspId()+"_"+serviceArtifact.getVersion().toString();
38 if (serviceArtifactsLoaded.contains(uniqueId)) {
39 serviceArtifactElements = new CollaborationElement[1];
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()),
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),
62 FileUtils.toByteArray(serviceArtifact.getContent()));
64 return serviceArtifactElements;
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());
75 private static List<String> getServiceArtifactNamespace() {
76 return ElementHandler.getElementPath(StructureElement.ServiceModel.name());
79 public static ElementEntityContext convertServiceArtifactToElementContext(ServiceArtifact
80 serviceArtifactEntity) {
82 return new ElementEntityContext("GLOBAL_USER", new
83 ElementContext(serviceArtifactEntity.getVspId(), serviceArtifactEntity.getVersion().toString()));