diff options
author | avigaffa <avi.gaffa@amdocs.com> | 2018-06-21 17:32:00 +0300 |
---|---|---|
committer | avigaffa <avi.gaffa@amdocs.com> | 2018-06-21 17:42:17 +0300 |
commit | 285ff886bf5da36a64e05c419e960e8c6079334f (patch) | |
tree | 24c85ff1cb1c53c25b8206aaa9169bb3b20c5753 /workflow-designer-be/src | |
parent | f13bc01e97d9dafdd70b6ced86d58bb0cf1afbda (diff) |
Fixed functionality of Workflow API
renaming Exceptions package to lower case
Change-Id: Ib1395c15012d393be913d6588454b3b4b7c4b075
Issue-ID: SDC-1396
Signed-off-by: avigaffa <avi.gaffa@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src')
10 files changed, 54 insertions, 32 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; diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java index 81ec82e6..0885d476 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java @@ -103,7 +103,7 @@ public class WorkflowControllerTest { Workflow reqWorkflow = createWorkflow(1, false); mockMvc.perform( post(WORKFLOWS_URL).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) - .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isOk()) + .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isCreated()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); verify(workflowManagerMock, times(1)).create(reqWorkflow); } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java index 50a19655..4911060a 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java @@ -18,7 +18,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; 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; public class UniqueValueServiceTest { |