private void writeCollectionHolder(String fieldName, TypedResource collectionHolder, JsonGenerator jgen) throws IOException { jgen.writeObjectFieldStart(fieldName); String identifyingUri = collectionHolder.getIdentifyingUri(); if (identifyingUri != null) { jgen.writeStringField(JsonLdKeywords.AT_ID, identifyingUri); } jgen.writeStringField(JsonLdKeywords.AT_TYPE, collectionHolder.getSemanticType()); jgen.writeEndObject(); }
@RequestMapping("/{orderId}/offers") public HttpEntity<Resources<Offer>> getOffersForOrder(@PathVariable int orderId) { HttpEntity<Resources<Offer>> offers = storeController.getOffers(); for (Offer offer : offers.getBody() .getContent()) { Product itemOffered = offer.getItemOffered(); // we can determine the subject URI of the order TypedResource subject = new TypedResource("Order", linkTo(methodOn(this.getClass()).getOrder(orderId)).toString()); itemOffered.add(linkTo(methodOn(OrderController.class) .orderAdditionalItem(orderId, itemOffered)) .rel(subject, "orderedItem") .build()); } return offers; } }
@RequestMapping("/{orderId}/offers") public HttpEntity<Resources<Offer>> getOffersForOrder(@PathVariable int orderId) { HttpEntity<Resources<Offer>> offers = storeController.getOffers(); for (Offer offer : offers.getBody() .getContent()) { Product itemOffered = offer.getItemOffered(); // we can determine the subject URI of the order TypedResource subject = new TypedResource("Order", linkTo(methodOn(this.getClass()).getOrder(orderId)).toString()); itemOffered.add(linkTo(methodOn(OrderController.class) .orderAdditionalItem(orderId, itemOffered)) .rel(subject, "orderedItem") .build()); } return offers; } }
private Offer createAddOnOffer(Product product, String addOnProductID, double price, int orderId, int orderedItemId) { Offer addOnOffer = new Offer(); addOnOffer.setPriceCurrency(Currency.getInstance("EUR")); addOnOffer.setPrice(BigDecimal.valueOf(price)); Product addOnProduct = productController.getProduct(addOnProductID); addOnOffer.setItemOffered(addOnProduct); String productSelfRel = product.getLink(Link.REL_SELF) .getHref(); addOnProduct.add(linkTo(methodOn(OrderController.class).orderAccessory(orderId, orderedItemId, addOnProduct)) .reverseRel("isAccessoryOrSparePartFor", "extras", new TypedResource("Product", productSelfRel)) .build()); return addOnOffer; }
private Offer createAddOnOffer(Product product, String addOnProductID, double price, int orderId, int orderedItemId) { Offer addOnOffer = new Offer(); addOnOffer.setPriceCurrency(Currency.getInstance("EUR")); addOnOffer.setPrice(BigDecimal.valueOf(price)); Product addOnProduct = productController.getProduct(addOnProductID); addOnOffer.setItemOffered(addOnProduct); String productSelfRel = product.getLink(Link.REL_SELF) .getHref(); addOnProduct.add(linkTo(methodOn(OrderController.class).orderAccessory(orderId, orderedItemId, addOnProduct)) .reverseRel("isAccessoryOrSparePartFor", "extras", new TypedResource("Product", productSelfRel)) .build()); return addOnOffer; }
@RequestMapping public @ResponseBody Store getStoreWithOffers() { Store store = createStoreWithOffers(); List<Offer> offers = store.getMakesOffer(); for (Offer offer : offers) { Product itemOffered = offer.getItemOffered(); itemOffered.add(linkTo(methodOn(OrderController.class).makeOrder(itemOffered)) .rel(new TypedResource("Order"), "orderedItem") .build()); } // TODO: support rev for links and make hydra collection aware of @reverse terms in context - both should work store.add(linkTo(methodOn(OrderController.class).getOrders(null)).reverseRel("seller", "orders") .build()); return store; }
@RequestMapping public @ResponseBody Store getStoreWithOffers() { Store store = createStoreWithOffers(); List<Offer> offers = store.getMakesOffer(); for (Offer offer : offers) { Product itemOffered = offer.getItemOffered(); itemOffered.add(linkTo(methodOn(OrderController.class).makeOrder(itemOffered)) .rel(new TypedResource("Order"), "orderedItem") .build()); } // TODO: support rev for links and make hydra collection aware of @reverse terms in context - both should work store.add(linkTo(methodOn(OrderController.class).getOrders(null)).reverseRel("seller", "orders") .build()); return store; }