From 285ff886bf5da36a64e05c419e960e8c6079334f Mon Sep 17 00:00:00 2001 From: avigaffa Date: Thu, 21 Jun 2018 17:32:00 +0300 Subject: Fixed functionality of Workflow API renaming Exceptions package to lower case Change-Id: Ib1395c15012d393be913d6588454b3b4b7c4b075 Issue-ID: SDC-1396 Signed-off-by: avigaffa --- .../onap/sdc/workflow/api/WorkflowController.java | 12 +++++---- .../CustomizedResponseEntityExceptionHandler.java | 29 ++++++++++++++++++++++ .../workflow/api/impl/WorkflowControllerImpl.java | 6 +++-- .../sdc/workflow/services/UniqueValueService.java | 3 +-- .../errors/UniqueValueViolationException.java | 16 ------------ .../services/errors/WorkflowNotFoundException.java | 13 ---------- .../exceptions/UniqueValueViolationException.java | 11 ++++++++ .../exceptions/WorkflowNotFoundException.java | 8 ++++++ .../services/impl/WorkflowManagerImpl.java | 4 +-- 9 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java delete mode 100644 workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/UniqueValueViolationException.java delete mode 100644 workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/WorkflowNotFoundException.java create mode 100644 workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java create mode 100644 workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowNotFoundException.java (limited to 'workflow-designer-be/src/main/java') 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 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 handleUniqueValueViolationException( + UniqueValueViolationException exception) { + return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY); + } + + @ExceptionHandler(WorkflowNotFoundException.class) + public final ResponseEntity 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/UniqueValueViolationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/UniqueValueViolationException.java deleted file mode 100644 index 358863e9..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/errors/UniqueValueViolationException.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.onap.sdc.workflow.services.errors; - - -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."; - - public UniqueValueViolationException(String uniqueType, String value) { - super(String.format(UNIQUE_VALUE_VIOLATION_MSG, uniqueType, value)); - } -} 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/exceptions/UniqueValueViolationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java new file mode 100644 index 00000000..82c97f94 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java @@ -0,0 +1,11 @@ +package org.onap.sdc.workflow.services.exceptions; + + +public class UniqueValueViolationException extends RuntimeException { + + private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists."; + + public UniqueValueViolationException(String uniqueType, String value) { + super(String.format(UNIQUE_VALUE_VIOLATION_MSG, uniqueType, value)); + } +} 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; -- cgit 1.2.3-korg