Search in sources :

Example 6 with Metadata

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

the class ValidatedRoasController method list.

@GetMapping
public ResponseEntity<ApiResponse<Stream<RoaPrefix>>> list(@RequestParam(name = "startFrom", defaultValue = "0") int startFrom, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize, @RequestParam(name = "search", defaultValue = "", required = false) String searchString, @RequestParam(name = "sortBy", defaultValue = "prefix") String sortBy, @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection) {
    final SearchTerm searchTerm = StringUtils.isNotBlank(searchString) ? new SearchTerm(searchString) : null;
    final Sorting sorting = Sorting.parse(sortBy, sortDirection);
    final Paging paging = Paging.of(startFrom, pageSize);
    ValidatedRpkiObjects.ValidatedObjects<ValidatedRpkiObjects.RoaPrefix> currentlyValidatedRoaPrefixes = validatedRpkiObjects.findCurrentlyValidatedRoaPrefixes(searchTerm, sorting, paging);
    final Stream<RoaPrefix> roas = currentlyValidatedRoaPrefixes.getObjects().map(prefix -> new RoaPrefix(prefix.getAsn().toString(), prefix.getPrefix().toString(), prefix.getEffectiveLength(), prefix.getTrustAnchor().getName(), prefix.getLocations().first()));
    int totalSize = currentlyValidatedRoaPrefixes.getTotalCount();
    final Links links = Paging.links(startFrom, pageSize, totalSize, (sf, ps) -> methodOn(ValidatedRoasController.class).list(sf, ps, searchString, sortBy, sortDirection));
    return ResponseEntity.ok(ApiResponse.<Stream<RoaPrefix>>builder().links(links).metadata(Metadata.of(totalSize)).data(roas).build());
}
Also used : ValidatedRpkiObjects(net.ripe.rpki.validator3.domain.ValidatedRpkiObjects) Paging(net.ripe.rpki.validator3.api.Paging) Links(org.springframework.hateoas.Links) 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)6 SearchTerm (net.ripe.rpki.validator3.api.SearchTerm)6 Sorting (net.ripe.rpki.validator3.api.Sorting)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 Links (org.springframework.hateoas.Links)5 Stream (java.util.stream.Stream)2 URI (java.net.URI)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Valid (javax.validation.Valid)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Api (net.ripe.rpki.validator3.api.Api)1 ApiCommand (net.ripe.rpki.validator3.api.ApiCommand)1 ApiError (net.ripe.rpki.validator3.api.ApiError)1 ApiResponse (net.ripe.rpki.validator3.api.ApiResponse)1 Metadata (net.ripe.rpki.validator3.api.Metadata)1 ValidationCheckResource (net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource)1 IgnoreFilters (net.ripe.rpki.validator3.domain.IgnoreFilters)1 RoaPrefixAssertion (net.ripe.rpki.validator3.domain.RoaPrefixAssertion)1 RpkiRepository (net.ripe.rpki.validator3.domain.RpkiRepository)1