Package com.theoryinpractise.halbuilder.api

Examples of com.theoryinpractise.halbuilder.api.RepresentationFactory


   * @param hal The HAL representation
   *
   * @return The unmarshalled domain object
   */
  protected static ReadableRepresentation unmarshalHal(String hal) {
    RepresentationFactory rf = getRepresentationFactory();
    Reader reader = new StringReader(hal);
    return rf.readRepresentation(reader);
  }
View Full Code Here


    // Create the Customer Item resource
    Representation customerItemRepresentation = publicItemRepresentation.get(cartItem.getItem());

    // Create the wrapping CartItem resource
    RepresentationFactory factory = new DefaultRepresentationFactory();

    return factory.newRepresentation("/cart/item/" + cartItem.getIndex())
      .withProperty("index", cartItem.getIndex())
      .withProperty("quantity", cartItem.getQuantity())
      .withProperty("price_subtotal", cartItem.getPriceSubtotal().getAmount().toPlainString())
      .withProperty("tax_subtotal", cartItem.getTaxSubtotal().getAmount().toPlainString())
      .withProperty("cart_item_subtotal", cartItem.getCartItemSubtotal().getAmount().toPlainString())
View Full Code Here

  public Representation get(Item item) {

    Preconditions.checkNotNull(item, "item");
    Preconditions.checkNotNull(item.getId(), "id");

    RepresentationFactory factory = new DefaultRepresentationFactory();

    return factory.newRepresentation("/item/" + item.getId())
      // Must use individual property entries due to collections
      .withProperty("sku", item.getSKU())
      .withProperty("gtin", item.getGTIN());

  }
View Full Code Here

    // Create the Customer Item resource
    Representation publicItemRepresentation = new PublicItemRepresentation().get(deliveryItem.getItem());

    // Create the wrapping DeliveryItem resource
    RepresentationFactory factory = new DefaultRepresentationFactory();

    return factory.newRepresentation("/delivery/item/" + deliveryItem.getItem().getSKU())
      .withProperty("supplier_sku", deliveryItem.getSupplierSKU())
      .withProperty("supplier_gtin", deliveryItem.getSupplierGTIN())
      .withProperty("batch_reference", deliveryItem.getBatchReference())
      .withProperty("quantity", deliveryItem.getQuantity())
      .withProperty("price_subtotal", deliveryItem.getPriceSubtotal().getAmount().toPlainString())
View Full Code Here

    Preconditions.checkNotNull(customer.getId(), "id");

    String basePath = "/customer/" + customer.getId();

    // Create top-level resource
    RepresentationFactory factory = new DefaultRepresentationFactory();
    return factory
      .newRepresentation(basePath)
      .withLink("user", "/user/" + customer.getUser().getId())
      .withLink("cart", "/cart/" + customer.getCart().getId());
  }
View Full Code Here

*/
public class ClientUserRepresentation {

  public Representation get(User user, Optional<User> principal) {

    RepresentationFactory factory = new DefaultRepresentationFactory();
    Representation representation;

    if (user != null) {
      // Working with an authenticated User

      // Determine how the path should be presented
      String path;
      // TODO Consider a general Decorator
      if (principal.isPresent() && principal.get().hasAuthority(Authority.ROLE_ADMIN)) {
        path = "/admin/user/" + user.getId();
      } else if (user.getCustomer() != null) {
        path = "/customer/user";
      } else if (user.getSupplier() != null) {
        path = "/supplier/user";
      } else {
        throw new IllegalStateException("User does not have correct rights to be here ["+user.getId()+"]");
      }

      // The user will refer to their own profile implicitly
      representation = factory.newRepresentation(path)
        // The username and password digest are not required for any further authentication
        // If they are required it will be as part of a user profile update
        // The API and secret key are required for future user requests via HMAC
        .withProperty("api_key", user.getApiKey())
        .withProperty("secret_key", user.getSecretKey())
      // End of build
      ;
    } else {
      // The unauthenticated user will still refer to their own profile implicitly
      representation = factory.newRepresentation("/customer/user")
        // Provide empty credentials indicating a failure
        .withProperty("api_key", "")
        .withProperty("secret_key", "")
      // End of build
      ;
View Full Code Here

    // Create the Customer Item resource
    Representation publicItemRepresentation = new PublicItemRepresentation().get(purchaseOrderItem.getItem());

    // Create the wrapping PurchaseOrderItem resource
    RepresentationFactory factory = new DefaultRepresentationFactory();

    return factory.newRepresentation("/purchase-order/item/" + purchaseOrderItem.getItem().getSKU())
      .withProperty("supplier_sku", purchaseOrderItem.getSupplierSKU())
      .withProperty("supplier_gtin", purchaseOrderItem.getSupplierGTIN())
      .withProperty("batch_reference", purchaseOrderItem.getBatchReference())
      .withProperty("quantity", purchaseOrderItem.getQuantity())
      .withProperty("price_subtotal", purchaseOrderItem.getPriceSubtotal().getAmount().toPlainString())
View Full Code Here

public class AdminCartCollectionRepresentation {

  private final PublicCartRepresentation publicCartRepresentation = new PublicCartRepresentation();

  public Representation get(PaginatedList<Cart> carts) {
    RepresentationFactory factory = new DefaultRepresentationFactory();

    URI self = UriBuilder.fromPath("/admin/cart").build();
    Representation cartList = Representations.newPaginatedList(self, carts);

    for (Cart cart : carts.list()) {
View Full Code Here

  public Representation get(Item item) {
    Preconditions.checkNotNull(item, "item");
    Preconditions.checkNotNull(item.getId(), "id");

    RepresentationFactory factory = new DefaultRepresentationFactory();

    // Create the slug from the title (if it is present)
    String title = item.getItemFieldContent(ItemField.TITLE);
    String slug = null;
    if (title != null) {
      slug = title
        .replaceAll("\\p{Punct}", "")
        .replaceAll("\\p{Space}", "-")
        .toLowerCase();
    }

    // Calculate the price
    // TODO Consider currency choice from preferences
    String price = item.getLocalPrice().getAmount().toPlainString();
    String taxRate = String.valueOf(item.getTaxRate());

    Representation userRepresentation = factory
      .newRepresentation("/item/" + item.getSKU())
      .withProperty("sku", item.getSKU())
      .withProperty("gtin", item.getGTIN())
      .withProperty("price", price)
      .withProperty("tax_rate", taxRate)
View Full Code Here

TOP

Related Classes of com.theoryinpractise.halbuilder.api.RepresentationFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.