use of org.springframework.web.util.UriComponentsBuilder in project taskana by Taskana.
the class AbstractRessourcesAssembler method addPageLinks.
protected PagedResources<?> addPageLinks(PagedResources<?> pagedResources, PageMetadata pageMetadata) {
UriComponentsBuilder original = getBuilderForOriginalUri();
pagedResources.add(new Link(original.replaceQueryParam("page", 1).toUriString()).withRel(Link.REL_FIRST));
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getTotalPages()).toUriString()).withRel(Link.REL_LAST));
if (pageMetadata.getNumber() > 1) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() - 1).toUriString()).withRel(Link.REL_PREVIOUS));
}
if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() + 1).toUriString()).withRel(Link.REL_NEXT));
}
return pagedResources;
}
use of org.springframework.web.util.UriComponentsBuilder in project taskana by Taskana.
the class WorkbasketSummaryResourcesAssembler method toResources.
public PagedResources<WorkbasketSummaryResource> toResources(List<WorkbasketSummary> workbasketSummaries, PageMetadata pageMetadata) {
WorkbasketSummaryResourceAssembler assembler = new WorkbasketSummaryResourceAssembler();
List<WorkbasketSummaryResource> resources = assembler.toResources(workbasketSummaries);
PagedResources<WorkbasketSummaryResource> pagedResources = new PagedResources<WorkbasketSummaryResource>(resources, pageMetadata);
UriComponentsBuilder original = getBuilderForOriginalUri();
pagedResources.add(new Link(original.toUriString()).withSelfRel());
if (pageMetadata != null) {
pagedResources.add(linkTo(WorkbasketController.class).withRel("allWorkbaskets"));
pagedResources.add(new Link(original.replaceQueryParam("page", 1).toUriString()).withRel(Link.REL_FIRST));
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getTotalPages()).toUriString()).withRel(Link.REL_LAST));
if (pageMetadata.getNumber() > 1) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() - 1).toUriString()).withRel(Link.REL_PREVIOUS));
}
if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() + 1).toUriString()).withRel(Link.REL_NEXT));
}
}
return pagedResources;
}
use of org.springframework.web.util.UriComponentsBuilder in project cf-java-client by cloudfoundry.
the class AbstractRootProvider method getRoot.
protected final UriComponents getRoot() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("https").host(getApiHost());
getPort().ifPresent(builder::port);
return normalize(builder);
}
use of org.springframework.web.util.UriComponentsBuilder in project cf-java-client by cloudfoundry.
the class QueryBuilderTest method test.
@Test
public void test() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
QueryBuilder.augment(builder, new StubQueryParamsSubClass());
MultiValueMap<String, String> queryParams = builder.build().encode().getQueryParams();
assertThat(queryParams).hasSize(5);
assertThat(queryParams.getFirst("test-single")).isEqualTo("test-value-1");
assertThat(queryParams.getFirst("test-collection")).isEqualTo("test-value-2,test-value-3");
assertThat(queryParams.getFirst("test-collection-custom-delimiter")).isEqualTo("test-value-4%20test-value-5");
assertThat(queryParams.getFirst("test-subclass")).isEqualTo("test-value-6");
assertThat(queryParams.getFirst("test-override")).isEqualTo("test-value-7");
}
use of org.springframework.web.util.UriComponentsBuilder in project cf-java-client by cloudfoundry.
the class FilterBuilderTest method test.
@Test
public void test() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
FilterBuilder.augment(builder, new StubFilterParamsSubClass());
MultiValueMap<String, String> queryParams = builder.build().encode().getQueryParams();
assertThat(queryParams).hasSize(4);
assertThat(queryParams.getFirst("test-single")).isEqualTo("test-value-1");
assertThat(queryParams.getFirst("test-collection")).isEqualTo("test-value-2,test-value-3");
assertThat(queryParams.getFirst("test-subclass")).isEqualTo("test-value-4");
assertThat(queryParams.getFirst("test-override")).isEqualTo("test-value-7");
}
Aggregations