@Test public void shouldGetAllByFacilityTypeIdAndProgramId() throws Exception { Long facilityTypeId = 1L; Long programId = 2L; String searchParam = "search"; Integer page = 2; String limit = "5"; Integer count = 10; Pagination pagination = new Pagination(0, 0); whenNew(Pagination.class).withArguments(page, parseInt(limit)).thenReturn(pagination); when(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)).thenReturn(count); when(service.getAllBy(facilityTypeId, programId, searchParam, pagination)).thenReturn(EMPTY_LIST); ResponseEntity<OpenLmisResponse> response = controller.getAllBy(facilityTypeId, programId, searchParam, page, limit); assertThat((java.util.List) response.getBody().getData().get(FACILITY_APPROVED_PRODUCTS), is(EMPTY_LIST)); assertThat((Pagination) response.getBody().getData().get(PAGINATION), is(pagination)); assertThat(pagination.getTotalRecords(), is(count)); verify(service).getAllBy(facilityTypeId, programId, searchParam, pagination); verify(service).getTotalSearchResultCount(facilityTypeId, programId, searchParam); }
@RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId, @RequestParam("programId") Long programId, @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)); List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts = service.getAllBy(facilityTypeId, programId, searchParam, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITY_APPROVED_PRODUCTS, facilityTypeApprovedProducts); response.getBody().addData(PAGINATION, pagination); return response; }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId, @RequestParam("programId") Long programId, @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)); List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts = service.getAllBy(facilityTypeId, programId, searchParam, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITY_APPROVED_PRODUCTS, facilityTypeApprovedProducts); response.getBody().addData(PAGINATION, pagination); return response; } }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId, @RequestParam("programId") Long programId, @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)); List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts = service.getAllBy(facilityTypeId, programId, searchParam, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITY_APPROVED_PRODUCTS, facilityTypeApprovedProducts); response.getBody().addData(PAGINATION, pagination); return response; }  }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId, @RequestParam("programId") Long programId, @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)); List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts = service.getAllBy(facilityTypeId, programId, searchParam, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITY_APPROVED_PRODUCTS, facilityTypeApprovedProducts); response.getBody().addData(PAGINATION, pagination); return response; }  @RequestMapping(value = "/facility/{facilityId}/program/{programId}/nonFullSupply", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllNonFullSupplyProductsByFacilityAndProgram(@PathVariable("facilityId") Long facilityId,
                                                                                          @PathVariable("programId") Long programId); @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId,
                                                   @RequestParam("programId") Long programId,
                                                   @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam,
                                                   @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                   @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); }
FacilityApprovedProductController extends BaseController { @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") public ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId, @RequestParam("programId") Long programId, @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(service.getTotalSearchResultCount(facilityTypeId, programId, searchParam)); List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts = service.getAllBy(facilityTypeId, programId, searchParam, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITY_APPROVED_PRODUCTS, facilityTypeApprovedProducts); response.getBody().addData(PAGINATION, pagination); return response; }  @RequestMapping(value = "/facility/{facilityId}/program/{programId}/nonFullSupply", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'CREATE_REQUISITION, AUTHORIZE_REQUISITION')") ResponseEntity<OpenLmisResponse> getAllNonFullSupplyProductsByFacilityAndProgram(@PathVariable("facilityId") Long facilityId,
                                                                                          @PathVariable("programId") Long programId); @RequestMapping(method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> getAllBy(@RequestParam("facilityTypeId") Long facilityTypeId,
                                                   @RequestParam("programId") Long programId,
                                                   @RequestParam(value = "searchParam", defaultValue = "", required = false) String searchParam,
                                                   @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                   @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> insert(@RequestBody FacilityTypeApprovedProductList facilityTypeApprovedProducts,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY_APPROVED_PRODUCT')") ResponseEntity<OpenLmisResponse> delete(@PathVariable("id") Long id); static final String NON_FULL_SUPPLY_PRODUCTS; static final String FACILITY_APPROVED_PRODUCTS; static final String PAGINATION; static final String FACILITY_TYPE_APPROVED_PRODUCT; }