org.springframework.hateoas.LinkRelation Java Examples

The following examples show how to use org.springframework.hateoas.LinkRelation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataflowTemplateTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private DataFlowTemplate getMockedDataFlowTemplate(boolean isLinksActive) throws Exception{
	RestTemplate restTemplate = mock(RestTemplate.class);
	RootResource rootResource = mock(RootResource.class);
	Link link = mock(Link.class);
	when(link.getHref()).thenReturn("https://whereever");
	when(rootResource.getApiRevision()).thenReturn(Version.REVISION);
	when(rootResource.getLink(any(LinkRelation.class))).thenReturn(Optional.of(link));
	when(rootResource.hasLink(any(LinkRelation.class))).thenReturn(isLinksActive);
	when(rootResource.getLink(anyString())).thenReturn(Optional.of(link));
	when(rootResource.hasLink(anyString())).thenReturn(isLinksActive);
	when(restTemplate.getForObject(any(),any())).thenReturn(rootResource);
	List<HttpMessageConverter<?>> converters = new ArrayList<>();
	converters.add(new MappingJackson2HttpMessageConverter());
	when(restTemplate.getMessageConverters()).thenReturn(converters);
	URI uri = new URI("foo");
	return new DataFlowTemplate(uri, restTemplate);
}
 
Example #2
Source File: StoresController.java    From spring-data-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Looks up the stores in the given distance around the given location.
 *
 * @param model the {@link Model} to populate.
 * @param location the optional location, if none is given, no search results will be returned.
 * @param distance the distance to use, if none is given the {@link #DEFAULT_DISTANCE} is used.
 * @param pageable the pagination information
 * @return
 */
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, @RequestParam Optional<Point> location, @RequestParam Optional<Distance> distance,
		Pageable pageable) {

	Point point = location.orElse(KNOWN_LOCATIONS.get("Timesquare NY"));

	Page<Store> stores = repository.findByAddressLocationNear(point, distance.orElse(DEFAULT_DISTANCE), pageable);

	model.addAttribute("stores", stores);
	model.addAttribute("distances", DISTANCES);
	model.addAttribute("selectedDistance", distance.orElse(DEFAULT_DISTANCE));
	model.addAttribute("location", point);
	model.addAttribute("locations", KNOWN_LOCATIONS);
	model.addAttribute("api",
			entityLinks.linkToSearchResource(Store.class, LinkRelation.of("by-location"), pageable).getHref());

	return "index";
}
 
Example #3
Source File: OrderProcessor.java    From spring-hateoas-examples with Apache License 2.0 5 votes vote down vote up
@Override
public EntityModel<Order> process(EntityModel<Order> model) {

	CustomOrderController controller = methodOn(CustomOrderController.class);
	String basePath = configuration.getBasePath().toString();

	// If PAID_FOR is valid, add a link to the `pay()` method
	if (valid(model.getContent().getOrderStatus(), OrderStatus.PAID_FOR)) {
		model.add(applyBasePath( //
				linkTo(controller.pay(model.getContent().getId())) //
						.withRel(IanaLinkRelations.PAYMENT), //
				basePath));
	}

	// If CANCELLED is valid, add a link to the `cancel()` method
	if (valid(model.getContent().getOrderStatus(), OrderStatus.CANCELLED)) {
		model.add(applyBasePath( //
				linkTo(controller.cancel(model.getContent().getId())) //
						.withRel(LinkRelation.of("cancel")), //
				basePath));
	}

	// If FULFILLED is valid, add a link to the `fulfill()` method
	if (valid(model.getContent().getOrderStatus(), OrderStatus.FULFILLED)) {
		model.add(applyBasePath( //
				linkTo(controller.fulfill(model.getContent().getId())) //
						.withRel(LinkRelation.of("fulfill")), //
				basePath));
	}

	return model;
}