Publish version exception handling 45/57945/6
authorayalaben <ayala.benzvi@amdocs.com>
Sun, 29 Jul 2018 11:46:38 +0000 (14:46 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Tue, 31 Jul 2018 11:42:06 +0000 (14:42 +0300)
Change-Id: If4e172f40c7410c5fa90d5686733f4d995b98d17
Issue-ID: SDC-1518
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java

index ed9371e..e10279f 100644 (file)
@@ -23,12 +23,14 @@ import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
 
 public interface ArtifactRepository {
 
-    void update(String id, String versionId,ArtifactEntity artifactEntity);
+    void update(String workflowId, String versionId,ArtifactEntity artifactEntity);
 
-    Optional<ArtifactEntity> get(String id, String versionId);
+    Optional<ArtifactEntity> get(String workflowId, String versionId);
 
-    void createStructure(String id, String versionId);
+    boolean isExist(String workflowId, String versionId);
 
-    void delete(String id, String versionId);
+    void createStructure(String workflowId, String versionId);
+
+    void delete(String workflowId, String versionId);
 
 }
index 3c528db..b49433c 100644 (file)
@@ -20,6 +20,7 @@ import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElemen
 import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
 
 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;
@@ -46,23 +47,23 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
 
 
     @Override
-    public void update(String id, String versionId, ArtifactEntity artifactEntity) {
+    public void update(String workflowId, String versionId, ArtifactEntity artifactEntity) {
 
         ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE);
         artifactElement.setData(artifactEntity.getArtifactData());
         artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName());
 
         SessionContext context = createSessionContext();
-        ElementContext elementContext = new ElementContext(id, versionId);
+        ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         zusammenAdaptor
                 .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
     }
 
     @Override
-    public Optional<ArtifactEntity> get(String id, String versionId) {
+    public Optional<ArtifactEntity> get(String workflowId, String versionId) {
         SessionContext context = createSessionContext();
-        ElementContext elementContext = new ElementContext(id, versionId);
+        ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         Optional<Element> elementOptional =
                 zusammenAdaptor.getElementByName(context, elementContext, null, WorkflowElementType.ARTIFACT.name());
@@ -80,9 +81,20 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
     }
 
     @Override
-    public void createStructure(String id, String versionId) {
+    public boolean isExist(String workflowId, String versionId) {
         SessionContext context = createSessionContext();
-        ElementContext elementContext = new ElementContext(id, versionId);
+        ElementContext elementContext = new ElementContext(workflowId, versionId);
+
+        Optional<ElementInfo> optionalElementInfo = zusammenAdaptor.getElementInfoByName(context, elementContext, null,
+                WorkflowElementType.ARTIFACT.name());
+        return optionalElementInfo.isPresent() && optionalElementInfo.get().getInfo().getProperties()
+                                                                     .containsKey(FILE_NAME_PROPERTY);
+    }
+
+    @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()));
@@ -93,9 +105,9 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
     }
 
     @Override
-    public void delete(String id, String versionId) {
+    public void delete(String workflowId, String versionId) {
         SessionContext context = createSessionContext();
-        ElementContext elementContext = new ElementContext(id, versionId);
+        ElementContext elementContext = new ElementContext(workflowId, versionId);
 
         ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE);
         artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
index 1c828d4..17f95ae 100644 (file)
@@ -30,6 +30,7 @@ public class WorkflowVersion {
     private String description;
     private String baseId;
     private WorkflowVersionState state;
+    private boolean hasArtifact;
     private Collection<ParameterEntity> inputs = Collections.emptyList();
     private Collection<ParameterEntity> outputs = Collections.emptyList();
     private Date creationTime;
index 484c598..0f7c993 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.sdc.workflow.services.impl;
 
 import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.CERTIFIED;
 
+import com.amdocs.zusammen.datatypes.response.ErrorCode;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
@@ -43,6 +44,7 @@ import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
 import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
 import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
 import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
 import org.openecomp.sdc.logging.api.Logger;
 import org.openecomp.sdc.logging.api.LoggerFactory;
 import org.openecomp.sdc.versioning.VersioningManager;
@@ -95,6 +97,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
     public WorkflowVersion get(String workflowId, String versionId) {
         WorkflowVersion workflowVersion = versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId));
         loadAndAddParameters(workflowId, workflowVersion);
+        workflowVersion.setHasArtifact(artifactRepository.isExist(workflowId,versionId));
         return workflowVersion;
     }
 
@@ -140,9 +143,14 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
         updateParameters(workflowId, version.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs());
 
         versioningManager.updateVersion(workflowId, version);
-        versioningManager.publish(workflowId, version, "Update version");
+
+        Version updatedVersion = versioningManager.get(workflowId, version);
+        if(updatedVersion.getState().isDirty()) {
+            versioningManager.publish(workflowId, version, "Update version");
+        }
     }
 
+
     @Override
     public WorkflowVersionState getState(String workflowId, String versionId) {
         return versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus());
@@ -274,4 +282,5 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
     private static Optional<Version> findVersion(List<Version> versions, String versionId) {
         return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst();
     }
+
 }
\ No newline at end of file
index 7dee524..6e5a905 100644 (file)
@@ -41,6 +41,7 @@ import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
 import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
 import org.openecomp.sdc.versioning.VersioningManager;
 import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionState;
 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 import org.openecomp.sdc.versioning.types.VersionCreationMethod;
 import org.springframework.mock.web.MockMultipartFile;
@@ -101,6 +102,9 @@ public class WorkflowVersionManagerImplTest {
         retrievedVersion.setName("1.0");
         retrievedVersion.setDescription("WorkflowVersion description");
         retrievedVersion.setStatus(VersionStatus.Draft);
+        VersionState versionState = new VersionState();
+        versionState.setDirty(true);
+        retrievedVersion.setState(versionState);
         doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus());