Java Code Examples for org.springframework.hateoas.PagedModel.PageMetadata#getNumber()

The following examples show how to use org.springframework.hateoas.PagedModel.PageMetadata#getNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRessourcesAssembler.java    From taskana with Apache License 2.0 6 votes vote down vote up
protected PagedResources<?> addPageLinks(
    PagedResources<?> pagedResources, PageMetadata pageMetadata) {
  UriComponentsBuilder original = getBuilderForOriginalUri();
  pagedResources.add(
      (Link.of(original.replaceQueryParam("page", 1).toUriString())).withRel("first"));
  pagedResources.add(
      (Link.of(original.replaceQueryParam("page", pageMetadata.getTotalPages()).toUriString()))
          .withRel("last"));
  if (pageMetadata.getNumber() > 1L) {
    pagedResources.add(
        (Link.of(original.replaceQueryParam("page", pageMetadata.getNumber() - 1L).toUriString()))
            .withRel("prev"));
  }

  if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
    pagedResources.add(
        (Link.of(original.replaceQueryParam("page", pageMetadata.getNumber() + 1L).toUriString()))
            .withRel("next"));
  }

  return pagedResources;
}
 
Example 2
Source File: PageLinksAspect.java    From taskana with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Around("@annotation(pro.taskana.resource.rest.PageLinks) && args(data, page, ..)")
public <T extends RepresentationModel<? extends T> & ProceedingJoinPoint>
    RepresentationModel<T> addLinksToPageResource(
        ProceedingJoinPoint joinPoint, List<?> data, PageMetadata page) throws Throwable {
  HttpServletRequest request =
      ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
  PageLinks pageLinks = method.getAnnotation(PageLinks.class);
  String relativeUrl = pageLinks.value();
  UriComponentsBuilder original = originalUri(relativeUrl, request);
  RepresentationModel<T> resourceSupport = (RepresentationModel<T>) joinPoint.proceed();
  resourceSupport.add(Link.of(original.toUriString()).withSelfRel());
  if (page != null) {
    resourceSupport.add(
        Link.of(original.replaceQueryParam("page", 1).toUriString())
            .withRel(IanaLinkRelations.FIRST));
    resourceSupport.add(
        Link.of(original.replaceQueryParam("page", page.getTotalPages()).toUriString())
            .withRel(IanaLinkRelations.LAST));
    if (page.getNumber() > 1) {
      resourceSupport.add(
          Link.of(original.replaceQueryParam("page", page.getNumber() - 1).toUriString())
              .withRel(IanaLinkRelations.PREV));
    }
    if (page.getNumber() < page.getTotalPages()) {
      resourceSupport.add(
          Link.of(original.replaceQueryParam("page", page.getNumber() + 1).toUriString())
              .withRel(IanaLinkRelations.NEXT));
    }
  }
  return resourceSupport;
}
 
Example 3
Source File: TaskHistoryEventListResourceAssembler.java    From taskana with Apache License 2.0 4 votes vote down vote up
public TaskHistoryEventListResource toResources(
    List<HistoryEventImpl> historyEvents, PageMetadata pageMetadata) {

  TaskHistoryEventResourceAssembler assembler = new TaskHistoryEventResourceAssembler();
  List<TaskHistoryEventResource> resources =
      new ArrayList<>(assembler.toCollectionModel(historyEvents).getContent());
  TaskHistoryEventListResource pagedResources =
      new TaskHistoryEventListResource(resources, pageMetadata);

  pagedResources.add(Link.of(this.getOriginal().toUriString()).withSelfRel());
  if (pageMetadata != null) {
    pagedResources.add(linkTo(TaskHistoryEventController.class).withRel("allTaskHistoryEvent"));
    pagedResources.add(
        Link.of(this.getOriginal().replaceQueryParam("page", 1).toUriString())
            .withRel(IanaLinkRelations.FIRST));
    pagedResources.add(
        Link.of(
                this.getOriginal()
                    .replaceQueryParam("page", pageMetadata.getTotalPages())
                    .toUriString())
            .withRel(IanaLinkRelations.LAST));
    if (pageMetadata.getNumber() > 1) {
      pagedResources.add(
          Link.of(
                  this.getOriginal()
                      .replaceQueryParam("page", pageMetadata.getNumber() - 1)
                      .toUriString())
              .withRel(IanaLinkRelations.PREV));
    }
    if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
      pagedResources.add(
          Link.of(
                  this.getOriginal()
                      .replaceQueryParam("page", pageMetadata.getNumber() + 1)
                      .toUriString())
              .withRel(IanaLinkRelations.NEXT));
    }
  }

  return pagedResources;
}