@Test public void shouldGiveErrorResponseWhenCreatingANewPeriodResultsThrowsDataException() throws Exception { ProcessingPeriod processingPeriod = new ProcessingPeriod(); doThrow(new DataException("error-message")).when(service).savePeriod(processingPeriod); ResponseEntity<OpenLmisResponse> responseEntity = controller.save(SCHEDULE_ID, processingPeriod, request); verify(service).savePeriod(processingPeriod); assertThat(responseEntity.getStatusCode(), is(HttpStatus.BAD_REQUEST)); assertThat(responseEntity.getBody().getErrorMsg(), is("error-message")); }
@RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request) { processingPeriod.setScheduleId(scheduleId); processingPeriod.setModifiedBy(loggedInUserId(request)); processingPeriod.setCreatedBy(loggedInUserId(request)); try { processingScheduleService.savePeriod(processingPeriod); } catch (Exception e) { return error(new DataException(e.getMessage()), HttpStatus.BAD_REQUEST); } ResponseEntity<OpenLmisResponse> successResponse = success(messageService.message("message.period.added.success")); successResponse.getBody().addData("id", processingPeriod.getId()); return successResponse; }
ProcessingPeriodController extends BaseController { @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request) { processingPeriod.setScheduleId(scheduleId); processingPeriod.setModifiedBy(loggedInUserId(request)); processingPeriod.setCreatedBy(loggedInUserId(request)); try { processingScheduleService.savePeriod(processingPeriod); } catch (Exception e) { return error(new DataException(e.getMessage()), HttpStatus.BAD_REQUEST); } ResponseEntity<OpenLmisResponse> successResponse = success(messageService.message("message.period.added.success")); successResponse.getBody().addData("id", processingPeriod.getId()); return successResponse; } }
ProcessingPeriodController extends BaseController { @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request) { processingPeriod.setScheduleId(scheduleId); processingPeriod.setModifiedBy(loggedInUserId(request)); processingPeriod.setCreatedBy(loggedInUserId(request)); try { processingScheduleService.savePeriod(processingPeriod); } catch (Exception e) { return error(new DataException(e.getMessage()), HttpStatus.BAD_REQUEST); } ResponseEntity<OpenLmisResponse> successResponse = success(messageService.message("message.period.added.success")); successResponse.getBody().addData("id", processingPeriod.getId()); return successResponse; }  }
ProcessingPeriodController extends BaseController { @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request) { processingPeriod.setScheduleId(scheduleId); processingPeriod.setModifiedBy(loggedInUserId(request)); processingPeriod.setCreatedBy(loggedInUserId(request)); try { processingScheduleService.savePeriod(processingPeriod); } catch (Exception e) { return error(new DataException(e.getMessage()), HttpStatus.BAD_REQUEST); } ResponseEntity<OpenLmisResponse> successResponse = success(messageService.message("message.period.added.success")); successResponse.getBody().addData("id", processingPeriod.getId()); return successResponse; }  @RequestMapping(value = "/schedules/{scheduleId}/periods", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> getAll(@PathVariable("scheduleId") Long scheduleId); @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request); @RequestMapping(value = "/periods/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); @RequestMapping(value = "/periods/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); }
ProcessingPeriodController extends BaseController { @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request) { processingPeriod.setScheduleId(scheduleId); processingPeriod.setModifiedBy(loggedInUserId(request)); processingPeriod.setCreatedBy(loggedInUserId(request)); try { processingScheduleService.savePeriod(processingPeriod); } catch (Exception e) { return error(new DataException(e.getMessage()), HttpStatus.BAD_REQUEST); } ResponseEntity<OpenLmisResponse> successResponse = success(messageService.message("message.period.added.success")); successResponse.getBody().addData("id", processingPeriod.getId()); return successResponse; }  @RequestMapping(value = "/schedules/{scheduleId}/periods", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> getAll(@PathVariable("scheduleId") Long scheduleId); @RequestMapping(value = "/schedules/{scheduleId}/periods", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> save(@PathVariable("scheduleId") Long scheduleId, @RequestBody ProcessingPeriod processingPeriod, HttpServletRequest request); @RequestMapping(value = "/periods/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SCHEDULE')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); @RequestMapping(value = "/periods/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); static final String PERIODS; static final String NEXT_START_DATE; }