Search in sources :

Example 1 with ValidationCheckResource

use of net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorController method validationChecks.

@GetMapping(path = "/{id}/validation-checks")
public ResponseEntity<ApiResponse<Stream<ValidationCheckResource>>> validationChecks(@PathVariable long id, @RequestParam(name = "startFrom", defaultValue = "0") int startFrom, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize, @RequestParam(name = "search", required = false) String searchString, @RequestParam(name = "sortBy", defaultValue = "location") String sortBy, @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection, Locale locale) {
    final SearchTerm searchTerm = StringUtils.isNotBlank(searchString) ? new SearchTerm(searchString) : null;
    final Sorting sorting = Sorting.parse(sortBy, sortDirection);
    final Paging paging = Paging.of(startFrom, pageSize);
    int totalCount = validationRunRepository.countValidationChecksForValidationRun(id, searchTerm);
    Stream<ValidationCheckResource> checks = validationRunRepository.findValidationChecksForValidationRun(id, paging, searchTerm, sorting).map(check -> ValidationCheckResource.of(check, messageSource.getMessage(check, locale)));
    Links links = Paging.links(startFrom, pageSize, totalCount, (sf, ps) -> methodOn(TrustAnchorController.class).validationChecks(id, sf, ps, searchString, sortBy, sortDirection, locale));
    return ResponseEntity.ok(ApiResponse.<Stream<ValidationCheckResource>>builder().links(links).data(checks).metadata(Metadata.of(totalCount)).build());
}
Also used : Paging(net.ripe.rpki.validator3.api.Paging) Links(org.springframework.hateoas.Links) ValidationCheckResource(net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource) SearchTerm(net.ripe.rpki.validator3.api.SearchTerm) Sorting(net.ripe.rpki.validator3.api.Sorting) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Paging (net.ripe.rpki.validator3.api.Paging)1 SearchTerm (net.ripe.rpki.validator3.api.SearchTerm)1 Sorting (net.ripe.rpki.validator3.api.Sorting)1 ValidationCheckResource (net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource)1 Links (org.springframework.hateoas.Links)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1