@Test public void shouldReturnErrorMessagesForCorrespondingFields() throws Exception { RnrColumnList rnrColumns = new RnrColumnList(); MockHttpServletRequest request = new MockHttpServletRequest(); HashMap<String, OpenLmisMessage> errorMap = new HashMap<>(); OpenLmisMessage openLmisMessage = new OpenLmisMessage("code", "param1", "param2"); errorMap.put("key", openLmisMessage); when(rnrTemplateService.saveRnRTemplateForProgram((ProgramRnrTemplate) any())).thenReturn(errorMap); when(messageService.message(openLmisMessage.getCode(), openLmisMessage.getParams())).thenReturn("dummy message param1 param2"); ResponseEntity<OpenLmisResponse> responseEntity = rnrTemplateController.saveRnRTemplateForProgram(existingProgramId, rnrColumns, request); assertThat((String) responseEntity.getBody().getData().get("key"), is("dummy message param1 param2")); assertThat((String) responseEntity.getBody().getData().get("error"), is("form.error")); }
@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; }