Refine search
@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()); }
/** * 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()); }
/** * Creates a new {@link UriTemplate} with a {@link TemplateVariable} with the given name and type added. * * @param variableName must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return will never be {@literal null}. */ public UriTemplate with(String variableName, TemplateVariable.VariableType type) { return with(new TemplateVariables(new TemplateVariable(variableName, type))); }
private ObjectNode dependenciesLink(String appUrl) { String uri = (appUrl != null) ? appUrl + "/dependencies" : "/dependencies"; UriTemplate uriTemplate = new UriTemplate(uri, this.dependenciesVariables); ObjectNode result = nodeFactory().objectNode(); result.put("href", uriTemplate.toString()); result.put("templated", true); return result; }
/** * 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()); }
/** * Creates a new {@link DefaultCurieProvider} for the given curies using the one with the given name as default, which * means to expand unprefixed, non-IANA link relations. * * @param curies must not be {@literal null}. * @param defaultCurieName can be {@literal null}. * @since 0.19 */ public DefaultCurieProvider(Map<String, UriTemplate> curies, String defaultCurieName) { Assert.notNull(curies, "Curies must not be null!"); curies.forEach((name, template) -> { Assert.hasText(name, "Curie name must not be null or empty!"); Assert.notNull(template, "UriTemplate must not be null!"); Assert.isTrue(template.getVariableNames().size() == 1, String.format("Expected a single template variable in the UriTemplate %s!", template.toString())); }); this.defaultCurie = StringUtils.hasText(defaultCurieName) ? defaultCurieName : curies.size() == 1 ? curies.keySet().iterator().next() : null; this.curies = Collections.unmodifiableMap(curies); }
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) { this.restTemplate = restTemplate; this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref()); this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref()); }
/** * Returns the link to to the paged colelction resource for the given type, pre-expanding the * * @param type must not be {@literal null}. * @param pageable the pageable to can be {@literal null}. * @return */ public Link linkToPagedResource(Class<?> type, Pageable pageable) { ResourceMetadata metadata = mappings.getMetadataFor(type); String href = linkFor(type).toString(); UriComponents components = prepareUri(href, metadata, pageable); TemplateVariables variables = getTemplateVariables(components, metadata, pageable).// concat(getProjectionVariable(type)); return new Link(new UriTemplate(href, variables), metadata.getRel()); }
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()); } }
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())); } }
} else if (link.isTemplated()) { List<SirenField> fields = new ArrayList<SirenField>(); List<TemplateVariable> variables = link.getVariables(); boolean queryOnly = false; for (TemplateVariable variable : variables) { String baseUri = new UriTemplate(link.getHref()).expand() .toASCIIString(); SirenAction sirenAction = new SirenAction(null, null, null, "GET",
private URIAndHeaders traverseToExpandedFinalUrl() { UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), this.rels.iterator(), HttpHeaders.EMPTY); return new URIAndHeaders(new UriTemplate(uriAndHeaders.getUri()).expand(this.templateParameters), uriAndHeaders.getHttpHeaders()); }
/** * Creates a {@link Link} with the given rel that will be based on the given {@link UriTemplate} but enriched with the * values of the given {@link Pageable} (if not {@literal null}). * * @param base must not be {@literal null}. * @param pageable can be {@literal null} * @param rel must not be {@literal null} or empty. * @return */ private Link createLink(UriTemplate base, Pageable pageable, String rel) { UriComponentsBuilder builder = fromUri(base.expand()); pageableResolver.enhance(builder, getMethodParameter(), pageable); return new Link(new UriTemplate(builder.build().toString()), rel); }
private UriTemplate getUriTemplate() { if (template == null) { this.template = new UriTemplate(href); } return template; }
/** * Creates a new Link from the given {@link UriTemplate} and rel. * * @param template must not be {@literal null}. * @param rel must not be {@literal null} or empty. */ public Link(UriTemplate template, String rel) { Assert.notNull(template, "UriTemplate must not be null!"); Assert.hasText(rel, "Rel must not be null or empty!"); this.template = template; this.href = template.toString(); this.rel = rel; this.affordances = new ArrayList<>(); }
@Override public CompletionProposalsResource streamCompletions(String prefix, int levelOfDetail) { return restTemplate.getForObject(streamCompletionUriTemplate.expand(prefix, levelOfDetail), CompletionProposalsResource.class); }
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) { this.restTemplate = restTemplate; this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref()); this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref()); }
/** * Returns the links to render for the given {@link Association}. * * @param association must not be {@literal null}. * @param path must not be {@literal null}. * @return */ public List<Link> getLinksFor(Association<? extends PersistentProperty<?>> association, Path path) { Assert.notNull(association, "Association must not be null!"); Assert.notNull(path, "Base path must not be null!"); if (isLinkableAssociation(association)) { PersistentProperty<?> property = association.getInverse(); ResourceMetadata metadata = mappings.getMetadataFor(property.getOwner().getType()); ResourceMapping propertyMapping = metadata.getMappingFor(property); String href = path.slash(propertyMapping.getPath()).toString(); UriTemplate template = new UriTemplate(href, getProjectionVariable(property)); return Collections.singletonList(new Link(template, propertyMapping.getRel())); } return Collections.emptyList(); }
private String getAndFindLinkWithRel(String uri, Iterator<Hop> rels) { if (!rels.hasNext()) { return uri; } HttpEntity<?> request = prepareRequest(headers); 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); } else { return getAndFindLinkWithRel(link.expand(thisHop.getMergedParameters(templateParameters)).getHref(), rels); } } }
} else if (link.isTemplated()) { List<SirenField> fields = new ArrayList<SirenField>(); List<TemplateVariable> variables = link.getVariables(); boolean queryOnly = false; for (TemplateVariable variable : variables) { String baseUri = new UriTemplate(link.getHref()).expand() .toASCIIString(); SirenAction sirenAction = new SirenAction(null, null, null, "GET",