Search in sources :

Example 36 with UriComponentsBuilder

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Link(org.springframework.hateoas.Link)

Example 37 with UriComponentsBuilder

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;
}
Also used : WorkbasketSummaryResource(pro.taskana.rest.resource.WorkbasketSummaryResource) PagedResources(org.springframework.hateoas.PagedResources) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Link(org.springframework.hateoas.Link)

Example 38 with UriComponentsBuilder

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);
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 39 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 40 with UriComponentsBuilder

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");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)162 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)24 HttpEntity (org.springframework.http.HttpEntity)18 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)13 URI (java.net.URI)10 Test (org.junit.jupiter.api.Test)9 HttpHeaders (org.springframework.http.HttpHeaders)9 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)9 ArrayList (java.util.ArrayList)8 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 List (java.util.List)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5