aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main/java
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-07-04 13:11:54 +0300
committerayalaben <ayala.benzvi@amdocs.com>2018-07-10 15:05:42 +0300
commit8660fef75d965fa92f0a6d28187469009abcf3ad (patch)
treef99afe0797dcbadce95db311689180b1511e4811 /workflow-designer-be/src/main/java
parentd1fc5bdebe14b199dfe0ea1d013201adc05b64e6 (diff)
Version Artifact API
Change-Id: Iae2dace7d9b31a633e60c7eebcbc50ee3f6ac7d6 Issue-ID: SDC-1462 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/main/java')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java22
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java58
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java11
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java18
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java104
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java16
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/VersionStatus.java7
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java19
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java9
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java8
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java8
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java9
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionNotFoundException.java8
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java8
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java7
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java144
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java15
19 files changed, 454 insertions, 69 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
index eb57353b..cb1fb1f3 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
@@ -3,39 +3,49 @@ package org.onap.sdc.workflow.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import java.util.Collection;
import org.onap.sdc.workflow.api.types.CollectionWrapper;
-import org.openecomp.sdc.versioning.dao.types.Version;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
-@RequestMapping("/workflows/{id}/versions")
+@RequestMapping("/workflows/{workflowId}/versions")
@Api("Workflow versions")
public interface WorkflowVersionController {
@GetMapping
@ApiOperation("List workflow versions")
- CollectionWrapper<Version> list(String id, String user);
+ CollectionWrapper<WorkflowVersion> list(String workflowId,String user);
@PostMapping
@ApiOperation("Create workflow version")
- ResponseEntity<?> create(String id, Version version, String user);
+ ResponseEntity<WorkflowVersion> create(String workflowId, VersionRequestDto versionRequest, String user);
@GetMapping("/{versionId}")
@ApiOperation("Get workflow version")
- Version get(String id,String versionId, String user);
+ WorkflowVersion get(String workflowId,String versionId, String user);
@PutMapping("/{versionId}")
@ApiOperation("Update workflow version")
- void update(String id, String versionId,Version version, String user);
+ void update(WorkflowVersion version,String workflowId, String versionId, String user);
+ @PutMapping("/{versionId}/artifact")
+ @ApiOperation("Create/update artifact of a version")
+ void createArtifact(MultipartFile fileToUpload, String workflowId, String versionId, String user);
+
+ @GetMapping("/{versionId}/artifact")
+ @ApiOperation("Download workflow version artifact")
+ ResponseEntity<Resource> getArtifact(String workflowId, String versionId, String user);
+
+ @DeleteMapping("/{versionId}/artifact")
+ @ApiOperation("Delete workflow version artifact")
+ void deleteArtifact(String workflowId, String versionId, String user);
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
index 978be192..0b5278ac 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
@@ -1,11 +1,14 @@
package org.onap.sdc.workflow.api.exceptionshandlers;
+import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
-import org.onap.sdc.workflow.services.exceptions.VersionNotFoundException;
-import org.onap.sdc.workflow.services.exceptions.WorkflowNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.CreateVersionException;
+import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -22,9 +25,22 @@ public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExce
return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
}
- @ExceptionHandler({WorkflowNotFoundException.class, VersionNotFoundException.class})
+ @ExceptionHandler(EntityNotFoundException.class)
public final ResponseEntity<String> handleWorkflowNotFoundException(
Exception exception) {
return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
}
+
+ @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class})
+ public final ResponseEntity<String> handleInvalidArtifactException(
+ Exception exception) {
+ return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
+ }
+
+
+ @ExceptionHandler(CreateVersionException.class)
+ public final ResponseEntity<String> handleVersioningErrorException(
+ CreateVersionException exception) {
+ return new ResponseEntity<>(exception.getMessage(), FORBIDDEN);
+ }
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java
index 49c31f5b..0570ac85 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java
@@ -2,22 +2,24 @@ package org.onap.sdc.workflow.api.impl;
import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
import org.onap.sdc.workflow.api.WorkflowVersionController;
import org.onap.sdc.workflow.api.types.CollectionWrapper;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -32,32 +34,56 @@ public class WorkflowVersionControllerImpl implements WorkflowVersionController
}
@Override
- public CollectionWrapper<Version> list(@PathVariable("id") String id,@RequestHeader(USER_ID_HEADER_PARAM) String user) {
- return new CollectionWrapper<>(workflowVersionManager.list(id));
+ public CollectionWrapper<WorkflowVersion> list(@PathVariable("workflowId") String workflowId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ return new CollectionWrapper<>(workflowVersionManager.list(workflowId));
}
@Override
- public ResponseEntity<?> create(@PathVariable("id") String id,@RequestBody Version version,
+ public ResponseEntity<WorkflowVersion> create(@PathVariable("workflowId") String workflowId,@RequestBody VersionRequestDto versionRequest,
@RequestHeader(USER_ID_HEADER_PARAM) String user) {
- Version createdVersion = workflowVersionManager.create(id, version);
-
+ WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, versionRequest);
return new ResponseEntity<>(createdVersion, HttpStatus.CREATED);
}
@Override
- public Version get(@PathVariable("id") String id,@PathVariable("versionId") String versionId,
+ public WorkflowVersion get(@PathVariable("workflowId") String workflowId,@PathVariable("versionId") String versionId,
@RequestHeader(USER_ID_HEADER_PARAM) String user) {
- Version version = new Version(versionId);
- return workflowVersionManager.get(id,version);
+ return workflowVersionManager.get(workflowId,versionId);
}
@Override
- public void update(@PathVariable("id") String id, @PathVariable("versionId") String versionId,
- @RequestBody Version version, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ public void update(@RequestBody WorkflowVersion version,@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
version.setId(versionId);
- workflowVersionManager.update(id,version);
+ workflowVersionManager.update(workflowId,version);
+ }
+
+ @Override
+ public void createArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId,@RequestHeader(USER_ID_HEADER_PARAM) String user) {
+
+ workflowVersionManager.uploadArtifact(workflowId,new WorkflowVersion(versionId),fileToUpload);
+
+ }
+
+ @Override
+ public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ WorkflowVersion requestedVersion = new WorkflowVersion(versionId);
+ ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, requestedVersion);
+
+ return ResponseEntity.ok()
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName())
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
+ .body(new InputStreamResource(artifact.getArtifactData()));
}
+ @Override
+ public void deleteArtifact(@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+
+ }
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java
new file mode 100644
index 00000000..92ac3a73
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java
@@ -0,0 +1,11 @@
+package org.onap.sdc.workflow.api.types;
+
+import lombok.Data;
+
+@Data
+public class VersionRequestDto {
+
+ private String description;
+ private String baseVersionId;
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java
new file mode 100644
index 00000000..a473f166
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java
@@ -0,0 +1,18 @@
+package org.onap.sdc.workflow.persistence;
+
+
+import java.util.Optional;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+
+
+public interface ArtifactRepository {
+
+ void update(String id, String versionId,ArtifactEntity artifactEntity);
+
+ Optional<ArtifactEntity> get(String id, String versionId);
+
+ void createStructure(String id, String versionId);
+
+ void delete(String id, String versionId);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
new file mode 100644
index 00000000..9a449f0d
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
@@ -0,0 +1,104 @@
+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 com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+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;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.commons.io.IOUtils;
+import org.onap.sdc.workflow.persistence.ArtifactRepository;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.openecomp.sdc.datatypes.model.ElementType;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class ArtifactRepositoryImpl implements ArtifactRepository {
+
+ private static final String FILE_NAME_PROPERTY = "fileName";
+ private static final String EMPTY_DATA = "{}";
+ private ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory.getInstance().createInterface();
+
+
+ @Override
+ public void update(String id, String versionId, ArtifactEntity artifactEntity) {
+
+ ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.UPDATE);
+ artifactElement.setData(artifactEntity.getArtifactData());
+ artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName());
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
+ }
+
+ @Override
+ public Optional<ArtifactEntity> get(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ Optional<Element> elementOptional =
+ zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.Artifact.name());
+
+ if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) {
+ return Optional.empty();
+ }
+
+ Element artifactElement = elementOptional.get();
+
+ ArtifactEntity artifact = new ArtifactEntity(artifactElement.getInfo().getProperty(FILE_NAME_PROPERTY),
+ artifactElement.getData());
+
+ return Optional.of(artifact);
+ }
+
+ @Override
+ public void createStructure(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.CREATE);
+ artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
+
+ }
+
+ @Override
+ public void delete(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.UPDATE);
+ artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
+ artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY);
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
+
+ }
+
+ private boolean hasEmptyData(InputStream elementData) {
+
+ byte[] byteElementData;
+ try {
+ byteElementData = IOUtils.toByteArray(elementData);
+ } catch (IOException ex) {
+ return false;
+ }
+ return Arrays.equals(EMPTY_DATA.getBytes(), byteElementData);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java
new file mode 100644
index 00000000..8f24ecc9
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java
@@ -0,0 +1,16 @@
+package org.onap.sdc.workflow.persistence.types;
+
+import java.io.InputStream;
+import lombok.Data;
+
+@Data
+public class ArtifactEntity {
+
+ private String fileName;
+ private InputStream artifactData;
+
+ public ArtifactEntity(String fileName, InputStream artifactData) {
+ this.fileName = fileName;
+ this.artifactData = artifactData;
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/VersionStatus.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/VersionStatus.java
new file mode 100644
index 00000000..a3e8a38a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/VersionStatus.java
@@ -0,0 +1,7 @@
+package org.onap.sdc.workflow.persistence.types;
+
+public enum VersionStatus {
+
+ Draft,
+ Certified;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java
new file mode 100644
index 00000000..3c667bed
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java
@@ -0,0 +1,26 @@
+package org.onap.sdc.workflow.persistence.types;
+
+import java.util.Date;
+import lombok.Data;
+
+
+@Data
+public class WorkflowVersion {
+
+ private String id;
+ private String name;
+ private String description;
+ private String baseId;
+ private Date creationTime;
+ private Date modificationTime;
+ private VersionStatus status;
+
+
+ public WorkflowVersion(String id) {
+ this.id = id;
+ this.status = VersionStatus.Draft;
+ }
+
+ public WorkflowVersion() {
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java
index b288b287..fc60b27a 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java
@@ -1,16 +1,25 @@
package org.onap.sdc.workflow.services;
import java.util.Collection;
-import org.openecomp.sdc.versioning.dao.types.Version;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+
public interface WorkflowVersionManager {
- Collection<Version> list(String id);
+ Collection<WorkflowVersion> list(String workflowId);
+
+ WorkflowVersion get(String workflowId,String versionId);
+
+ WorkflowVersion create(String workflowId, VersionRequestDto versionRequest);
+
+ void update(String id,WorkflowVersion version);
- Version get(String id, Version version);
+ void uploadArtifact(String workflowId,WorkflowVersion version, MultipartFile artifact);
- Version create(String id, Version version);
+ ArtifactEntity getArtifact(String workflowId,WorkflowVersion version);
- void update(String id,Version version);
+ void deleteArtifact(String workflowId,WorkflowVersion version);
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java
new file mode 100644
index 00000000..cadabb4c
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java
@@ -0,0 +1,9 @@
+package org.onap.sdc.workflow.services.exceptions;
+
+public class CreateVersionException extends RuntimeException {
+
+ public CreateVersionException(String workflowId, String version) {
+ super(String.format("Error creating new version for workflow with id %s. There is already a draft version %s",
+ workflowId, version));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java
new file mode 100644
index 00000000..1ed3df5a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java
@@ -0,0 +1,8 @@
+package org.onap.sdc.workflow.services.exceptions;
+
+public class EntityNotFoundException extends RuntimeException {
+
+ public EntityNotFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java
new file mode 100644
index 00000000..89c5fd5f
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java
@@ -0,0 +1,8 @@
+package org.onap.sdc.workflow.services.exceptions;
+
+public class InvalidArtifactException extends RuntimeException {
+
+ public InvalidArtifactException(String message) {
+ super("Invalid artifact file can not be processed. Error: " + message);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java
new file mode 100644
index 00000000..dc7d62fd
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java
@@ -0,0 +1,9 @@
+package org.onap.sdc.workflow.services.exceptions;
+
+public class VersionModificationException extends RuntimeException {
+
+ public VersionModificationException(String workflowId, String version) {
+ super(String.format("Error while trying to modify version for workflow id %s. "
+ + "Version %s is Certified and can not be edited", workflowId, version));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionNotFoundException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionNotFoundException.java
deleted file mode 100644
index 3bf86ad1..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionNotFoundException.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.onap.sdc.workflow.services.exceptions;
-
-public class VersionNotFoundException extends RuntimeException {
-
- public VersionNotFoundException(String workflowId, String versioId) {
- super(String.format("version with id '%s' does not exist for workflow with id %s",versioId,workflowId));
- }
-}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java
deleted file mode 100644
index 13c8021f..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.onap.sdc.workflow.services.exceptions;
-
-public class WorkflowNotFoundException extends RuntimeException {
-
- public WorkflowNotFoundException(String workflowId) {
- super(String.format("Workflow with id '%s' does not exist", workflowId));
- }
-}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
index 8bb5f709..cf1a7e18 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
@@ -3,11 +3,11 @@ package org.onap.sdc.workflow.services.impl;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.mappers.WorkflowMapper;
import org.onap.sdc.workflow.persistence.types.Workflow;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.WorkflowManager;
-import org.onap.sdc.workflow.services.exceptions.WorkflowNotFoundException;
import org.openecomp.sdc.versioning.ItemManager;
import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.ItemStatus;
@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
public class WorkflowManagerImpl implements WorkflowManager {
private static final String WORKFLOW_TYPE = "WORKFLOW";
+ private static final String WORKFLOW_NOT_FOUND_ERROR_MSG = "Workflow with id '%s' does not exist";
protected static final Predicate<Item> ITEM_PREDICATE = item -> WORKFLOW_TYPE.equals(item.getType());
private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME";
private final ItemManager itemManager;
@@ -43,7 +44,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
public Workflow get(Workflow workflow) {
Item retrievedItem = itemManager.get(workflow.getId());
if (retrievedItem == null) {
- throw new WorkflowNotFoundException(workflow.getId());
+ throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
}
return this.workflowMapper.itemToWorkflow(retrievedItem);
}
@@ -63,7 +64,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
public void update(Workflow workflow) {
Item retrievedItem = itemManager.get(workflow.getId());
if (retrievedItem == null) {
- throw new WorkflowNotFoundException(workflow.getId());
+ throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
}
uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, retrievedItem.getName(), workflow.getName());
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
index b0a14fd6..99b64c7f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
@@ -1,57 +1,165 @@
package org.onap.sdc.workflow.services.impl;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
+
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.ArtifactRepository;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.VersionStatus;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
-import org.onap.sdc.workflow.services.exceptions.VersionNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.CreateVersionException;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
+import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
+import org.onap.sdc.workflow.services.mappers.VersionMapper;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
@Service("workflowVersionManager")
-public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
+public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
private final VersioningManager versioningManager;
+ private final ArtifactRepository artifactRepository;
+ private VersionMapper versionMapper;
+
@Autowired
- public WorkflowVersionManagerImpl(VersioningManager versioningManager) {
+ public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository,
+ VersionMapper versionMapper) {
this.versioningManager = versioningManager;
+ this.artifactRepository = artifactRepository;
+ this.versionMapper = versionMapper;
}
@Override
- public Collection<Version> list(String id) {
- return versioningManager.list(id);
+ public Collection<WorkflowVersion> list(String workflowId) {
+
+ return versioningManager.list(workflowId).stream()
+ .map(version -> versionMapper.versionToWorkflowVersion(version))
+ .collect(Collectors.toList());
}
@Override
- public Version get(String id,Version version) {
+ public WorkflowVersion get(String workflowId, String versionId) {
+ Version version = new Version(versionId);
try {
- return versioningManager.get(id, version);
- } catch (Exception e){
- throw new VersionNotFoundException(id,version.getId());
+ return this.versionMapper.versionToWorkflowVersion(versioningManager.get(workflowId, version));
+ } catch (Exception e) {
+ throw new EntityNotFoundException(
+ String.format("version with id '%s' does not exist for workflow with id %s", version.getId(),
+ workflowId));
+ }
+ }
+
+ @Override
+ public WorkflowVersion create(String workflowId, VersionRequestDto versionRequest) {
+
+ List<Version> versions = versioningManager.list(workflowId);
+
+ if (versionRequest.getBaseVersionId() != null) {
+ Version baseVersion = findVersion(versions, versionRequest.getBaseVersionId()).orElseThrow(
+ () -> new EntityNotFoundException(
+ String.format("version with id '%s' does not exist for workflow with id %s",
+ versionRequest.getBaseVersionId(), workflowId)));
+
+ if(!Certified.equals(baseVersion.getStatus())){
+ throw new CreateVersionException(workflowId, versionRequest.getBaseVersionId());
+ }
+ }
+
+ Version version = new Version();
+ version.setDescription(versionRequest.getDescription());
+ version.setBaseId(versionRequest.getBaseVersionId());
+ Version createdVersion = versioningManager.create(workflowId, version, VersionCreationMethod.major);
+
+ if (versions.isEmpty()){
+ artifactRepository.createStructure(workflowId, createdVersion.getId());
+ }
+
+ versioningManager.publish(workflowId, createdVersion, "Initial version");
+
+ return versionMapper.versionToWorkflowVersion(createdVersion);
+ }
+
+ private Optional<Version> findVersion(List<Version> versions, String baseVersionId) {
+ return versions.stream().filter(version -> baseVersionId.equals(version.getId())).findFirst();
+ }
+
+ @Override
+ public void update(String id, WorkflowVersion version) {
+
+ Version versionToUpdate = mapVersionInfo(id, version);
+ versioningManager.updateVersion(id, versionToUpdate);
+ versioningManager.publish(id, versionToUpdate, "Update version");
+ }
+
+
+ @Override
+ public void uploadArtifact(String workflowId, WorkflowVersion version, MultipartFile artifact) {
+ WorkflowVersion retrievedVersion = get(workflowId, version.getId());
+ if (VersionStatus.Certified.equals(retrievedVersion.getStatus())) {
+ throw new VersionModificationException(workflowId, version.getId());
+ }
+
+ try (InputStream artifactData = artifact.getInputStream()) {
+ ArtifactEntity artifactEntity =
+ new ArtifactEntity(StringUtils.cleanPath(artifact.getOriginalFilename()), artifactData);
+ artifactRepository.update(workflowId, version.getId(), artifactEntity);
+ versioningManager.publish(workflowId, versionMapper.workflowVersionToVersion(version), "Update Artifact");
+
+ } catch (IOException e) {
+ throw new InvalidArtifactException(e.getMessage());
}
}
@Override
- public Version create(String id, Version version) {
- if (Objects.nonNull(getLatestVersion(id)))
- version.setBaseId(getLatestVersion(id).getId());
- return versioningManager.create(id,version, VersionCreationMethod.major);
+ public ArtifactEntity getArtifact(String workflowId, WorkflowVersion version) {
+ WorkflowVersion retrievedVersion = get(workflowId, version.getId());
+ Optional<ArtifactEntity> artifactOptional = artifactRepository.get(workflowId, retrievedVersion.getId());
+ if (!artifactOptional.isPresent()) {
+ throw new EntityNotFoundException(
+ String.format("Artifact for workflow id %S version id %S was not found", workflowId,
+ version.getId()));
+ }
+ return artifactOptional.get();
}
@Override
- public void update(String id,Version version) {
+ public void deleteArtifact(String workflowId, WorkflowVersion version) {
+ WorkflowVersion retrievedVersion = get(workflowId, version.getId());
+ if (VersionStatus.Certified.equals(retrievedVersion.getStatus())) {
+ throw new VersionModificationException(workflowId, version.getId());
+ }
+
+ artifactRepository.delete(workflowId, version.getId());
+ }
- versioningManager.updateVersion(id,version);
+ private boolean isFirstVersionCreation(String id, Version createdVersion) {
+ return Objects.isNull(createdVersion.getBaseId()) && versioningManager.list(id).size() == 1;
}
- protected Version getLatestVersion(String itemId) {
- List<Version> list = versioningManager.list(itemId);
- return list.stream().max(Version::compareTo).orElse(null);
+ protected Version mapVersionInfo(String id, WorkflowVersion workflowVersion) {
+ WorkflowVersion retrievedVersion = get(id, workflowVersion.getId());
+ Version version = new Version(workflowVersion.getId());
+ version.setBaseId(retrievedVersion.getBaseId());
+ version.setName(retrievedVersion.getName());
+ return version;
}
+
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java
new file mode 100644
index 00000000..4f894f7f
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java
@@ -0,0 +1,15 @@
+package org.onap.sdc.workflow.services.mappers;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+@Mapper(componentModel = "spring")
+public interface VersionMapper {
+
+ WorkflowVersion versionToWorkflowVersion(Version version);
+
+ @InheritInverseConfiguration
+ Version workflowVersionToVersion(WorkflowVersion workflowVersion);
+}