@Test public void shouldSaveRegimenTemplate() throws Exception { Long programId = 1L; List<RegimenColumn> columns = new ArrayList<>(); List<Regimen> regimens = new ArrayList<>(); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, columns); RegimenFormDTO regimenFormDTO = new RegimenFormDTO(regimens, columns); controller.save(programId, regimenFormDTO, request); verify(regimenColumnService).save(regimenTemplate, userId); verify(regimenService).save(regimens, userId); assertThat(regimenTemplate.getProgramId(), is(programId)); }
@Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request) { regimenService.save(regimenFormDTO.getRegimens(), loggedInUserId(request)); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, regimenFormDTO.getRegimenColumnList()); regimenColumnService.save(regimenTemplate, loggedInUserId(request)); return success(REGIMENS_SAVED_SUCCESSFULLY); }
RegimenController extends BaseController { @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request) { regimenService.save(regimenFormDTO.getRegimens(), loggedInUserId(request)); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, regimenFormDTO.getRegimenColumnList()); regimenColumnService.save(regimenTemplate, loggedInUserId(request)); return success(REGIMENS_SAVED_SUCCESSFULLY); } }
RegimenController extends BaseController { @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request) { regimenService.save(regimenFormDTO.getRegimens(), loggedInUserId(request)); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, regimenFormDTO.getRegimenColumnList()); regimenColumnService.save(regimenTemplate, loggedInUserId(request)); return success(REGIMENS_SAVED_SUCCESSFULLY); }  }
RegimenController extends BaseController { @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request) { regimenService.save(regimenFormDTO.getRegimens(), loggedInUserId(request)); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, regimenFormDTO.getRegimenColumnList()); regimenColumnService.save(regimenTemplate, loggedInUserId(request)); return success(REGIMENS_SAVED_SUCCESSFULLY); }  @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request); @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId); @RequestMapping(value = "/regimenCategories", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getAllRegimenCategories(); }
RegimenController extends BaseController { @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request) { regimenService.save(regimenFormDTO.getRegimens(), loggedInUserId(request)); RegimenTemplate regimenTemplate = new RegimenTemplate(programId, regimenFormDTO.getRegimenColumnList()); regimenColumnService.save(regimenTemplate, loggedInUserId(request)); return success(REGIMENS_SAVED_SUCCESSFULLY); }  @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request); @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId); @RequestMapping(value = "/regimenCategories", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getAllRegimenCategories(); static final String REGIMENS_SAVED_SUCCESSFULLY; static final String REGIMENS; static final String REGIMEN_CATEGORIES; }