aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main/java
diff options
context:
space:
mode:
authorVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-06-21 15:02:59 +0000
committerGerrit Code Review <gerrit@onap.org>2018-06-21 15:02:59 +0000
commit61c926695f5bd5977dc10a77010b0500a16bb6a1 (patch)
tree24c85ff1cb1c53c25b8206aaa9169bb3b20c5753 /workflow-designer-be/src/main/java
parentaf3f6811efabdc12f963339851e325dda777960b (diff)
parent285ff886bf5da36a64e05c419e960e8c6079334f (diff)
Merge "Fixed functionality of Workflow API"
Diffstat (limited to 'workflow-designer-be/src/main/java')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java12
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java29
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java6
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java3
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/WorkflowNotFoundException.java13
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java (renamed from workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/UniqueValueViolationException.java)7
-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.java4
8 files changed, 52 insertions, 30 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 90657709..95f11cd1 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
@@ -6,6 +6,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.onap.sdc.workflow.api.types.CollectionWrapper;
import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -18,19 +20,19 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Api("Workflows")
public interface WorkflowController {
- @GetMapping
+ @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("List workflows")
CollectionWrapper<Workflow> list(@RequestHeader(USER_ID_HEADER_PARAM) String user);
- @PostMapping
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Create workflow")
- Workflow create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user);
+ ResponseEntity<?> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user);
- @GetMapping("/{id}")
+ @GetMapping(path = "/{id}")
@ApiOperation("Get workflow")
Workflow get(@PathVariable("id") String id, @RequestHeader(USER_ID_HEADER_PARAM) String user);
- @PutMapping("/{id}")
+ @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);
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
new file mode 100644
index 00000000..c29d2ab1
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
@@ -0,0 +1,29 @@
+package org.onap.sdc.workflow.api.exceptionshandlers;
+
+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.WorkflowNotFoundException;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+@ControllerAdvice
+@RestController
+public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
+
+ @ExceptionHandler(UniqueValueViolationException.class)
+ public final ResponseEntity<String> handleUniqueValueViolationException(
+ UniqueValueViolationException exception) {
+ return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
+ }
+
+ @ExceptionHandler(WorkflowNotFoundException.class)
+ public final ResponseEntity<String> handleWorkflowNotFoundException(
+ WorkflowNotFoundException exception) {
+ return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java
index b7a122b8..f0b9f3ee 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java
@@ -8,6 +8,8 @@ import org.onap.sdc.workflow.persistence.types.Workflow;
import org.onap.sdc.workflow.services.WorkflowManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+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;
@@ -29,9 +31,9 @@ public class WorkflowControllerImpl implements WorkflowController {
}
@Override
- public Workflow create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ public ResponseEntity<?> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
workflowManager.create(workflow);
- return workflow;
+ return new ResponseEntity<>(workflow, HttpStatus.CREATED);
}
@Override
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java
index 9a8eee2f..a9acb816 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java
@@ -1,11 +1,10 @@
package org.onap.sdc.workflow.services;
-import com.google.common.annotations.VisibleForTesting;
import java.util.Optional;
import org.apache.commons.lang.ArrayUtils;
import org.onap.sdc.workflow.persistence.UniqueValueRepository;
import org.onap.sdc.workflow.persistence.types.UniqueValueEntity;
-import org.onap.sdc.workflow.services.errors.UniqueValueViolationException;
+import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
import org.openecomp.core.utilities.CommonMethods; // todo get rid of
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/WorkflowNotFoundException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/WorkflowNotFoundException.java
deleted file mode 100644
index 46a6d5ef..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/WorkflowNotFoundException.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.onap.sdc.workflow.services.errors;
-
-import static org.springframework.http.HttpStatus.NOT_FOUND;
-
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-@ResponseStatus(NOT_FOUND)
-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/errors/UniqueValueViolationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java
index 358863e9..82c97f94 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/UniqueValueViolationException.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java
@@ -1,11 +1,6 @@
-package org.onap.sdc.workflow.services.errors;
+package org.onap.sdc.workflow.services.exceptions;
-import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
-
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-@ResponseStatus(UNPROCESSABLE_ENTITY)
public class UniqueValueViolationException extends RuntimeException {
private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists.";
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
new file mode 100644
index 00000000..13c8021f
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java
@@ -0,0 +1,8 @@
+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 2afaaa0d..d5d9851e 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
@@ -6,7 +6,7 @@ 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.errors.WorkflowNotFoundException;
+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;
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
@Service("workflowManager")
public class WorkflowManagerImpl implements WorkflowManager {
- public static final String WORKFLOW_TYPE = "WORKFLOW";
+ private static final String WORKFLOW_TYPE = "WORKFLOW";
private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME";
private final ItemManager itemManager;
private final UniqueValueService uniqueValueService;