paging in suggestion api
This commit is contained in:
parent
760791578b
commit
3cbce1024c
|
@ -170,15 +170,16 @@ public class OrganizationController extends AbstractDnetController {
|
||||||
|
|
||||||
@GetMapping("/duplicates/byCountry/{country}")
|
@GetMapping("/duplicates/byCountry/{country}")
|
||||||
public Iterable<DuplicateGroupView> findDuplicatesByCountry(@PathVariable final String country,
|
public Iterable<DuplicateGroupView> findDuplicatesByCountry(@PathVariable final String country,
|
||||||
@RequestParam(required = false, defaultValue = "${openorgs.findDuplicatesByCountry.limit.default}") final int limit,
|
@RequestParam(required = false, defaultValue = "0") final int page,
|
||||||
|
@RequestParam(required = false, defaultValue = "${openorgs.findDuplicatesByCountry.limit.default}") final int size,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
|
|
||||||
if (UserInfo.isSuperAdmin(authentication)) { return duplicateGroupViewRepository.findByCountry(country, PageRequest.of(0, limit)); }
|
if (UserInfo.isSuperAdmin(authentication)) { return duplicateGroupViewRepository.findByCountry(country, PageRequest.of(page, size)); }
|
||||||
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||||
return userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
return userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
||||||
.stream()
|
.stream()
|
||||||
.filter(country::equalsIgnoreCase)
|
.filter(country::equalsIgnoreCase)
|
||||||
.map(c -> duplicateGroupViewRepository.findByCountry(c, PageRequest.of(0, limit)))
|
.map(c -> duplicateGroupViewRepository.findByCountry(c, PageRequest.of(page, size)))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(new ArrayList<DuplicateGroupView>());
|
.orElse(new ArrayList<DuplicateGroupView>());
|
||||||
}
|
}
|
||||||
|
@ -188,7 +189,7 @@ public class OrganizationController extends AbstractDnetController {
|
||||||
@GetMapping(value = "/duplicates/byCountry/{country}/csv", produces = "text/csv")
|
@GetMapping(value = "/duplicates/byCountry/{country}/csv", produces = "text/csv")
|
||||||
public void findDuplicatesByCountryCSV(@PathVariable final String country, final HttpServletResponse res, final Authentication authentication)
|
public void findDuplicatesByCountryCSV(@PathVariable final String country, final HttpServletResponse res, final Authentication authentication)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final Iterable<DuplicateGroupView> list = findDuplicatesByCountry(country, Integer.MAX_VALUE, authentication);
|
final Iterable<DuplicateGroupView> list = findDuplicatesByCountry(country, 0, Integer.MAX_VALUE, authentication);
|
||||||
CSVConverter.writeCSV(res.getOutputStream(), list, DuplicateGroupView.class, "id", "name", "city", "country", "numberOfDuplicates");
|
CSVConverter.writeCSV(res.getOutputStream(), list, DuplicateGroupView.class, "id", "name", "city", "country", "numberOfDuplicates");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,13 +265,14 @@ public class OrganizationController extends AbstractDnetController {
|
||||||
@GetMapping("/byCountry/{status}/{code}")
|
@GetMapping("/byCountry/{status}/{code}")
|
||||||
public List<OrganizationSimpleView> findOrgsByStatusAndCountry(@PathVariable final String status,
|
public List<OrganizationSimpleView> findOrgsByStatusAndCountry(@PathVariable final String status,
|
||||||
@PathVariable final String code,
|
@PathVariable final String code,
|
||||||
@RequestParam(required = false, defaultValue = "${openorgs.findOrgsByStatusAndCountry.limit.default}") final int limit,
|
@RequestParam(required = false, defaultValue = "0") final int page,
|
||||||
|
@RequestParam(required = false, defaultValue = "${openorgs.findOrgsByStatusAndCountry.limit.default}") final int size,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
if (!UserInfo.isSuperAdmin(authentication) && !userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
if (!UserInfo.isSuperAdmin(authentication) && !userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
||||||
throw new RuntimeException("User not authorized");
|
throw new RuntimeException("User not authorized");
|
||||||
}
|
}
|
||||||
if ("all".equalsIgnoreCase(status)) { return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(0, limit)).getContent(); }
|
if ("all".equalsIgnoreCase(status)) { return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size)).getContent(); }
|
||||||
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(0, limit)).getContent();
|
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(page, size)).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/byCountry/{status}/{code}/csv", produces = "text/csv")
|
@GetMapping(value = "/byCountry/{status}/{code}/csv", produces = "text/csv")
|
||||||
|
@ -278,7 +280,7 @@ public class OrganizationController extends AbstractDnetController {
|
||||||
@PathVariable final String code,
|
@PathVariable final String code,
|
||||||
final HttpServletResponse res,
|
final HttpServletResponse res,
|
||||||
final Authentication authentication) throws IOException {
|
final Authentication authentication) throws IOException {
|
||||||
final Iterable<OrganizationSimpleView> list = findOrgsByStatusAndCountry(status, code, Integer.MAX_VALUE, authentication);
|
final Iterable<OrganizationSimpleView> list = findOrgsByStatusAndCountry(status, code, 0, Integer.MAX_VALUE, authentication);
|
||||||
CSVConverter.writeCSV(res
|
CSVConverter.writeCSV(res
|
||||||
.getOutputStream(), list, OrganizationSimpleView.class, "id", "name", "type", "city", "country", "acronyms", "urls", "status", "nSimilarDups", "nSuggestedDups", "nDifferentDups");
|
.getOutputStream(), list, OrganizationSimpleView.class, "id", "name", "type", "city", "country", "acronyms", "urls", "status", "nSimilarDups", "nSuggestedDups", "nDifferentDups");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue