@Test public void shouldReturnErrorMessageWhenExceptionOccursOnSupervisoryNodeInsert() { SupervisoryNode supervisoryNode = new SupervisoryNode(); doThrow(new DataException("error")).when(supervisoryNodeService).save(supervisoryNode); ResponseEntity<OpenLmisResponse> responseEntity = controller.insert(supervisoryNode, request); verify(supervisoryNodeService).save(supervisoryNode); verify(messageService, never()).message(anyString(), anyString()); assertThat(responseEntity.getBody().getErrorMsg(), is("error")); assertThat(supervisoryNode.getCreatedBy(), is(1L)); assertThat(supervisoryNode.getModifiedBy(), is(1L)); }
@RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supervisoryNode.setCreatedBy(userId); supervisoryNode.setModifiedBy(userId); try { supervisoryNodeService.save(supervisoryNode); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success( messageService.message("message.supervisory.node.created.success", supervisoryNode.getName())); response.getBody().addData("supervisoryNodeId", supervisoryNode.getId()); return response; }
SupervisoryNodeController extends BaseController { @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supervisoryNode.setCreatedBy(userId); supervisoryNode.setModifiedBy(userId); try { supervisoryNodeService.save(supervisoryNode); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success( messageService.message("message.supervisory.node.created.success", supervisoryNode.getName())); response.getBody().addData("supervisoryNodeId", supervisoryNode.getId()); return response; } }
SupervisoryNodeController extends BaseController { @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supervisoryNode.setCreatedBy(userId); supervisoryNode.setModifiedBy(userId); try { supervisoryNodeService.save(supervisoryNode); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success( messageService.message("message.supervisory.node.created.success", supervisoryNode.getName())); response.getBody().addData("supervisoryNodeId", supervisoryNode.getId()); return response; }  }
SupervisoryNodeController extends BaseController { @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supervisoryNode.setCreatedBy(userId); supervisoryNode.setModifiedBy(userId); try { supervisoryNodeService.save(supervisoryNode); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success( messageService.message("message.supervisory.node.created.success", supervisoryNode.getName())); response.getBody().addData("supervisoryNodeId", supervisoryNode.getId()); return response; }  @RequestMapping(value = "/supervisory-nodes", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/supervisory-nodes/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadOnly(); @RequestMapping(value = "/paged-search-supervisory-nodes", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> searchSupervisoryNode(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
                                                                @RequestParam(required = true) String param,
                                                                @RequestParam(required = true) Boolean parent); @RequestMapping(value = "/supervisory-nodes/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") SupervisoryNode getById(@PathVariable(value = "id") Long id); @RequestMapping(value = "/search-supervisory-nodes", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP')") List<SupervisoryNode> getFilteredNodes(@RequestParam(value = "searchParam") String param); @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode,
                                                 HttpServletRequest request); @RequestMapping(value = "/supervisory-nodes/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> update(@RequestBody SupervisoryNode supervisoryNode,
                                                 @PathVariable(value = "id") Long supervisoryNodeId,
                                                 HttpServletRequest request); @RequestMapping(value = "/topLevelSupervisoryNodes", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") List<SupervisoryNode> searchTopLevelSupervisoryNodesByName(@RequestParam(value = "searchParam") String param); }
SupervisoryNodeController extends BaseController { @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") public ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supervisoryNode.setCreatedBy(userId); supervisoryNode.setModifiedBy(userId); try { supervisoryNodeService.save(supervisoryNode); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success( messageService.message("message.supervisory.node.created.success", supervisoryNode.getName())); response.getBody().addData("supervisoryNodeId", supervisoryNode.getId()); return response; }  @RequestMapping(value = "/supervisory-nodes", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/supervisory-nodes/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadOnly(); @RequestMapping(value = "/paged-search-supervisory-nodes", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> searchSupervisoryNode(@RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
                                                                @RequestParam(required = true) String param,
                                                                @RequestParam(required = true) Boolean parent); @RequestMapping(value = "/supervisory-nodes/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") SupervisoryNode getById(@PathVariable(value = "id") Long id); @RequestMapping(value = "/search-supervisory-nodes", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP')") List<SupervisoryNode> getFilteredNodes(@RequestParam(value = "searchParam") String param); @RequestMapping(value = "/supervisory-nodes", method = POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody SupervisoryNode supervisoryNode,
                                                 HttpServletRequest request); @RequestMapping(value = "/supervisory-nodes/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPERVISORY_NODE')") ResponseEntity<OpenLmisResponse> update(@RequestBody SupervisoryNode supervisoryNode,
                                                 @PathVariable(value = "id") Long supervisoryNodeId,
                                                 HttpServletRequest request); @RequestMapping(value = "/topLevelSupervisoryNodes", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") List<SupervisoryNode> searchTopLevelSupervisoryNodesByName(@RequestParam(value = "searchParam") String param); static final String SUPERVISORY_NODES; }