use of org.springframework.hateoas.UriTemplate in project spring-data-commons by spring-projects.
the class PagedResourcesAssembler method createLink.
/**
* Creates a {@link Link} with the given rel that will be based on the given {@link UriTemplate} but enriched with the
* values of the given {@link Pageable} (if not {@literal null}).
*
* @param base must not be {@literal null}.
* @param pageable can be {@literal null}
* @param rel must not be {@literal null} or empty.
* @return
*/
private Link createLink(UriTemplate base, Pageable pageable, String rel) {
UriComponentsBuilder builder = fromUri(base.expand());
pageableResolver.enhance(builder, getMethodParameter(), pageable);
return new Link(new UriTemplate(builder.build().toString()), rel);
}
use of org.springframework.hateoas.UriTemplate in project spring-data-commons by spring-projects.
the class PagedResourcesAssembler method addPaginationLinks.
private <R> PagedResources<R> addPaginationLinks(PagedResources<R> resources, Page<?> page, Optional<Link> link) {
UriTemplate base = getUriTemplate(link);
boolean isNavigable = page.hasPrevious() || page.hasNext();
if (isNavigable || forceFirstAndLastRels) {
resources.add(createLink(base, PageRequest.of(0, page.getSize(), page.getSort()), Link.REL_FIRST));
}
if (page.hasPrevious()) {
resources.add(createLink(base, page.previousPageable(), Link.REL_PREVIOUS));
}
Link selfLink = //
link.map(it -> it.withSelfRel()).orElseGet(() -> createLink(base, page.getPageable(), Link.REL_SELF));
resources.add(selfLink);
if (page.hasNext()) {
resources.add(createLink(base, page.nextPageable(), Link.REL_NEXT));
}
if (isNavigable || forceFirstAndLastRels) {
int lastIndex = page.getTotalPages() == 0 ? 0 : page.getTotalPages() - 1;
resources.add(createLink(base, PageRequest.of(lastIndex, page.getSize(), page.getSort()), Link.REL_LAST));
}
return resources;
}
use of org.springframework.hateoas.UriTemplate in project sw360portal by sw360.
the class AttachmentController method process.
@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
final ControllerLinkBuilder controllerLinkBuilder = linkTo(AttachmentController.class);
final Link attachments = new Link(new UriTemplate(controllerLinkBuilder.toUri().toString() + "/api/attachments{?sha1}"), "attachments");
resource.add(attachments);
return resource;
}
Aggregations