当前位置: 首页>>代码示例>>Java>>正文


Java TypeReferences类代码示例

本文整理汇总了Java中org.springframework.hateoas.mvc.TypeReferences的典型用法代码示例。如果您正苦于以下问题:Java TypeReferences类的具体用法?Java TypeReferences怎么用?Java TypeReferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeReferences类属于org.springframework.hateoas.mvc包,在下文中一共展示了TypeReferences类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: traversCustomersIT

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomersIT() {
    //Travers customers
    try {
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers")
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(3);
        System.err.println(resources.getContent());
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }
}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:17,代码来源:CustomerRepositoryDataRestIT.java

示例2: traversCustomersResourceIT

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomersResourceIT() {
    //Travers customers
    try {
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers")
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(3);
        System.err.println(resources.getMetadata());
        for (Resource<Customer> resource : resources) {
            final List<Link> links = resource.getLinks();
            System.err.println(links);
            final Customer customer = resource.getContent();
            System.err.println(customer);
        }
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }
}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:23,代码来源:CustomerRepositoryDataRestIT.java

示例3: traversCustomerFindByFirstNameIT

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomerFindByFirstNameIT() {
    //travers to findByFirstName
    try {
        final Map<String, Object> parameters = new HashMap<>();
        parameters.put("firstName", "Donnie");
        final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
        final PagedResources<Resource<Customer>> resources = traverson
                .follow("customers", "search", "findByFirstName")
                .withTemplateParameters(parameters)
                .toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
                });
        assertThat(resources.getContent()).isNotNull();
        assertThat(resources.getContent().size()).isEqualTo(1);
        final List<Resource<Customer>> customers = new LinkedList<>(resources.getContent());
        final Customer customer = customers.get(0).getContent();
        assertThat(customer).isNotNull();
        assertThat(customer.getFirstName()).isEqualTo("Donnie");
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }

}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:24,代码来源:CustomerRepositoryDataRestIT.java

示例4: getResource

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Async
public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws
        InterruptedException, IOException {
    RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
    LOG.debug("Requesting: " + request.toString());
    Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
    LOG.debug("Received: " + body.toString());
    return new AsyncResult<>(body);
}
 
开发者ID:microservices-demo,项目名称:orders,代码行数:10,代码来源:AsyncGetService.java

示例5: getDataList

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Async
public <T> Future<Resources<T>> getDataList(URI url, TypeReferences.ResourcesType<T> type) throws
        InterruptedException, IOException {
    RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
    LOG.debug("Requesting: " + request.toString());
    Resources<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
    LOG.debug("Received: " + body.toString());
    return new AsyncResult<>(body);
}
 
开发者ID:microservices-demo,项目名称:orders,代码行数:10,代码来源:AsyncGetService.java

示例6: getRubricAssociationResource

import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
/**
 * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional.
 * @param toolId the tool id, something like "sakai.assignment"
 * @param associatedToolItemId the id of the associated element within the tool
 * @return
 */
protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId) throws Exception {

    TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference =
            new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {};

    URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX);
    Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON);

    Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search",
            "by-tool-item-ids");

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId)));
    builder.withHeaders(headers);

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("toolId", toolId);
    parameters.put("itemId", associatedToolItemId);

    Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(
            parameters).toObject(resourceParameterizedTypeReference);

    // Should only be one matching this search criterion
    if (associationResources.getContent().size() > 1) {
        throw new IllegalStateException(String.format(
                "Number of rubric association resources greater than one for request: %s",
                associationResources.getLink(Link.REL_SELF).toString()));
    }

    Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst();

    return associationResource;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:40,代码来源:RubricsServiceImpl.java


注:本文中的org.springframework.hateoas.mvc.TypeReferences类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。