Use versioning, zusammen and session libs from sdc-common-be
[sdc/sdc-workflow-designer.git] / workflow-designer-be / src / main / java / org / onap / sdc / workflow / persistence / impl / ArtifactRepositoryImpl.java
index 06e2a63..4ad5461 100644 (file)
 
 package org.onap.sdc.workflow.persistence.impl;
 
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement;
 
 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
-import com.amdocs.zusammen.datatypes.SessionContext;
 import com.amdocs.zusammen.datatypes.item.Action;
 import com.amdocs.zusammen.datatypes.item.ElementContext;
 import java.io.ByteArrayInputStream;
@@ -31,10 +29,11 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Optional;
 import org.apache.commons.io.IOUtils;
+import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
 import org.onap.sdc.workflow.persistence.ArtifactRepository;
-import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
 import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 
@@ -45,10 +44,12 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
     private static final String EMPTY_DATA = "{}";
 
     private final ZusammenAdaptor zusammenAdaptor;
+    private final ZusammenSessionContextCreator contextCreator;
 
     @Autowired
-    public ArtifactRepositoryImpl(ZusammenAdaptor zusammenAdaptor) {
+    public ArtifactRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) {
         this.zusammenAdaptor = zusammenAdaptor;
+        this.contextCreator = contextCreator;
     }
 
     @Override
@@ -58,20 +59,20 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
         artifactElement.setData(artifactEntity.getArtifactData());
         artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName());
 
-        SessionContext context = createSessionContext();
+
         ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         zusammenAdaptor
-                .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
+                .saveElement(contextCreator.create(), elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
     }
 
     @Override
     public Optional<ArtifactEntity> get(String workflowId, String versionId) {
-        SessionContext context = createSessionContext();
+
         ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         Optional<Element> elementOptional =
-                zusammenAdaptor.getElementByName(context, elementContext, null, WorkflowElementType.ARTIFACT.name());
+                zusammenAdaptor.getElementByName(contextCreator.create(), elementContext, null, WorkflowElementType.ARTIFACT.name());
 
         if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) {
             return Optional.empty();
@@ -87,10 +88,10 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
 
     @Override
     public boolean isExist(String workflowId, String versionId) {
-        SessionContext context = createSessionContext();
+
         ElementContext elementContext = new ElementContext(workflowId, versionId);
 
-        Optional<ElementInfo> optionalElementInfo = zusammenAdaptor.getElementInfoByName(context, elementContext, null,
+        Optional<ElementInfo> optionalElementInfo = zusammenAdaptor.getElementInfoByName(contextCreator.create(), elementContext, null,
                 WorkflowElementType.ARTIFACT.name());
         return optionalElementInfo.isPresent() && optionalElementInfo.get().getInfo().getProperties()
                                                                      .containsKey(FILE_NAME_PROPERTY);
@@ -98,27 +99,27 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
 
     @Override
     public void createStructure(String workflowId, String versionId) {
-        SessionContext context = createSessionContext();
+
         ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.CREATE);
         artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
 
         zusammenAdaptor
-                .saveElement(context, elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
+                .saveElement(contextCreator.create(), elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
 
     }
 
     @Override
     public void delete(String workflowId, String versionId) {
-        SessionContext context = createSessionContext();
+
         ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE);
         artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
         artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY);
 
-        zusammenAdaptor.saveElement(context, elementContext, artifactElement, "Delete WorkflowVersion Artifact Data");
+        zusammenAdaptor.saveElement(contextCreator.create(), elementContext, artifactElement, "Delete WorkflowVersion Artifact Data");
 
     }