@Test public void shouldCreateARnRTemplateForAGivenProgramWithSpecifiedColumns() throws Exception { final RnrColumnList rnrColumns = new RnrColumnList(); MockHttpServletRequest request = new MockHttpServletRequest(); when(rnrTemplateService.saveRnRTemplateForProgram((ProgramRnrTemplate) any())).thenReturn(new HashMap<String, OpenLmisMessage>()); when(messageService.message("template.save.success")).thenReturn("dummy success"); ResponseEntity<OpenLmisResponse> responseEntity = rnrTemplateController.saveRnRTemplateForProgram(existingProgramId, rnrColumns, request); assertThat(responseEntity.getBody().getSuccessMsg(), is("dummy success")); }
@RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") public ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId, @RequestBody RnrColumnList rnrColumnList, HttpServletRequest request) { ProgramRnrTemplate programRnrTemplate = new ProgramRnrTemplate(programId, rnrColumnList); programRnrTemplate.setModifiedBy(loggedInUserId(request)); Map<String, OpenLmisMessage> validationErrors = rnrTemplateService.saveRnRTemplateForProgram(programRnrTemplate); ResponseEntity<OpenLmisResponse> responseEntity; if (!validationErrors.isEmpty()) { responseEntity = response(getMessages(validationErrors), HttpStatus.BAD_REQUEST); responseEntity.getBody().addData("error", "form.error"); } else { responseEntity = success(messageService.message(RNR_TEMPLATE_SAVE_SUCCESS)); } return responseEntity; }
RnrTemplateController extends BaseController { @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") public ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId, @RequestBody RnrColumnList rnrColumnList, HttpServletRequest request) { ProgramRnrTemplate programRnrTemplate = new ProgramRnrTemplate(programId, rnrColumnList); programRnrTemplate.setModifiedBy(loggedInUserId(request)); Map<String, OpenLmisMessage> validationErrors = rnrTemplateService.saveRnRTemplateForProgram(programRnrTemplate); ResponseEntity<OpenLmisResponse> responseEntity; if (!validationErrors.isEmpty()) { responseEntity = response(getMessages(validationErrors), HttpStatus.BAD_REQUEST); responseEntity.getBody().addData("error", "form.error"); } else { responseEntity = success(messageService.message(RNR_TEMPLATE_SAVE_SUCCESS)); } return responseEntity; } }
RnrTemplateController extends BaseController { @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") public ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId, @RequestBody RnrColumnList rnrColumnList, HttpServletRequest request) { ProgramRnrTemplate programRnrTemplate = new ProgramRnrTemplate(programId, rnrColumnList); programRnrTemplate.setModifiedBy(loggedInUserId(request)); Map<String, OpenLmisMessage> validationErrors = rnrTemplateService.saveRnRTemplateForProgram(programRnrTemplate); ResponseEntity<OpenLmisResponse> responseEntity; if (!validationErrors.isEmpty()) { responseEntity = response(getMessages(validationErrors), HttpStatus.BAD_REQUEST); responseEntity.getBody().addData("error", "form.error"); } else { responseEntity = success(messageService.message(RNR_TEMPLATE_SAVE_SUCCESS)); } return responseEntity; }  }
RnrTemplateController extends BaseController { @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") public ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId, @RequestBody RnrColumnList rnrColumnList, HttpServletRequest request) { ProgramRnrTemplate programRnrTemplate = new ProgramRnrTemplate(programId, rnrColumnList); programRnrTemplate.setModifiedBy(loggedInUserId(request)); Map<String, OpenLmisMessage> validationErrors = rnrTemplateService.saveRnRTemplateForProgram(programRnrTemplate); ResponseEntity<OpenLmisResponse> responseEntity; if (!validationErrors.isEmpty()) { responseEntity = response(getMessages(validationErrors), HttpStatus.BAD_REQUEST); responseEntity.getBody().addData("error", "form.error"); } else { responseEntity = success(messageService.message(RNR_TEMPLATE_SAVE_SUCCESS)); } return responseEntity; }  @RequestMapping(value = "/program/{programId}/rnr-template", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") RnrTemplateForm fetchAllProgramRnrColumnList(@PathVariable("programId") Long programId); @RequestMapping(value = "/rnr/{programId}/columns", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION, VIEW_REQUISITION')") List<RnrColumn> fetchColumnsForRequisition(@PathVariable("programId") Long programId); @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId,
                                                                    @RequestBody RnrColumnList rnrColumnList,
                                                                    HttpServletRequest request); }
RnrTemplateController extends BaseController { @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") public ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId, @RequestBody RnrColumnList rnrColumnList, HttpServletRequest request) { ProgramRnrTemplate programRnrTemplate = new ProgramRnrTemplate(programId, rnrColumnList); programRnrTemplate.setModifiedBy(loggedInUserId(request)); Map<String, OpenLmisMessage> validationErrors = rnrTemplateService.saveRnRTemplateForProgram(programRnrTemplate); ResponseEntity<OpenLmisResponse> responseEntity; if (!validationErrors.isEmpty()) { responseEntity = response(getMessages(validationErrors), HttpStatus.BAD_REQUEST); responseEntity.getBody().addData("error", "form.error"); } else { responseEntity = success(messageService.message(RNR_TEMPLATE_SAVE_SUCCESS)); } return responseEntity; }  @RequestMapping(value = "/program/{programId}/rnr-template", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") RnrTemplateForm fetchAllProgramRnrColumnList(@PathVariable("programId") Long programId); @RequestMapping(value = "/rnr/{programId}/columns", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION, APPROVE_REQUISITION, VIEW_REQUISITION')") List<RnrColumn> fetchColumnsForRequisition(@PathVariable("programId") Long programId); @RequestMapping(value = "/program/{programId}/rnr-template", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CONFIGURE_RNR')") ResponseEntity<OpenLmisResponse> saveRnRTemplateForProgram(@PathVariable("programId") Long programId,
                                                                    @RequestBody RnrColumnList rnrColumnList,
                                                                    HttpServletRequest request); static final String RNR_TEMPLATE_SAVE_SUCCESS; }