/** * Returns a {@link Link} pointing to the same URI but with the {@code self} relation. * * @return */ public Link withSelfRel() { return withRel(IanaLinkRelation.SELF.value()); }
/** * Returns a link pointing to the given entity using the given {@link ResourceMapping} to detect the link relation. * * @param entity must not be {@literal null}. * @param mapping must not be {@literal null}. * @return */ private Link getLinkFor(Object entity, ResourceMapping mapping) { return selfLinks.createSelfLinkFor(entity).withRel(mapping.getRel()); }
Link affordanceLink = new Link(components.toUriString()).withRel(methodName);
/** * Returns a {@link Link} pointing to the same URI but with the {@code self} relation. * * @return */ public Link withSelfRel() { return withRel(Link.REL_SELF); }
/** * Returns a link pointing to the given entity using the given {@link ResourceMapping} to detect the link relation. * * @param entity must not be {@literal null}. * @param mapping must not be {@literal null}. * @return */ private Link getLinkFor(Object entity, ResourceMapping mapping) { return selfLinks.createSelfLinkFor(entity).withRel(mapping.getRel()); }
@Override public OrderResource toResource(Order order) { OrderResource resource = new OrderResource(order); final Link selfLink = entityLinks.linkToSingleResource(order); resource.add(selfLink.withSelfRel()); resource.add(selfLink.withRel(UPDATE_REL)); resource.add(selfLink.withRel(DELETE_REL)); return resource; } }
@RequestMapping(method = RequestMethod.GET) public List<Resource<S3ObjectSummary>> getBucketResources() { ObjectListing objectListing = amazonS3Template.getAmazonS3Client() .listObjects(new ListObjectsRequest() .withBucketName(bucketName)); return objectListing.getObjectSummaries() .stream() .map(a -> new Resource<>(a, new Link(String.format("https://s3.amazonaws.com/%s/%s", a.getBucketName(), a.getKey())).withRel("url"))) .collect(Collectors.toList()); }
@Override public Resource<Customer> process(Resource<Customer> resource) { Customer customer = resource.getContent(); Location location = customer.getAddress().getLocation(); Map<String, Object> parameters = new HashMap<>(); parameters.put("location", String.format("%s,%s", location.getLatitude(), location.getLongitude())); parameters.put("distance", "50km"); String host = this.request.getIfAvailable().getHeader(X_FORWARDED_HOST); Link link = this.storeIntegration.getStoresByLocationLink(parameters, host); if (link != null) { resource.add(link.withRel("stores-nearby")); } return resource; } }
@Override public Resource<Customer> process(Resource<Customer> resource) { Customer customer = resource.getContent(); Location location = customer.getAddress().getLocation(); Optional<Link> link = Optional.ofNullable(storesByLocationResource.getLink()); link.ifPresent(it -> { if (location == null) { return; } Map<String, Object> parameters = new HashMap<>(); parameters.put("location", String.format("%s,%s", location.getLatitude(), location.getLongitude())); parameters.put("distance", "50km"); resource.add(it.expand(parameters).withRel("stores-nearby")); }); return resource; } }
@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; } }
@RequestMapping(method = RequestMethod.PATCH) public NewCartResource buy(@RequestBody final CartResource theCart) { NewCartResource cart = new NewCartResource(initializeBooksInCart(), cartPurchased); if (theCart.isPurchased()) { cartPurchased = true; cart.setPurchased(cartPurchased); } cart.add(new Link("http://localhost:8081/api/receipt/1").withRel("receipt")); return cart; }
/** * Return a {@link ResourceSupport} object containing the resources * served by the admin server. * * @return {@code ResourceSupport} object containing the admin server's resources */ @RequestMapping("/") public ResourceSupport info() { ResourceSupport resourceSupport = new ResourceSupport(); resourceSupport.add(entityLinks.linkToCollectionResource(StreamDefinitionResource.class).withRel("streams/definitions")); resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamDefinitionResource.class, "{name}").withRel("streams/definitions/definition"))); resourceSupport.add(entityLinks.linkToCollectionResource(StreamDeploymentResource.class).withRel("streams/deployments")); resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamDeploymentResource.class, "{name}").withRel("streams/deployments/deployment"))); resourceSupport.add(entityLinks.linkToCollectionResource(TaskDefinitionResource.class).withRel("tasks")); resourceSupport.add(entityLinks.linkToCollectionResource(CounterResource.class).withRel("counters")); resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(CounterResource.class, "{name}").withRel("counters/counter"))); resourceSupport.add(entityLinks.linkToCollectionResource(ModuleRegistrationResource.class).withRel("modules")); resourceSupport.add(entityLinks.linkToCollectionResource(LibraryRegistrationResource.class).withRel("libraries")); resourceSupport.add(entityLinks.linkToCollectionResource(ModuleStatusResource.class).withRel("runtime/modules")); resourceSupport.add(unescapeTemplateVariables(entityLinks.linkForSingleResource(ModuleStatusResource.class, "{moduleId}").withRel("runtime/module"))); resourceSupport.add(unescapeTemplateVariables(entityLinks.linkFor(ModuleInstanceStatusResource.class, UriComponents.UriTemplateVariables.SKIP_VALUE).withRel("runtime/modules/instances"))); String templated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/stream{?start,detailLevel}"); resourceSupport.add(new Link(templated).withRel("completions/stream")); return resourceSupport; }
.withRel("streams/definitions")); root.add( unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamDefinitionResource.class, "{name}") .withRel("streams/definitions/definition"))); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamAppStatusResource.class, "{name}") .withRel("streams/validation"))); root.add(entityLinks.linkToCollectionResource(AppStatusResource.class).withRel("runtime/apps")); root.add(unescapeTemplateVariables( entityLinks.linkForSingleResource(AppStatusResource.class, "{appId}").withRel("runtime/apps/app"))); .withRel("streams/deployments/deployment"))); root.add(entityLinks.linkToCollectionResource(TaskDefinitionResource.class).withRel("tasks/definitions")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskDefinitionResource.class, "{name}") .withRel("tasks/definitions/definition"))); root.add(entityLinks.linkToCollectionResource(TaskExecutionResource.class).withRel("tasks/executions")); String taskTemplated = entityLinks.linkToCollectionResource(TaskExecutionResource.class).getHref() + "{?name}"; root.add(new Link(taskTemplated).withRel("tasks/executions/name")); root.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(TaskExecutionController.class) .getCurrentTaskExecutionsInfo()).withRel("tasks/executions/current")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskExecutionResource.class, "{id}") .withRel("tasks/executions/execution"))); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskAppStatusResource.class, "{name}") .withRel("tasks/validation"))); root.add(entityLinks.linkToCollectionResource(ScheduleInfoResource.class).withRel("tasks/schedules")); String scheduleTemplated = entityLinks.linkToCollectionResource(ScheduleInfoResource.class).getHref() + "/instances/{taskDefinitionName}";
.withRel("streams/definitions")); root.add( unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamDefinitionResource.class, "{name}") .withRel("streams/definitions/definition"))); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(StreamAppStatusResource.class, "{name}") .withRel("streams/validation"))); .withRel("streams/deployments/deployment"))); root.add(entityLinks.linkToCollectionResource(LauncherResource.class).withRel("tasks/platforms")); root.add(entityLinks.linkToCollectionResource(TaskDefinitionResource.class).withRel("tasks/definitions")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskDefinitionResource.class, "{name}") .withRel("tasks/definitions/definition"))); root.add(entityLinks.linkToCollectionResource(TaskExecutionResource.class).withRel("tasks/executions")); String taskTemplated = entityLinks.linkToCollectionResource(TaskExecutionResource.class).getHref() + "{?name}"; root.add(new Link(taskTemplated).withRel("tasks/executions/name")); root.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(TaskExecutionController.class) .getCurrentTaskExecutionsInfo()).withRel("tasks/executions/current")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskExecutionResource.class, "{id}") .withRel("tasks/executions/execution"))); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(TaskAppStatusResource.class, "{name}") .withRel("tasks/validation"))); root.add(entityLinks.linkToCollectionResource(ScheduleInfoResource.class).withRel("tasks/schedules")); String scheduleTemplated = entityLinks.linkToCollectionResource(ScheduleInfoResource.class).getHref() + "/instances/{taskDefinitionName}"; root.add(new Link(scheduleTemplated).withRel("tasks/schedules/instances"));
private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler, final Artifact artifact, final SystemManagement systemManagement, final HttpRequest request) { final DdiArtifact file = new DdiArtifact(); file.setHashes(new DdiArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); file.setFilename(artifact.getFilename()); file.setSize(artifact.getSize()); artifactUrlHandler .getUrls(new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(), systemManagement.getTenantMetadata().getId(), target.getControllerId(), target.getId(), new SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getId(), artifact.getSha1Hash())), ApiType.DDI, request.getURI()) .forEach(entry -> file.add(new Link(entry.getRef()).withRel(entry.getRel()))); return file; }
private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler, final Artifact artifact, final SystemManagement systemManagement, final HttpRequest request) { final DdiArtifact file = new DdiArtifact(); file.setHashes(new DdiArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); file.setFilename(artifact.getFilename()); file.setSize(artifact.getSize()); artifactUrlHandler .getUrls(new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(), systemManagement.getTenantMetadata().getId(), target.getControllerId(), target.getId(), new SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getId(), artifact.getSha1Hash())), ApiType.DDI, request.getURI()) .forEach(entry -> file.add(new Link(entry.getRef()).withRel(entry.getRel()))); return file; }