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.model.impl.zusammen.StructureElement;
12 import java.util.HashSet;
13 import java.util.List;
18 * @since April 23, 2017
21 public class VspServiceArtifactConvertor
23 private static Set<String> serviceArtifactsLoaded = new HashSet<>();
27 public static CollaborationElement[] convertServiceArtifactToElement(ServiceArtifact serviceArtifact) {
29 CollaborationElement[] serviceArtifactElements;
30 List<String> serviceArtifactNamespace = getServiceArtifactNamespace();
33 String serviceArtifactsEntityId = StructureElement.Artifacts.name();
34 String uniqueId = serviceArtifact.getVspId()+"_"+serviceArtifact.getVersion().toString();
35 if (serviceArtifactsLoaded.contains(uniqueId)) {
36 serviceArtifactElements = new CollaborationElement[1];
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()),
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),
59 FileUtils.toByteArray(serviceArtifact.getContent()));
61 return serviceArtifactElements;
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());
72 private static List<String> getServiceArtifactNamespace() {
73 return ElementHandler.getElementPath(StructureElement.ServiceModel.name());
76 public static ElementEntityContext convertServiceArtifactToElementContext(ServiceArtifact
77 serviceArtifactEntity) {
79 return new ElementEntityContext("GLOBAL_USER", new
80 ElementContext(serviceArtifactEntity.getVspId(), serviceArtifactEntity.getVersion().toString()));