/** * Returns the {@link Link} to point to the {@link Payment} for the given {@link Order}. * * @param order must not be {@literal null}. * @return */ Link getPaymentLink(Order order) { return entityLinks.linkForSingleResource(order).slash(PAYMENT).withRel(PAYMENT_REL); }
/** * Returns the {@link Link} to the {@link Receipt} of the given {@link Order}. * * @param order * @return */ Link getReceiptLink(Order order) { return entityLinks.linkForSingleResource(order).slash(RECEIPT).withRel(RECEIPT_REL); } }
@Override public Resource<Order> process(Resource<Order> resource) { Order order = resource.getContent(); if (!order.isPaid()) { resource.add(entityLinks.linkForSingleResource(order).withRel(CANCEL_REL)); resource.add(entityLinks.linkForSingleResource(order).withRel(UPDATE_REL)); } return resource; } }
private List<Link> getCollectionResourceLinks(RootResourceInformation resourceInformation, DefaultedPageable pageable) { ResourceMetadata metadata = resourceInformation.getResourceMetadata(); SearchResourceMappings searchMappings = metadata.getSearchResourceMappings(); List<Link> links = new ArrayList<Link>(); links.add(new Link(ProfileController.getPath(this.config, metadata), ProfileResourceProcessor.PROFILE_REL)); if (searchMappings.isExported()) { links.add(entityLinks.linkFor(metadata.getDomainType()).slash(searchMappings.getPath()) .withRel(searchMappings.getRel())); } return links; }
@Override public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { PersistentProperty<?> property = association.getInverse(); Object propertyValue = accessor.getProperty(property); ResourceMetadata metadata = mappings.getMetadataFor(property.getOwner().getType()); ResourceMapping propertyMapping = metadata.getMappingFor(property); if (property.isCollectionLike()) { for (Object element : (Collection<?>) propertyValue) { PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(element.getClass()); IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(element); links.add(entityLinks.linkForSingleResource(element.getClass(), identifierAccessor.getIdentifier()) .withRel(propertyMapping.getRel())); } } else { PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(propertyValue.getClass()); IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(propertyValue); links.add(entityLinks.linkForSingleResource(propertyValue.getClass(), identifierAccessor.getIdentifier()) .withRel(propertyMapping.getRel())); } } }
@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()); }
@Component public class CaseResourceProcessor implements ResourceProcessor<Resource<Case>> { @Autowired private RepositoryRestMvcConfiguration configuration; @Override public Resource<Case> process(Resource<Case> resource) { LinkBuilder link = configuration.entityLinks().linkForSingleResource(Submission.class, resource.getContent().getLatestSubmission().getId()); resource.add(link.withRel("latestSubmission")); return resource; } }
public Link getConfigurationLink(WorkBook workBook) { return this.entityLinks.linkForSingleResource(WorkBook.class, workBook.getId()) .slash("configuration").withRel("configuration"); } }
@Override public PagedResources<Resource<Taco>> process(PagedResources<Resource<Taco>> resources) { resources .add(entityLinks .linkFor(Taco.class) .slash("recent") .withRel("recents")); return resources; }
public Link getConfigurationLink(Workbench workbench) { return this.entityLinks.linkForSingleResource(Workbench.class, workbench.getId()) .slash("configuration").withRel("configuration"); } }
private List<Link> getCollectionResourceLinks(RootResourceInformation resourceInformation, DefaultedPageable pageable) { ResourceMetadata metadata = resourceInformation.getResourceMetadata(); SearchResourceMappings searchMappings = metadata.getSearchResourceMappings(); List<Link> links = new ArrayList<Link>(); links.add(new Link(ProfileController.getPath(this.config, metadata), ProfileResourceProcessor.PROFILE_REL)); if (searchMappings.isExported()) { links.add(entityLinks.linkFor(metadata.getDomainType()).slash(searchMappings.getPath()) .withRel(searchMappings.getRel())); } return links; }
@Override public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { PersistentProperty<?> property = association.getInverse(); Object propertyValue = accessor.getProperty(property); ResourceMetadata metadata = mappings.getMetadataFor(property.getOwner().getType()); ResourceMapping propertyMapping = metadata.getMappingFor(property); if (property.isCollectionLike()) { for (Object element : (Collection<?>) propertyValue) { PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(element.getClass()); IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(element); links.add(entityLinks.linkForSingleResource(element.getClass(), identifierAccessor.getIdentifier()) .withRel(propertyMapping.getRel())); } } else { PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(propertyValue.getClass()); IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(propertyValue); links.add(entityLinks.linkForSingleResource(propertyValue.getClass(), identifierAccessor.getIdentifier()) .withRel(propertyMapping.getRel())); } } }
@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()); }
/** * 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; }
root.add(entityLinks.linkToCollectionResource(AppStatusResource.class).withRel("runtime/apps")); root.add(unescapeTemplateVariables( entityLinks.linkForSingleResource(AppStatusResource.class, "{appId}").withRel("runtime/apps/app"))); root.add(unescapeTemplateVariables( entityLinks.linkFor(AppInstanceStatusResource.class, "{appId}") .withRel("runtime/apps/instances"))); root.add(ControllerLinkBuilder.linkTo(MetricsController.class).withRel("metrics/streams")); .withRel("jobs/executions/execution"))); root.add(unescapeTemplateVariables(entityLinks.linkFor(StepExecutionResource.class, "{jobExecutionId}") .withRel("jobs/executions/execution/steps"))); root.add(unescapeTemplateVariables(entityLinks.linkFor(StepExecutionResource.class, "{jobExecutionId}") .slash("{stepId}").withRel("jobs/executions/execution/steps/step"))); root.add(unescapeTemplateVariables( entityLinks.linkFor(StepExecutionProgressInfoResource.class, "{jobExecutionId}").slash("{stepId}") .slash("progress").withRel("jobs/executions/execution/steps/step/progress"))); taskTemplated = entityLinks.linkToCollectionResource(JobInstanceResource.class).getHref() + "{?name}"; root.add(new Link(taskTemplated).withRel("jobs/instances/name")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(JobInstanceResource.class, "{id}") .withRel("jobs/instances/instance"))); root.add(entityLinks.linkFor(TaskToolsResource.class).withRel("tools/parseTaskTextToGraph")); root.add(entityLinks.linkFor(TaskToolsResource.class).withRel("tools/convertTaskGraphToText"));
.withRel("jobs/executions/execution"))); root.add(unescapeTemplateVariables(entityLinks.linkFor(StepExecutionResource.class, "{jobExecutionId}") .withRel("jobs/executions/execution/steps"))); root.add(unescapeTemplateVariables(entityLinks.linkFor(StepExecutionResource.class, "{jobExecutionId}") .slash("{stepId}").withRel("jobs/executions/execution/steps/step"))); root.add(unescapeTemplateVariables( entityLinks.linkFor(StepExecutionProgressInfoResource.class, "{jobExecutionId}").slash("{stepId}") .slash("progress").withRel("jobs/executions/execution/steps/step/progress"))); taskTemplated = entityLinks.linkToCollectionResource(JobInstanceResource.class).getHref() + "{?name}"; root.add(new Link(taskTemplated).withRel("jobs/instances/name")); root.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(JobInstanceResource.class, "{id}") .withRel("jobs/instances/instance"))); root.add(entityLinks.linkFor(TaskToolsResource.class).withRel("tools/parseTaskTextToGraph")); root.add(entityLinks.linkFor(TaskToolsResource.class).withRel("tools/convertTaskGraphToText")); root.add(entityLinks.linkToCollectionResource(JobExecutionThinResource.class).withRel("jobs/thinexecutions")); taskTemplated = entityLinks.linkToCollectionResource(JobExecutionThinResource.class).getHref() + "{?name}";