diff options
author | 2018-06-26 09:29:06 +0300 | |
---|---|---|
committer | 2018-06-26 09:29:06 +0300 | |
commit | e9d97234f17d8ecdbfc0481d6a2ba2698d52ddd0 (patch) | |
tree | 0990c708c3b50c84115efeecab6df5346d430749 /workflow-designer-be/src/main/java/org | |
parent | 3fb47c47b301bf8f401cabf63b13f17a39182d85 (diff) |
workflow version API
Change-Id: Iadbf5325091084b4feca386740d6655845904d88
Issue-ID: SDC-1445
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/main/java/org')
7 files changed, 194 insertions, 7 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java index 95f11cd1..41f47674 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java @@ -22,18 +22,17 @@ public interface WorkflowController { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("List workflows") - CollectionWrapper<Workflow> list(@RequestHeader(USER_ID_HEADER_PARAM) String user); + CollectionWrapper<Workflow> list(String user); @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Create workflow") - ResponseEntity<?> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user); + ResponseEntity<?> create(Workflow workflow, String user); @GetMapping(path = "/{id}") @ApiOperation("Get workflow") - Workflow get(@PathVariable("id") String id, @RequestHeader(USER_ID_HEADER_PARAM) String user); + Workflow get(String id, String user); @PutMapping(path = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Update workflow") - Workflow update(@RequestBody Workflow workflow, @PathVariable("id") String id, - @RequestHeader(USER_ID_HEADER_PARAM) String user); + Workflow update(Workflow workflow, String id, String user); } 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 new file mode 100644 index 00000000..eb57353b --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java @@ -0,0 +1,41 @@ +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.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") +@Api("Workflow versions") +public interface WorkflowVersionController { + + + @GetMapping + @ApiOperation("List workflow versions") + CollectionWrapper<Version> list(String id, String user); + + @PostMapping + @ApiOperation("Create workflow version") + ResponseEntity<?> create(String id, Version version, String user); + + @GetMapping("/{versionId}") + @ApiOperation("Get workflow version") + Version get(String id,String versionId, String user); + + @PutMapping("/{versionId}") + @ApiOperation("Update workflow version") + void update(String id, String versionId,Version version, 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 c29d2ab1..978be192 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 @@ -4,6 +4,7 @@ import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; 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.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -21,9 +22,9 @@ public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExce return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY); } - @ExceptionHandler(WorkflowNotFoundException.class) + @ExceptionHandler({WorkflowNotFoundException.class, VersionNotFoundException.class}) public final ResponseEntity<String> handleWorkflowNotFoundException( - WorkflowNotFoundException exception) { + Exception exception) { return new ResponseEntity<>(exception.getMessage(), NOT_FOUND); } } 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 new file mode 100644 index 00000000..49c31f5b --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java @@ -0,0 +1,63 @@ +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.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.Resource; +import org.springframework.http.HttpStatus; +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.RestController; +import org.springframework.web.multipart.MultipartFile; + +@RestController("workflowsVersionController") +public class WorkflowVersionControllerImpl implements WorkflowVersionController { + + private final WorkflowVersionManager workflowVersionManager; + + @Autowired + public WorkflowVersionControllerImpl(@Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager) { + this.workflowVersionManager = workflowVersionManager; + } + + @Override + public CollectionWrapper<Version> list(@PathVariable("id") String id,@RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new CollectionWrapper<>(workflowVersionManager.list(id)); + } + + @Override + public ResponseEntity<?> create(@PathVariable("id") String id,@RequestBody Version version, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + + Version createdVersion = workflowVersionManager.create(id, version); + + return new ResponseEntity<>(createdVersion, HttpStatus.CREATED); + } + + @Override + public Version get(@PathVariable("id") String id,@PathVariable("versionId") String versionId, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + Version version = new Version(versionId); + return workflowVersionManager.get(id,version); + } + + @Override + public void update(@PathVariable("id") String id, @PathVariable("versionId") String versionId, + @RequestBody Version version, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + + version.setId(versionId); + workflowVersionManager.update(id,version); + } + +} 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 new file mode 100644 index 00000000..b288b287 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java @@ -0,0 +1,16 @@ +package org.onap.sdc.workflow.services; + +import java.util.Collection; +import org.openecomp.sdc.versioning.dao.types.Version; + +public interface WorkflowVersionManager { + + Collection<Version> list(String id); + + Version get(String id, Version version); + + Version create(String id, Version version); + + void update(String id,Version 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 new file mode 100644 index 00000000..d98a15d7 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionNotFoundException.java @@ -0,0 +1,7 @@ +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/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java new file mode 100644 index 00000000..cda17914 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java @@ -0,0 +1,60 @@ +package org.onap.sdc.workflow.services.impl; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import org.onap.sdc.workflow.services.WorkflowVersionManager; +import org.onap.sdc.workflow.services.exceptions.VersionNotFoundException; +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; + +@Service("workflowVersionManager") +public class WorkflowVersionManagerImpl implements WorkflowVersionManager { + + private final VersioningManager versioningManager; + + @Autowired + public WorkflowVersionManagerImpl(VersioningManager versioningManager) { + this.versioningManager = versioningManager; + } + + @Override + public Collection<Version> list(String id) { + return versioningManager.list(id); + } + + @Override + public Version get(String id,Version version) { + + try { + return versioningManager.get(id, version); + } catch (Exception e){ + throw new VersionNotFoundException(id,version.getId()); + } + } + + @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); + } + + @Override + public void update(String id,Version version) { + + versioningManager.updateVersion(id,version); + } + + private Version getLatestVersion(String itemId) { + List<Version> list = versioningManager.list(itemId); + Optional<Version> max = list.stream().max(Version::compareTo); + + return max.orElse(null); + } + +} |