@Test public void getAllTransplantRequestsTest() throws Exception { setUpTransplantRequests(); mockMvc.perform(get("/clients/transplantRequests").header("X-Auth-Token", VALID_AUTH)) .andExpect(status().isOk()) .andExpect(jsonPath("$.totalResults", is(3))); }
@GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) public ResponseEntity<PaginatedTransplantList> getAllTransplantRequests( @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "regions", required = false) Set<String> regions, @RequestParam(value = "organs", required = false) Set<Organ> organs, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); final Set<String> regionsToFilter = new HashSet<>(); if (regions != null) { for (String region : regions) { regionsToFilter.add(region.replace("%20", " ")); } } List<TransplantRequestView> matchingRequests = State.getClientManager().getAllTransplantRequests().stream() .filter(request -> regionsToFilter.isEmpty() || regionsToFilter.contains(request.getClient().getRegion()) || (regionsToFilter.contains("International") && request.getClient().getCountry() != Country.NZ)) .filter(request -> organs == null || organs.isEmpty() || organs.contains(request.getRequestedOrgan())) .map(TransplantRequestView::new) .collect(Collectors.toList()); if (offset == null) { offset = 0; } if (count == null) { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), matchingRequests.size()), matchingRequests.size()), HttpStatus.OK); } else { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), Math.min(offset + count, matchingRequests.size())), matchingRequests.size()), HttpStatus.OK); } }
ClientTransplantRequestsController { @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) public ResponseEntity<PaginatedTransplantList> getAllTransplantRequests( @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "regions", required = false) Set<String> regions, @RequestParam(value = "organs", required = false) Set<Organ> organs, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); final Set<String> regionsToFilter = new HashSet<>(); if (regions != null) { for (String region : regions) { regionsToFilter.add(region.replace("%20", " ")); } } List<TransplantRequestView> matchingRequests = State.getClientManager().getAllTransplantRequests().stream() .filter(request -> regionsToFilter.isEmpty() || regionsToFilter.contains(request.getClient().getRegion()) || (regionsToFilter.contains("International") && request.getClient().getCountry() != Country.NZ)) .filter(request -> organs == null || organs.isEmpty() || organs.contains(request.getRequestedOrgan())) .map(TransplantRequestView::new) .collect(Collectors.toList()); if (offset == null) { offset = 0; } if (count == null) { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), matchingRequests.size()), matchingRequests.size()), HttpStatus.OK); } else { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), Math.min(offset + count, matchingRequests.size())), matchingRequests.size()), HttpStatus.OK); } } }
ClientTransplantRequestsController { @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) public ResponseEntity<PaginatedTransplantList> getAllTransplantRequests( @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "regions", required = false) Set<String> regions, @RequestParam(value = "organs", required = false) Set<Organ> organs, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); final Set<String> regionsToFilter = new HashSet<>(); if (regions != null) { for (String region : regions) { regionsToFilter.add(region.replace("%20", " ")); } } List<TransplantRequestView> matchingRequests = State.getClientManager().getAllTransplantRequests().stream() .filter(request -> regionsToFilter.isEmpty() || regionsToFilter.contains(request.getClient().getRegion()) || (regionsToFilter.contains("International") && request.getClient().getCountry() != Country.NZ)) .filter(request -> organs == null || organs.isEmpty() || organs.contains(request.getRequestedOrgan())) .map(TransplantRequestView::new) .collect(Collectors.toList()); if (offset == null) { offset = 0; } if (count == null) { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), matchingRequests.size()), matchingRequests.size()), HttpStatus.OK); } else { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), Math.min(offset + count, matchingRequests.size())), matchingRequests.size()), HttpStatus.OK); } }  }
ClientTransplantRequestsController { @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) public ResponseEntity<PaginatedTransplantList> getAllTransplantRequests( @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "regions", required = false) Set<String> regions, @RequestParam(value = "organs", required = false) Set<Organ> organs, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); final Set<String> regionsToFilter = new HashSet<>(); if (regions != null) { for (String region : regions) { regionsToFilter.add(region.replace("%20", " ")); } } List<TransplantRequestView> matchingRequests = State.getClientManager().getAllTransplantRequests().stream() .filter(request -> regionsToFilter.isEmpty() || regionsToFilter.contains(request.getClient().getRegion()) || (regionsToFilter.contains("International") && request.getClient().getCountry() != Country.NZ)) .filter(request -> organs == null || organs.isEmpty() || organs.contains(request.getRequestedOrgan())) .map(TransplantRequestView::new) .collect(Collectors.toList()); if (offset == null) { offset = 0; } if (count == null) { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), matchingRequests.size()), matchingRequests.size()), HttpStatus.OK); } else { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), Math.min(offset + count, matchingRequests.size())), matchingRequests.size()), HttpStatus.OK); } }  @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) ResponseEntity<PaginatedTransplantList> getAllTransplantRequests(
            @RequestParam(value = "offset", required = false) Integer offset,
            @RequestParam(value = "count", required = false) Integer count,
            @RequestParam(value = "regions", required = false) Set<String> regions,
            @RequestParam(value = "organs", required = false) Set<Organ> organs,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @GetMapping("/clients/{id}/transplantRequests") ResponseEntity<Collection<TransplantRequest>> getClientTransplantRequests(
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{id}/transplantRequests") ResponseEntity<Collection<TransplantRequest>> postTransplantRequest(
            @RequestBody TransplantRequest transplantRequest,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PatchMapping("/clients/{uid}/transplantRequests/{id}") @JsonView(Views.Overview.class) ResponseEntity<TransplantRequest> patchTransplantRequest(
            @RequestBody ResolveTransplantRequestObject resolveRequestObject,
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); }
ClientTransplantRequestsController { @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) public ResponseEntity<PaginatedTransplantList> getAllTransplantRequests( @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "regions", required = false) Set<String> regions, @RequestParam(value = "organs", required = false) Set<Organ> organs, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws AuthenticationException { State.getAuthenticationManager().verifyClinicianOrAdmin(authToken); final Set<String> regionsToFilter = new HashSet<>(); if (regions != null) { for (String region : regions) { regionsToFilter.add(region.replace("%20", " ")); } } List<TransplantRequestView> matchingRequests = State.getClientManager().getAllTransplantRequests().stream() .filter(request -> regionsToFilter.isEmpty() || regionsToFilter.contains(request.getClient().getRegion()) || (regionsToFilter.contains("International") && request.getClient().getCountry() != Country.NZ)) .filter(request -> organs == null || organs.isEmpty() || organs.contains(request.getRequestedOrgan())) .map(TransplantRequestView::new) .collect(Collectors.toList()); if (offset == null) { offset = 0; } if (count == null) { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), matchingRequests.size()), matchingRequests.size()), HttpStatus.OK); } else { return new ResponseEntity<>(new PaginatedTransplantList( matchingRequests.subList( Math.min(offset, matchingRequests.size()), Math.min(offset + count, matchingRequests.size())), matchingRequests.size()), HttpStatus.OK); } }  @GetMapping("/clients/transplantRequests") @JsonView(Views.Overview.class) ResponseEntity<PaginatedTransplantList> getAllTransplantRequests(
            @RequestParam(value = "offset", required = false) Integer offset,
            @RequestParam(value = "count", required = false) Integer count,
            @RequestParam(value = "regions", required = false) Set<String> regions,
            @RequestParam(value = "organs", required = false) Set<Organ> organs,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @GetMapping("/clients/{id}/transplantRequests") ResponseEntity<Collection<TransplantRequest>> getClientTransplantRequests(
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{id}/transplantRequests") ResponseEntity<Collection<TransplantRequest>> postTransplantRequest(
            @RequestBody TransplantRequest transplantRequest,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PatchMapping("/clients/{uid}/transplantRequests/{id}") @JsonView(Views.Overview.class) ResponseEntity<TransplantRequest> patchTransplantRequest(
            @RequestBody ResolveTransplantRequestObject resolveRequestObject,
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken);  }