@Test public void shouldSearchFacilitiesBySearchParam() throws Exception { String searchParam = "FAC"; String columnName = "facility"; Integer page = 1; String limit = "5"; List<Facility> facilities = new ArrayList<>(); Integer totalResultCount = 10; Pagination pagination = new Pagination(0, 0); whenNew(Pagination.class).withArguments(page, parseInt(limit)).thenReturn(pagination); when(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)).thenReturn(totalResultCount); when(facilityService.searchBy(searchParam, columnName, pagination)).thenReturn(facilities); ResponseEntity<OpenLmisResponse> response = facilityController.get(searchParam, columnName, page, limit); assertThat((List<Facility>) response.getBody().getData().get(FacilityController.FACILITIES), is(facilities)); assertThat((Pagination) response.getBody().getData().get("pagination"), is(pagination)); assertThat(pagination.getTotalRecords(), is(totalResultCount)); verify(facilityService).getTotalSearchResultCountByColumnName(searchParam, columnName); verify(facilityService).searchBy(searchParam, columnName, pagination); }
@RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") public ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam, @RequestParam(value = "columnName") String columnName, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)); List<Facility> facilities = facilityService.searchBy(searchParam, columnName, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITIES, facilities); response.getBody().addData("pagination", pagination); return response; }
FacilityController extends BaseController { @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") public ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam, @RequestParam(value = "columnName") String columnName, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)); List<Facility> facilities = facilityService.searchBy(searchParam, columnName, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITIES, facilities); response.getBody().addData("pagination", pagination); return response; } }
FacilityController extends BaseController { @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") public ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam, @RequestParam(value = "columnName") String columnName, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)); List<Facility> facilities = facilityService.searchBy(searchParam, columnName, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITIES, facilities); response.getBody().addData("pagination", pagination); return response; }  }
FacilityController extends BaseController { @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") public ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam, @RequestParam(value = "columnName") String columnName, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)); List<Facility> facilities = facilityService.searchBy(searchParam, columnName, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITIES, facilities); response.getBody().addData("pagination", pagination); return response; }  @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam,
                                              @RequestParam(value = "columnName") String columnName,
                                              @RequestParam(value = "page", defaultValue = "1") Integer page,
                                              @Value("${search.page.size}") String limit); @RequestMapping(value = "/filter-facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getFilteredFacilities(@RequestParam(value = "searchParam", required = false) String searchParam,
                                                                @RequestParam(value = "facilityTypeId", required = false) Long facilityTypeId,
                                                                @RequestParam(value = "geoZoneId", required = false) Long geoZoneId,
                                                                @RequestParam(value = "virtualFacility", required = false) Boolean virtualFacility,
                                                                @RequestParam(value = "enabled", required = false) Boolean enabled,
                                                                @Value("${search.results.limit}") String facilitySearchLimit); @RequestMapping(value = "/user/facilities", method = GET) List<Facility> getHomeFacility(HttpServletRequest httpServletRequest); @RequestMapping(value = "/facilities/reference-data", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") Map getReferenceData(); @RequestMapping(value = "/facilities/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_FACILITY, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getFacility(@PathVariable(value = "id") Long id); @RequestMapping(value = "/create/requisition/supervised/{programId}/facilities.json", method = GET) ResponseEntity<ModelMap> getUserSupervisedFacilitiesSupportingProgram(@PathVariable(value = "programId") Long programId,
                                                                               HttpServletRequest request); @RequestMapping(value = "/users/{userId}/supervised/{programId}/facilities.json", method = GET) ResponseEntity<ModelMap> getUserSupervisedFacilitiesSupportingProgram(@PathVariable(
        value = "programId") Long programId, @PathVariable("userId") Long userId); @RequestMapping(value = "/facilities", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity insert(@RequestBody Facility facility, HttpServletRequest request); @RequestMapping(value = "/facilities/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody Facility facility,
                                                 HttpServletRequest request); @RequestMapping(value = "/user/facilities/view", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> listForViewing(HttpServletRequest request); @RequestMapping(value = "/facilities/{facilityId}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> softDelete(HttpServletRequest httpServletRequest,
                                                     @PathVariable Long facilityId); @RequestMapping(value = "/facilities/{id}/restore", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> restore(HttpServletRequest request,
                                                  @PathVariable("id") Long facilityId); @RequestMapping(value = "/deliveryZones/{deliveryZoneId}/programs/{programId}/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION')") ResponseEntity<OpenLmisResponse> getFacilitiesForDeliveryZoneAndProgram(@PathVariable("deliveryZoneId") Long deliveryZoneId,
                                                                                 @PathVariable("programId") Long programId); @RequestMapping(value = "/enabledWarehouses", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> getEnabledWarehouses(); @RequestMapping(value = "/facility-types", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_FACILITY_APPROVED_PRODUCT, MANAGE_USER')") List<FacilityType> getFacilityTypes(); @RequestMapping(value = "/facility-contacts", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getContactsForFacility(@RequestParam("type") String type, @RequestParam("facilityId") Long facilityId); @RequestMapping(value = "/facility-supervisors", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getFacilitySupervisors(@RequestParam("facilityId") Long facilityId); @RequestMapping(value = "/facilityType/{facilityTypeId}/requisitionGroup/{requisitionGroupId}/facilities", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getFacilityByTypeAndRequisitionGroupId(@PathVariable("facilityTypeId") Long facilityTypeId, @PathVariable("requisitionGroupId") Long requisitionGroupId); @RequestMapping(value = "/geoFacilityTree", method = GET) ResponseEntity<OpenLmisResponse> getGeoTreeFacility(HttpServletRequest httpServletRequest); @RequestMapping(value = "/user/facilities/view-order-requisition", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> listForViewingOrderRequisition(HttpServletRequest request); }
FacilityController extends BaseController { @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") public ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam, @RequestParam(value = "columnName") String columnName, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit) { Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords(facilityService.getTotalSearchResultCountByColumnName(searchParam, columnName)); List<Facility> facilities = facilityService.searchBy(searchParam, columnName, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(FACILITIES, facilities); response.getBody().addData("pagination", pagination); return response; }  @RequestMapping(value = "/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_USER')") ResponseEntity<OpenLmisResponse> get(@RequestParam(value = "searchParam", required = false) String searchParam,
                                              @RequestParam(value = "columnName") String columnName,
                                              @RequestParam(value = "page", defaultValue = "1") Integer page,
                                              @Value("${search.page.size}") String limit); @RequestMapping(value = "/filter-facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getFilteredFacilities(@RequestParam(value = "searchParam", required = false) String searchParam,
                                                                @RequestParam(value = "facilityTypeId", required = false) Long facilityTypeId,
                                                                @RequestParam(value = "geoZoneId", required = false) Long geoZoneId,
                                                                @RequestParam(value = "virtualFacility", required = false) Boolean virtualFacility,
                                                                @RequestParam(value = "enabled", required = false) Boolean enabled,
                                                                @Value("${search.results.limit}") String facilitySearchLimit); @RequestMapping(value = "/user/facilities", method = GET) List<Facility> getHomeFacility(HttpServletRequest httpServletRequest); @RequestMapping(value = "/facilities/reference-data", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") Map getReferenceData(); @RequestMapping(value = "/facilities/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal, 'MANAGE_FACILITY, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getFacility(@PathVariable(value = "id") Long id); @RequestMapping(value = "/create/requisition/supervised/{programId}/facilities.json", method = GET) ResponseEntity<ModelMap> getUserSupervisedFacilitiesSupportingProgram(@PathVariable(value = "programId") Long programId,
                                                                               HttpServletRequest request); @RequestMapping(value = "/users/{userId}/supervised/{programId}/facilities.json", method = GET) ResponseEntity<ModelMap> getUserSupervisedFacilitiesSupportingProgram(@PathVariable(
        value = "programId") Long programId, @PathVariable("userId") Long userId); @RequestMapping(value = "/facilities", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity insert(@RequestBody Facility facility, HttpServletRequest request); @RequestMapping(value = "/facilities/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> update(@PathVariable("id") Long id,
                                                 @RequestBody Facility facility,
                                                 HttpServletRequest request); @RequestMapping(value = "/user/facilities/view", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> listForViewing(HttpServletRequest request); @RequestMapping(value = "/facilities/{facilityId}", method = DELETE, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> softDelete(HttpServletRequest httpServletRequest,
                                                     @PathVariable Long facilityId); @RequestMapping(value = "/facilities/{id}/restore", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY')") ResponseEntity<OpenLmisResponse> restore(HttpServletRequest request,
                                                  @PathVariable("id") Long facilityId); @RequestMapping(value = "/deliveryZones/{deliveryZoneId}/programs/{programId}/facilities", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_DISTRIBUTION')") ResponseEntity<OpenLmisResponse> getFacilitiesForDeliveryZoneAndProgram(@PathVariable("deliveryZoneId") Long deliveryZoneId,
                                                                                 @PathVariable("programId") Long programId); @RequestMapping(value = "/enabledWarehouses", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> getEnabledWarehouses(); @RequestMapping(value = "/facility-types", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_FACILITY, MANAGE_SUPERVISORY_NODE, MANAGE_REQUISITION_GROUP, MANAGE_SUPPLY_LINE, MANAGE_FACILITY_APPROVED_PRODUCT, MANAGE_USER')") List<FacilityType> getFacilityTypes(); @RequestMapping(value = "/facility-contacts", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getContactsForFacility(@RequestParam("type") String type, @RequestParam("facilityId") Long facilityId); @RequestMapping(value = "/facility-supervisors", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getFacilitySupervisors(@RequestParam("facilityId") Long facilityId); @RequestMapping(value = "/facilityType/{facilityTypeId}/requisitionGroup/{requisitionGroupId}/facilities", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getFacilityByTypeAndRequisitionGroupId(@PathVariable("facilityTypeId") Long facilityTypeId, @PathVariable("requisitionGroupId") Long requisitionGroupId); @RequestMapping(value = "/geoFacilityTree", method = GET) ResponseEntity<OpenLmisResponse> getGeoTreeFacility(HttpServletRequest httpServletRequest); @RequestMapping(value = "/user/facilities/view-order-requisition", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> listForViewingOrderRequisition(HttpServletRequest request); static final String FACILITIES; }