@Override public Link linkToCollectionResource(Class<?> entity) { return linkFor(entity).withSelfRel(); }
@Override public Link linkToSingleResource(Class<?> entity, Object id) { return linkFor(entity).slash(id).withSelfRel(); }
/** * 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); }
@Override public Link linkToCollectionResource(Class<?> entity) { return linkFor(entity).withSelfRel(); }
public Link getSelfLink(Workbench workbench) { return this.entityLinks.linkForSingleResource(Workbench.class, workbench.getId()) .withSelfRel(); }
@Override public Link linkToSingleResource(Class<?> entity, Object id) { return linkFor(entity).slash(id).withSelfRel(); }
public Link getSelfLink(WorkBook workBook) { return this.entityLinks.linkForSingleResource(WorkBook.class, workBook.getId()) .withSelfRel(); }
@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("/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<?> 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(); }
/** * Eagerly resolve a base URI for the given {@link MethodParameter} to be handed to the assembler. * * @param parameter must not be {@literal null}. * @return the {@link UriComponents} representing the base URI, or {@literal null} if it can't be resolved eagerly. */ @Nullable private UriComponents resolveBaseUri(MethodParameter parameter) { try { Link linkToMethod = linkBuilderFactory.linkTo(parameter.getDeclaringClass(), parameter.getMethod()).withSelfRel(); return UriComponentsBuilder.fromUriString(linkToMethod.getHref()).build(); } catch (IllegalArgumentException o_O) { return null; } }
@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(); }
/** * 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(AboutResource.class).withRel("about")); String completionStreamTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel() .getHref() + ("/stream{?start,detailLevel}"); root.add(new Link(completionStreamTemplated).withRel("completions/stream")); String completionTaskTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/task{?start,detailLevel}"); root.add(new Link(completionTaskTemplated).withRel("completions/task"));
root.add(entityLinks.linkToCollectionResource(AboutResource.class).withRel("about")); String completionStreamTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel() .getHref() + ("/stream{?start,detailLevel}"); root.add(new Link(completionStreamTemplated).withRel("completions/stream")); String completionTaskTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/task{?start,detailLevel}"); root.add(new Link(completionTaskTemplated).withRel("completions/task"));