@Test public void shouldApproveRequisitionAndTagWithModifiedBy() throws Exception { Rnr approvedRnr = new Rnr(); when(requisitionService.approve(rnr, null)).thenReturn(approvedRnr); whenNew(Rnr.class).withArguments(rnr.getId()).thenReturn(rnr); OpenLmisMessage message = new OpenLmisMessage("message.key"); when(messageService.message(message)).thenReturn("R&R saved successfully!"); when(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr)).thenReturn(message); final ResponseEntity<OpenLmisResponse> response = controller.approve(rnr.getId(), request); verify(requisitionService).approve(rnr, null); assertThat(rnr.getModifiedBy(), CoreMatchers.is(USER_ID)); assertThat(response.getStatusCode(), is(HttpStatus.OK)); assertThat(response.getBody().getSuccessMsg(), is("R&R saved successfully!")); }
@RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) public ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request) { Rnr rnr = new Rnr(id); rnr.setModifiedBy(loggedInUserId(request)); try { Rnr approvedRnr = requisitionService.approve(rnr, null); return success(messageService.message(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr))); } catch (DataException dataException) { logger.warn("Error in approving requisition #{}", id, dataException); return error(dataException, BAD_REQUEST); } }
RequisitionController extends BaseController { @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) public ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request) { Rnr rnr = new Rnr(id); rnr.setModifiedBy(loggedInUserId(request)); try { Rnr approvedRnr = requisitionService.approve(rnr, null); return success(messageService.message(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr))); } catch (DataException dataException) { logger.warn("Error in approving requisition #{}", id, dataException); return error(dataException, BAD_REQUEST); } } }
RequisitionController extends BaseController { @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) public ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request) { Rnr rnr = new Rnr(id); rnr.setModifiedBy(loggedInUserId(request)); try { Rnr approvedRnr = requisitionService.approve(rnr, null); return success(messageService.message(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr))); } catch (DataException dataException) { logger.warn("Error in approving requisition #{}", id, dataException); return error(dataException, BAD_REQUEST); } }  }
RequisitionController extends BaseController { @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) public ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request) { Rnr rnr = new Rnr(id); rnr.setModifiedBy(loggedInUserId(request)); try { Rnr approvedRnr = requisitionService.approve(rnr, null); return success(messageService.message(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr))); } catch (DataException dataException) { logger.warn("Error in approving requisition #{}", id, dataException); return error(dataException, BAD_REQUEST); } }  @RequestMapping(value = "/requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> initiateRnr(@RequestParam("facilityId") Long facilityId,
                                                      @RequestParam("programId") Long programId,
                                                      @RequestParam("emergency") Boolean emergency,
                                                      HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}", method = GET) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.body.data.get(\"rnr\"), 'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getById(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/skipped", method = GET) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.body.data.get(\"rnr\"), 'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getByIdWithOutSkippedItems(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/save", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> saveRnr(@RequestBody Rnr rnr,
                                                  @PathVariable("id") Long id,
                                                  HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/submit", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> submit(@PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/authorize", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> authorize(@PathVariable("id") Long id,
                                                    HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/lossAndAdjustments/reference-data", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> getReferenceData(); @RequestMapping(value = "/requisitions", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getRequisitionsForView(RequisitionSearchCriteria criteria, HttpServletRequest request); @RequestMapping(value = "/requisitions-for-approval", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> listForApproval(HttpServletRequest request); @RequestMapping(value = "/requisitions-for-convert-to-order", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CONVERT_TO_ORDER')") //TODO: move request params into form ResponseEntity<OpenLmisResponse> listForConvertToOrder(@RequestParam(value = "searchType", required = false, defaultValue = SEARCH_ALL) String searchType,
                                                                @RequestParam(value = "searchVal", required = false, defaultValue = "") String searchVal,
                                                                @RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
                                                                @RequestParam(value = "sortBy", required = false, defaultValue = "submittedDate") String sortBy,
                                                                @RequestParam(value = "sortDirection", required = false, defaultValue = "asc") String sortDirection,
                                                                HttpServletRequest request); @RequestMapping(value = "/logistics/periods", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllPeriodsForInitiatingRequisitionWithRequisitionStatus(
    RequisitionSearchCriteria criteria, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/print", method = GET, headers = ACCEPT_PDF) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.model.get(\"rnr\"), 'VIEW_REQUISITION')") ModelAndView printRequisition(@PathVariable Long id); @RequestMapping(value = "/requisitions/{id}/comments", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> insertComment(@RequestBody Comment comment,
                                                        @PathVariable("id") Long id,
                                                        HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/comments", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getCommentsForARnr(@PathVariable Long id); @RequestMapping(value = "/requisitions/delete/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'DELETE_REQUISITION')") ResponseEntity<OpenLmisResponse> deleteRnR(@PathVariable("id") Long rnrId); @RequestMapping(value = "/requisitions/skip/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> skipRnR(@PathVariable("id") Long rnrId,
                                                    HttpServletRequest request); @RequestMapping(value = "/requisitions/reject/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> rejectRnR(@PathVariable("id") Long rnrId,
                                                  HttpServletRequest request); @RequestMapping(value = "/requisitions/reopen/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> reopenRnR(@PathVariable("id") Long rnrId,
                                                  HttpServletRequest request); }
RequisitionController extends BaseController { @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) public ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request) { Rnr rnr = new Rnr(id); rnr.setModifiedBy(loggedInUserId(request)); try { Rnr approvedRnr = requisitionService.approve(rnr, null); return success(messageService.message(requisitionService.getApproveMessageBasedOnParentNode(approvedRnr))); } catch (DataException dataException) { logger.warn("Error in approving requisition #{}", id, dataException); return error(dataException, BAD_REQUEST); } }  @RequestMapping(value = "/requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> initiateRnr(@RequestParam("facilityId") Long facilityId,
                                                      @RequestParam("programId") Long programId,
                                                      @RequestParam("emergency") Boolean emergency,
                                                      HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}", method = GET) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.body.data.get(\"rnr\"), 'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getById(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/skipped", method = GET) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.body.data.get(\"rnr\"), 'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getByIdWithOutSkippedItems(@PathVariable Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/save", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> saveRnr(@RequestBody Rnr rnr,
                                                  @PathVariable("id") Long id,
                                                  HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/submit", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> submit(@PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/authorize", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> authorize(@PathVariable("id") Long id,
                                                    HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/approve", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> approve(@PathVariable("id") Long id, HttpServletRequest request); @RequestMapping(value = "/requisitions/lossAndAdjustments/reference-data", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> getReferenceData(); @RequestMapping(value = "/requisitions", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'VIEW_REQUISITION')") ResponseEntity<OpenLmisResponse> getRequisitionsForView(RequisitionSearchCriteria criteria, HttpServletRequest request); @RequestMapping(value = "/requisitions-for-approval", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> listForApproval(HttpServletRequest request); @RequestMapping(value = "/requisitions-for-convert-to-order", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CONVERT_TO_ORDER')") //TODO: move request params into form ResponseEntity<OpenLmisResponse> listForConvertToOrder(@RequestParam(value = "searchType", required = false, defaultValue = SEARCH_ALL) String searchType,
                                                                @RequestParam(value = "searchVal", required = false, defaultValue = "") String searchVal,
                                                                @RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
                                                                @RequestParam(value = "sortBy", required = false, defaultValue = "submittedDate") String sortBy,
                                                                @RequestParam(value = "sortDirection", required = false, defaultValue = "asc") String sortDirection,
                                                                HttpServletRequest request); @RequestMapping(value = "/logistics/periods", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllPeriodsForInitiatingRequisitionWithRequisitionStatus(
    RequisitionSearchCriteria criteria, HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/print", method = GET, headers = ACCEPT_PDF) @PostAuthorize("@requisitionPermissionService.hasPermission(principal, returnObject.model.get(\"rnr\"), 'VIEW_REQUISITION')") ModelAndView printRequisition(@PathVariable Long id); @RequestMapping(value = "/requisitions/{id}/comments", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION')") ResponseEntity<OpenLmisResponse> insertComment(@RequestBody Comment comment,
                                                        @PathVariable("id") Long id,
                                                        HttpServletRequest request); @RequestMapping(value = "/requisitions/{id}/comments", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getCommentsForARnr(@PathVariable Long id); @RequestMapping(value = "/requisitions/delete/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'DELETE_REQUISITION')") ResponseEntity<OpenLmisResponse> deleteRnR(@PathVariable("id") Long rnrId); @RequestMapping(value = "/requisitions/skip/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> skipRnR(@PathVariable("id") Long rnrId,
                                                    HttpServletRequest request); @RequestMapping(value = "/requisitions/reject/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> rejectRnR(@PathVariable("id") Long rnrId,
                                                  HttpServletRequest request); @RequestMapping(value = "/requisitions/reopen/{id}", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'CREATE_REQUISITION')") ResponseEntity<OpenLmisResponse> reopenRnR(@PathVariable("id") Long rnrId,
                                                  HttpServletRequest request); static final String RNR; static final String RNR_SAVE_SUCCESS; static final String RNR_LIST; static final String RNR_TEMPLATE; static final String PERIODS; static final String CURRENCY; static final String COMMENTS; static final String REGIMEN_TEMPLATE; static final String LOSS_ADJUSTMENT_TYPES; static final String STATUS_CHANGES; static final String IS_EMERGENCY; static final String LOSSES_AND_ADJUSTMENT_TYPES; static final String NUMBER_OF_MONTHS; static final String CAN_APPROVE_RNR; }