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


Java Resources.add方法代码示例

本文整理汇总了Java中org.springframework.hateoas.Resources.add方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.add方法的具体用法?Java Resources.add怎么用?Java Resources.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.hateoas.Resources的用法示例。


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

示例1: getAllEntities

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public HttpEntity<? extends Resources<? extends Type>> getAllEntities(Principal principal) {

    SLUser currentUser = principal == null ? null : slUserService.findById(principal.getName()).orElse(null);

    List<Type> all = entityService.findAll();
    List<Type> resourcesList = new ArrayList<>();

    for (Type entity : all) {
        try {
            requestHandler.handleRead(entity, currentUser);
            resourcesList.add(resourceProcessor.process(entity, currentUser));
        } catch (Exception e) {
            LOGGER.debug(String.format("Filtered %s with id '%s'", entity.getClass().getTypeName(),
                    entity.getEntityId().toString()));
        }
    }

    Resources<? extends Type> entityResources = new Resources<>(resourcesList);

    if (!all.isEmpty()) {
        entityResources.add(entityLinks.linkToCollectionResource(all.get(0).getClass()));
    }

    return new HttpEntity<>(entityResources);
}
 
开发者ID:Yannic92,项目名称:shoppingList,代码行数:27,代码来源:RestEntityController.java

示例2: findDistinct

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
/**
 * {@code GET /distinct}
 * Fetches the distinct values of the model attribute, {@code field}, which fulfill the given 
 *   query parameters.
 * 
 * @param field Name of the model attribute to retrieve unique values of.
 * @param request {@link HttpServletRequest}
 * @return
 */
@RequestMapping(value = "/distinct", method = RequestMethod.GET,
		produces = { ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE,
				ApiMediaTypes.APPLICATION_HAL_XML_VALUE, MediaType.APPLICATION_XML_VALUE,
				MediaType.TEXT_PLAIN_VALUE })
public HttpEntity<?> findDistinct(
		@RequestParam String field, 
		HttpServletRequest request)
{
	List<QueryCriteria> queryCriterias = RequestUtils.getQueryCriteriaFromRequest(model, request);
	List<Object> distinct = (List<Object>) repository.distinct(field, queryCriterias);
	ResponseEnvelope envelope = null;
	if (ApiMediaTypes.isHalMediaType(request.getHeader("Accept"))){
		Link selfLink = new Link(linkTo(this.getClass()).slash("distinct").toString() + 
				(request.getQueryString() != null ? "?" + request.getQueryString() : ""), "self");
		Resources resources = new Resources(distinct);
		resources.add(selfLink);
		envelope = new ResponseEnvelope(resources);
	} else {
		envelope = new ResponseEnvelope(distinct);
	}
	return new ResponseEntity<>(envelope, HttpStatus.OK);
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:32,代码来源:AbstractApiController.java

示例3: testResources

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@Test
public void testResources() {
    List<Address> addresses = new ArrayList<Address>();
    for (int i = 0; i < 4; i++) {
        addresses.add(new Address());
    }

    Resources<Address> addressResources = new Resources<Address>(addresses);
    addressResources.add(new Link("http://example.com/addresses", "self"));
    SirenEntity entity = new SirenEntity();
    sirenUtils.toSirenEntity(entity, addressResources);

    String json = objectMapper.valueToTree(entity)
            .toString();
    with(json).assertThat("$.entities", hasSize(4));
    with(json).assertThat("$.entities[0].properties.city.postalCode", equalTo("74199"));
    with(json).assertThat("$.entities[3].properties.city.name", equalTo("Donnbronn"));
    with(json).assertThat("$.links", hasSize(1));
}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:20,代码来源:SirenUtilsTest.java

示例4: resourcesToUberNode

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@Test
public void resourcesToUberNode() throws Exception {
    List<Bean> beans = Arrays.asList(new Bean(), new Bean("fooValue2", "barValue2"));
    Resources<Bean> beanResources = new Resources<Bean>(beans);
    beanResources.add(LINK_HOME);

    UberNode node = new UberNode();
    UberUtils.toUberData(node, beanResources);

    System.out.println(new ObjectMapper().writeValueAsString(node));
    assertEquals(3, node.getData()
            .size());
    Iterator<UberNode> dataNodes = node.iterator();
    UberNode first = dataNodes.next();
    assertEquals(BAR_VALUE, first.getFirstByName("bar")
            .getValue());
    assertEquals(FOO_VALUE, first.getFirstByName("foo")
            .getValue());
    UberNode second = dataNodes.next();
    assertEquals("barValue2", second.getFirstByName("bar")
            .getValue());
    assertEquals("fooValue2", second.getFirstByName("foo")
            .getValue());
    assertEquals(URL_HOME, node.getFirstByRel("home")
            .getUrl());
}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:27,代码来源:UberUtilsTest.java

示例5: findEvents

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Resources<Event>> findEvents(@RequestParam(required = false) String name) {
    List<Event> events = assembler.toResources(eventBackend.getEvents());
    List<Event> matches = new ArrayList<Event>();
    for (Event event : events) {
        if (name == null || event.workPerformed.getContent().name.equals(name)) {
            addAffordances(event);
            matches.add(event);
        }
    }
    Resources<Event> eventResources = new Resources<Event>(matches);

    eventResources.add(AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(EventController.class)
            .addEvent(new Event(null, new CreativeWork(null), null, EventStatusType.EVENT_SCHEDULED)))
            .withSelfRel());

    eventResources.add(AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(EventController.class)
            .findEvents(null))
            .withRel("hydra:search"));

    return new ResponseEntity<Resources<Event>>(eventResources, HttpStatus.OK);
}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:24,代码来源:EventController.java

示例6: getReviews

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Resources<Review>> getReviews(@PathVariable int eventId) {
    List<Review> reviews = eventBackend.getReviews()
            .get(eventId);

    ResponseEntity<Resources<Review>> ret;
    if (reviews != null) {
        final Resources<Review> reviewResources = new Resources<Review>(reviews);

        reviewResources.add(AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(EventController.class)
                .getEvent(eventId)) // passing null requires that method takes Integer, not int
                .withRel("hydra:search"));
        reviewResources.add(AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass())
                .addReview
                        (eventId, null))
                .withSelfRel());
        ret = new ResponseEntity<Resources<Review>>(reviewResources, HttpStatus.OK);
    } else {
        ret = new ResponseEntity<Resources<Review>>(HttpStatus.NOT_FOUND);
    }
    return ret;
}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:24,代码来源:ReviewController.java

示例7: getAllStates

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
private Resources<StatesResource> getAllStates(Collection<StatesResource> statesResources, UUID provider) throws StateDefinitionNotFoundException, ProviderNotFoundException, AttributeDefinitionNotFoundException {
	if (LOG.isTraceEnabled()) {
		LOG.entry(statesResources);
	}
	
	for (StatesResource resource : statesResources) {
		resource.add(entityLinks.linkToSingleResource(StatesResource.class, resource.getStateDefinition().getUUID()).withSelfRel());
		resource.add(linkTo(methodOn(StateDefinitionsController.class).getStateDefinition(resource.getStateDefinition().getUUID())).withRel(relProvider.getItemResourceRelFor(StateDefinitionResource.class)));
	}
	
	final Resources<StatesResource> resources = new Resources<>(statesResources);
	if (provider == null) {
		resources.add(entityLinks.linkToCollectionResource(StatesResource.class));
	} else {
		resources.add(linkTo(methodOn(StatesController.class).getAllStates(provider)).withSelfRel());
	}
	
	if (LOG.isTraceEnabled()) {
		LOG.exit(resources);	
	}
	return resources;
}
 
开发者ID:kmbulebu,项目名称:NickNack,代码行数:23,代码来源:StatesController.java

示例8: getEventDefinitions

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
private Resources<EventDefinitionResource> getEventDefinitions(Collection<EventDefinition> eventDefinitions) throws EventDefinitionNotFoundException, ProviderNotFoundException, AttributeDefinitionNotFoundException {
	if (LOG.isTraceEnabled()) {
		LOG.entry(eventDefinitions);
	}

	final List<EventDefinitionResource> eventDefinitionResources = new ArrayList<EventDefinitionResource>(eventDefinitions.size());
	
	for (EventDefinition eventDefinition : eventDefinitions) {
		final EventDefinitionResource resource = new EventDefinitionResource(eventDefinition);
		resource.add(linkTo(methodOn(EventDefinitionsController.class).getEventDefinition(eventDefinition.getUUID())).withSelfRel());
		resource.add(linkTo(methodOn(EventDefinitionsController.class).getAttributeDefinitions(eventDefinition.getUUID())).withRel("attributeDefinitions"));
		eventDefinitionResources.add(resource);
	}
	
	final Resources<EventDefinitionResource> resources = new Resources<EventDefinitionResource>(eventDefinitionResources);
	resources.add(entityLinks.linkToCollectionResource(EventDefinitionResource.class));
	
	
	if (LOG.isTraceEnabled()) {
		LOG.exit(resources);	
	}
	return resources;
}
 
开发者ID:kmbulebu,项目名称:NickNack,代码行数:24,代码来源:EventDefinitionsController.java

示例9: getAttributeDefinitions

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@RequestMapping(value="/{eventUuid}/attributeDefinitions", method={RequestMethod.GET, RequestMethod.HEAD})
public Resources<AttributeDefinitionResource> getAttributeDefinitions(@PathVariable UUID eventUuid) throws EventDefinitionNotFoundException, ProviderNotFoundException, AttributeDefinitionNotFoundException {
	if (LOG.isTraceEnabled()) {
		LOG.entry(eventUuid);
	}
	
	final List<AttributeDefinition> attributeDefinitions = eventDefinitionService.getAttributeDefinitions(eventUuid);
	final List<AttributeDefinitionResource> attributeDefinitionResources = new ArrayList<AttributeDefinitionResource>(attributeDefinitions.size());
	
	
	for (AttributeDefinition attributeDefinition : attributeDefinitions) {
		final AttributeDefinitionResource resource = new AttributeDefinitionResource(attributeDefinition);
		resource.add(linkTo(methodOn(EventDefinitionsController.class).getAttributeDefinition(eventUuid, attributeDefinition.getUUID())).withSelfRel());

		attributeDefinitionResources.add(resource);
	}
	
	final Resources<AttributeDefinitionResource> resources = new Resources<AttributeDefinitionResource>(attributeDefinitionResources);
	resources.add(linkTo(methodOn(EventDefinitionsController.class).getAttributeDefinitions(eventUuid)).withSelfRel());

	if (LOG.isTraceEnabled()) {
		LOG.exit(resources);	
	}
	return resources;
}
 
开发者ID:kmbulebu,项目名称:NickNack,代码行数:26,代码来源:EventDefinitionsController.java

示例10: getStateDefinitions

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
private Resources<StateDefinitionResource> getStateDefinitions(Collection<StateDefinition> stateDefinitions) throws StateDefinitionNotFoundException, ProviderNotFoundException, AttributeDefinitionNotFoundException {
	if (LOG.isTraceEnabled()) {
		LOG.entry(stateDefinitions);
	}

	final List<StateDefinitionResource> stateDefinitionResources = new ArrayList<StateDefinitionResource>(stateDefinitions.size());
	
	for (StateDefinition stateDefinition : stateDefinitions) {
		final StateDefinitionResource resource = new StateDefinitionResource(stateDefinition);
		resource.add(linkTo(methodOn(StateDefinitionsController.class).getStateDefinition(stateDefinition.getUUID())).withSelfRel());
		resource.add(linkTo(methodOn(StateDefinitionsController.class).getAttributeDefinitions(stateDefinition.getUUID())).withRel("attributeDefinitions"));
		stateDefinitionResources.add(resource);
	}
	
	final Resources<StateDefinitionResource> resources = new Resources<StateDefinitionResource>(stateDefinitionResources);
	resources.add(entityLinks.linkToCollectionResource(StateDefinitionResource.class));
	
	
	if (LOG.isTraceEnabled()) {
		LOG.exit(resources);	
	}
	return resources;
}
 
开发者ID:kmbulebu,项目名称:NickNack,代码行数:24,代码来源:StateDefinitionsController.java

示例11: getAttributeDefinitions

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
@RequestMapping(value="/{stateUuid}/attributeDefinitions", method={RequestMethod.GET, RequestMethod.HEAD})
public Resources<AttributeDefinitionResource> getAttributeDefinitions(@PathVariable UUID stateUuid) throws StateDefinitionNotFoundException, ProviderNotFoundException, AttributeDefinitionNotFoundException {
	if (LOG.isTraceEnabled()) {
		LOG.entry(stateUuid);
	}
	
	final List<AttributeDefinition> attributeDefinitions = stateDefinitionService.getAttributeDefinitions(stateUuid);
	final List<AttributeDefinitionResource> attributeDefinitionResources = new ArrayList<AttributeDefinitionResource>(attributeDefinitions.size());
	
	
	for (AttributeDefinition attributeDefinition : attributeDefinitions) {
		final AttributeDefinitionResource resource = new AttributeDefinitionResource(attributeDefinition);
		resource.add(linkTo(methodOn(StateDefinitionsController.class).getAttributeDefinition(stateUuid, attributeDefinition.getUUID())).withSelfRel());

		attributeDefinitionResources.add(resource);
	}
	
	final Resources<AttributeDefinitionResource> resources = new Resources<AttributeDefinitionResource>(attributeDefinitionResources);
	resources.add(linkTo(methodOn(StateDefinitionsController.class).getAttributeDefinitions(stateUuid)).withSelfRel());

	if (LOG.isTraceEnabled()) {
		LOG.exit(resources);	
	}
	return resources;
}
 
开发者ID:kmbulebu,项目名称:NickNack,代码行数:26,代码来源:StateDefinitionsController.java

示例12: addLinks

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
/**
 * Retain default links for the entire collection, but add extra custom links for the {@link Manager} collection.
 *
 * @param resources
 */
@Override
protected void addLinks(Resources<Resource<Manager>> resources) {

	super.addLinks(resources);

	resources.add(linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees"));
	resources.add(linkTo(methodOn(EmployeeController.class).findAllDetailedEmployees()).withRel("detailedEmployees"));
	resources.add(linkTo(methodOn(RootController.class).root()).withRel("root"));
}
 
开发者ID:spring-projects,项目名称:spring-hateoas-examples,代码行数:15,代码来源:ManagerResourceAssembler.java

示例13: addLinks

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
/**
 * Define links to add to {@link Resources} collection.
 *
 * @param resources
 */
@Override
protected void addLinks(Resources<Resource<Employee>> resources) {
	
	super.addLinks(resources);

	resources.add(linkTo(methodOn(EmployeeController.class).findAllDetailedEmployees()).withRel("detailedEmployees"));
	resources.add(linkTo(methodOn(ManagerController.class).findAll()).withRel("managers"));
	resources.add(linkTo(methodOn(RootController.class).root()).withRel("root"));
}
 
开发者ID:spring-projects,项目名称:spring-hateoas-examples,代码行数:15,代码来源:EmployeeResourceAssembler.java

示例14: addLinks

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
/**
 * Define links to add to the {@link Resources} collection.
 *
 * @param resources
 */
@Override
protected void addLinks(Resources<Resource<EmployeeWithManager>> resources) {

	resources.add(linkTo(methodOn(EmployeeController.class).findAllDetailedEmployees()).withSelfRel());
	resources.add(linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees"));
	resources.add(linkTo(methodOn(ManagerController.class).findAll()).withRel("managers"));
	resources.add(linkTo(methodOn(RootController.class).root()).withRel("root"));
}
 
开发者ID:spring-projects,项目名称:spring-hateoas-examples,代码行数:14,代码来源:EmployeeWithManagerResourceAssembler.java

示例15: showOrdersInProgress

import org.springframework.hateoas.Resources; //导入方法依赖的package包/类
/**
 * Exposes all {@link Order}s currently in preparation.
 * 
 * @return
 */
@RequestMapping("/engine")
HttpEntity<Resources<Resource<Order>>> showOrdersInProgress() {

	Resources<Resource<Order>> orderResources = Resources.wrap(processor.getOrders());
	orderResources.add(linkTo(methodOn(EngineController.class).showOrdersInProgress()).withSelfRel());

	return new ResponseEntity<>(orderResources, HttpStatus.OK);
}
 
开发者ID:idugalic,项目名称:micro-ecommerce,代码行数:14,代码来源:EngineController.java


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