Refine search
/** * Turns the current template into a {@link Link} by expanding it using the given parameters. * * @param arguments * @return */ public Link expand(Object... arguments) { return new Link(getUriTemplate().expand(arguments).toString(), getRel()); }
@Override public StepExecutionProgressInfoResource stepExecutionProgress(long jobExecutionId, long stepExecutionId) { return restTemplate.getForObject(stepExecutionProgressLink.expand(jobExecutionId, stepExecutionId).getHref(), StepExecutionProgressInfoResource.class); }
@Override public ScheduleInfoResource getSchedule(String scheduleName) { return restTemplate.getForObject(schedulesLink.getHref() + "/" + scheduleName, ScheduleInfoResource.class); } }
@Override public Collection<Deployer> listPlatforms() { ParameterizedTypeReference<Collection<Deployer>> typeReference = new ParameterizedTypeReference<Collection<Deployer>>() { }; Map<String, Object> parameters = new HashMap<>(); String url = url = deploymentsLink.getHref() + "/platform/list"; return this.restTemplate.exchange(url, HttpMethod.GET, null, typeReference, parameters).getBody(); }
@Override public TaskDefinitionResource create(String name, String definition) { MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>(); values.add("name", name); values.add("definition", definition); TaskDefinitionResource task = restTemplate.postForObject(definitionsLink.expand().getHref(), values, TaskDefinitionResource.class); return task; }
@Override public AppRegistrationResource register(String name, ApplicationType type, String version, String uri, String metadataUri, boolean force) { MultiValueMap<String, Object> values = new LinkedMultiValueMap<>(); values.add("uri", uri); if (metadataUri != null) { values.add("metadata-uri", metadataUri); } values.add("force", Boolean.toString(force)); return restTemplate.postForObject(appsLink.getHref() + "/{type}/{name}/{version}", values, AppRegistrationResource.class, type, name, version); }
/** * 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, "by-location", pageable).getHref()); return "index"; } }
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) { this.restTemplate = restTemplate; this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref()); this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref()); }
@Override public Link linkToSingleResource(Class<?> type, Object id) { Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!"); ResourceMetadata metadata = mappings.getMetadataFor(type); String mappedId = idConverters.getPluginFor(type)// .orElse(DefaultIdConverter.INSTANCE)// .toRequestId((Serializable) id, type); Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel()); return new Link(new UriTemplate(link.getHref(), getProjectionVariable(type)).toString(), metadata.getItemResourceRel()); }
public RegistrationsResource() { add(linkTo(UserRegistrationRestController.class).withSelfRel()); Link searchLink = linkTo(UserRegistrationRestController.class).slash(RestApiConstants.SEARCH_RESOURCE) .withRel(RestApiConstants.SEARCH_RESOURCE); add(new Link(new UriTemplate(searchLink.getHref()) .with(RestApiConstants.TOKEN_PARAM, TemplateVariable.VariableType.REQUEST_PARAM), searchLink.getRel())); } }
/** * Turn a {@list List} of {@link Link}s into a {@link Map}, where you can see ALL the rels of a given * link. * * @param links * @return a map with links mapping onto a {@link List} of rels */ private static Map<String, LinkAndRels> urlRelMap(List<Link> links) { Map<String, LinkAndRels> urlRelMap = new LinkedHashMap<>(); links.forEach(link -> { LinkAndRels linkAndRels = urlRelMap.computeIfAbsent(link.getHref(), s -> new LinkAndRels()); linkAndRels.setLink(link); linkAndRels.getRels().add(link.getRel()); }); return urlRelMap; }
private UriStringAndHeaders getAndFindLinkWithRel(String uri, Iterator<Hop> rels, HttpHeaders extraHeaders) { if (!rels.hasNext()) { return new UriStringAndHeaders(uri, extraHeaders); } HttpEntity<?> request = prepareRequest(mergeHeaders(this.headers, extraHeaders)); UriTemplate template = new UriTemplate(uri); ResponseEntity<String> responseEntity = operations.exchange(template.expand(), GET, request, String.class); MediaType contentType = responseEntity.getHeaders().getContentType(); String responseBody = responseEntity.getBody(); Hop thisHop = rels.next(); Rel rel = Rels.getRelFor(thisHop.getRel(), discoverers); Link link = rel.findInResponse(responseBody, contentType); if (link == null) { throw new IllegalStateException( String.format("Expected to find link with rel '%s' in response %s!", rel, responseBody)); } /* * Don't expand if the parameters are empty */ if (!thisHop.hasParameters()) { return getAndFindLinkWithRel(link.getHref(), rels, thisHop.getHeaders()); } else { return getAndFindLinkWithRel(link.expand(thisHop.getMergedParameters(this.templateParameters)).getHref(), rels, thisHop.getHeaders()); } }
/** * Sets the location header pointing to the resource representing the given instance. Will make sure we properly * expand the URI template potentially created as self link. * * @param headers must not be {@literal null}. * @param assembler must not be {@literal null}. * @param source must not be {@literal null}. */ private void addLocationHeader(HttpHeaders headers, PersistentEntityResourceAssembler assembler, Object source) { String selfLink = assembler.getSelfLinkFor(source).getHref(); headers.setLocation(new UriTemplate(selfLink).expand()); }
// In a page constructor add(new Link("link") { public void onClick() { setVisible(false); } });
@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE) public RootResource info() { String streamTemplated = entityLinks.linkToCollectionResource(StreamMetrics.class).getHref() + "?{name}"; RootResource rootResource = new RootResource(); rootResource.add(new Link(streamTemplated).withRel("/collector/metrics/streams")); return rootResource; } }