/** * Take an {@link Employee} and get the URI using Spring Data REST's {@link EntityLinks}. * * @param employee */ private String getPath(Employee employee) { return this.entityLinks.linkForSingleResource(employee.getClass(), employee.getId()).toUri().getPath(); }
/** * Take an {@link Employee} and get the URI using Spring Data REST's {@link EntityLinks}. * * @param employee */ private String getPath(Employee employee) { return this.entityLinks.linkForSingleResource(employee.getClass(), employee.getId()).toUri().getPath(); }
/** * 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; } }
@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())); } } }
/** * Renders the given {@link Receipt} including links to the associated {@link Order} as well as a self link in case * the {@link Receipt} is still available. * * @param receipt * @return */ private HttpEntity<Resource<Receipt>> createReceiptResponse(Receipt receipt) { Order order = receipt.getOrder(); Resource<Receipt> resource = new Resource<>(receipt); resource.add(entityLinks.linkToSingleResource(order)); if (!order.isTaken()) { resource.add(entityLinks.linkForSingleResource(order).slash("receipt").withSelfRel()); } return ResponseEntity.ok(resource); }
public Link getSelfLink(WorkBook workBook) { return this.entityLinks.linkForSingleResource(WorkBook.class, workBook.getId()) .withSelfRel(); }
public Link getSelfLink(Workbench workbench) { return this.entityLinks.linkForSingleResource(Workbench.class, workbench.getId()) .withSelfRel(); }
@PostMapping public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) { HttpHeaders headers = new HttpHeaders(); Foo entity = new Foo(fooResource.getUuid(), "Foo"); // ... headers.setLocation(entityLinks.linkForSingleResource(FooResource.class, UuidHelper.toFriendlyId(entity)).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
@PostMapping public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) { HttpHeaders headers = new HttpHeaders(); Foo entity = new Foo(fooResource.getUuid(), "Foo"); // ... headers.setLocation(entityLinks.linkForSingleResource(FooResource.class, UuidHelper.toFriendlyId(entity)).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
public Link getConfigurationLink(WorkBook workBook) { return this.entityLinks.linkForSingleResource(WorkBook.class, workBook.getId()) .slash("configuration").withRel("configuration"); } }
public Link getConfigurationLink(Workbench workbench) { return this.entityLinks.linkForSingleResource(Workbench.class, workbench.getId()) .slash("configuration").withRel("configuration"); } }
@PostMapping("/open") public Future<?> open(@RequestBody Map<String, String> body) { String id = randomUUID().toString(); String customerId = new ResourceURI(body.get("customer")).getId(); Optional .ofNullable(this.customers.findOne(customerId)) .orElseThrow(CustomerNotFoundException::new); FutureCallback<OpenOrderCommand, Object> callback = new FutureCallback<>(); commandGateway.send(new OpenOrderCommand(id, customerId), callback); return callback .thenApply(v -> links.linkForSingleResource(Order.class, id).withSelfRel().getHref()) .toCompletableFuture(); }
@PostMapping("/add") public Future<?> addAddress(@PathVariable String customerId, @RequestBody AddressRequestBody body) { String addressId = randomUUID().toString(); String location = body.getLocation(); String nickName = body.getNickName(); FutureCallback<AddAddressCommand, Object> callback = new FutureCallback<>(); commandGateway.send(new AddAddressCommand(customerId, addressId, nickName, location), callback); return callback .thenApply(v -> links.linkForSingleResource(Address.class, addressId).withSelfRel().getHref()) .toCompletableFuture(); }
@PostMapping("/add") public Future<?> addMenuItem(@RequestBody MenuItemRequestBody body) { String id = randomUUID().toString(); String description = body.getDescription(); BigDecimal price = body.getPrice(); FutureCallback<AddMenuItemCommand, Object> callback = new FutureCallback<>(); commandGateway.send(new AddMenuItemCommand(id, description, price), callback); return callback .thenApply(v -> links.linkForSingleResource(Item.class, id).withSelfRel().getHref()) .toCompletableFuture(); }
@PostMapping("/add") public Future<?> add(@PathVariable String orderId, @RequestBody OrderItemRequestBody body) { String menuItemId = new ResourceURI(body.getMenuItem()).getId(); String orderItemId = randomUUID().toString(); Integer quantity = body.getQuantity(); BigDecimal price = Optional .ofNullable(menuItems.findOne(menuItemId)) .orElseThrow(Exceptions.MenuItemNotFoundException::new) .getPrice(); FutureCallback<AddItemToOrderCommand, Object> callback = new FutureCallback<>(); commandGateway.send(new AddItemToOrderCommand(orderId, orderItemId, menuItemId, price, quantity), callback); return callback .thenApply(v -> links.linkForSingleResource(OrderItem.class, orderItemId).withSelfRel().getHref()) .toCompletableFuture(); }
@PostMapping("/sign-up") public Future<?> signUp(@RequestBody CustomerRequestBody body) { String email = body.getEmail(); String id = generateId(email); FutureCallback<SignUpCustomerCommand, Object> callback = new FutureCallback<>(); commandGateway.send(new SignUpCustomerCommand(id, email), callback); return callback .thenApply(v -> links.linkForSingleResource(Customer.class, id).withSelfRel().getHref()) .toCompletableFuture(); }
@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())); } } }
/** * 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; }