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; }
private String generateTemplatedUri(String appUrl, Type type) { String uri = (appUrl != null) ? appUrl + type.getAction() : type.getAction(); uri = uri + "?type=" + type.getId(); UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables); return uriTemplate.toString(); }
/** * 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<>(); }
/** * Returns the href for the {@link Curie} instance to be created. Will prepend the current application URI (servlet * mapping) in case the template is not an absolute one in the first place. * * @param name will never be {@literal null} or empty. * @param template will never be {@literal null}. * @return the {@link String} to be used as href in the {@link Curie} to be created, must not be {@literal null}. */ protected String getCurieHref(String name, UriTemplate template) { if (template.toString().startsWith("http")) { return template.toString(); } String applicationUri = ServletUriComponentsBuilder.fromCurrentServletMapping().build().expand().toString(); return applicationUri.concat(template.toString()); }
/** * 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); }
private UriStringAndHeaders traverseToFinalUrl() { UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), this.rels.iterator(), HttpHeaders.EMPTY); return new UriStringAndHeaders(new UriTemplate(uriAndHeaders.getUri()).toString(), uriAndHeaders.getHttpHeaders()); }
@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()); }
@Override public CounterResource retrieve(String name) { String url = resources.get("counters").toString() + "/{name}"; return restTemplate.getForObject(url, CounterResource.class, name); }
@Override public PagedResources<MetricResource> list() { String url = resources.get("counters").toString() + "?size=10000"; return restTemplate.getForObject(url, MetricResource.Page.class); }
@Override public FieldValueCounterResource retrieve(String name) { String url = resources.get("field-value-counters").toString() + "/{name}"; return restTemplate.getForObject(url, FieldValueCounterResource.class, name); }
@Override public RichGaugeResource retrieve(String name) { String url = resources.get("rich-gauges").toString() + "/{name}"; return restTemplate.getForObject(url, RichGaugeResource.class, name); }
@Override public PagedResources<MetricResource> list() { String url = resources.get("field-value-counters").toString() + "?page=10000"; return restTemplate.getForObject(url, MetricResource.Page.class); }
@Override public void stopJobExecution(long executionId) { String uriTemplate = resources.get("jobs/executions").toString() + "/{executionId}"; MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>(); values.add("executionId", executionId); uriTemplate = uriTemplate + "?stop=true"; restTemplate.put(uriTemplate, values, executionId); }
@Override public void restartJobExecution(long executionId) { String uriTemplate = resources.get("jobs/executions").toString() + "/{executionId}"; MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>(); values.add("executionId", executionId); uriTemplate = uriTemplate + "?restart=true"; restTemplate.put(uriTemplate, values, executionId); }
@Override public void delete(String name) { String url = resources.get("rich-gauges").toString() + "/{name}"; restTemplate.delete(url, name); }
@Override public String downloadConfigurationFile(RESTModuleType type, String name) { final String uriTemplate = resources.get("modules").toString() + "/{type}/{name}/definition"; return restTemplate.getForObject(uriTemplate, String.class, type.name(), name); }
@Override public AppRegistrationResource register(String name, ApplicationType type, String uri, String metadataUri, boolean force) { MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>(); values.add("uri", uri); if (metadataUri != null) { values.add("metadata-uri", metadataUri); } values.add("force", Boolean.toString(force)); return restTemplate.postForObject(uriTemplate.toString() + "/{type}/{name}", values, AppRegistrationResource.class, type, name); }
@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(uriTemplate.toString() + "/{type}/{name}/{version}", values, AppRegistrationResource.class, type, name, version); }
@Override public PagedResources<AppRegistrationResource> importFromResource(String uri, boolean force) { MultiValueMap<String, Object> values = new LinkedMultiValueMap<>(); values.add("uri", uri); values.add("force", Boolean.toString(force)); return restTemplate.postForObject(uriTemplate.toString(), values, AppRegistrationResource.Page.class); }
@Override public void delete(String name) { String url = resources.get("counters").toString() + "/{name}"; restTemplate.delete(url, name); }