Package com.theoryinpractise.halbuilder.api

Examples of com.theoryinpractise.halbuilder.api.Representation


      purchaseOrderTotal = purchaseOrderTotal.plus(purchaseOrderItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(purchaseOrderItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation purchaseOrderRepresentation = new DefaultRepresentationFactory()
      .newRepresentation(basePath)
      // Do not reveal the supplier to non-admins
      .withLink("supplier","/supplier")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
      .withProperty("price_total", purchaseOrderTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", purchaseOrder.getItemTotal())
      .withProperty("quantity_total", purchaseOrder.getQuantityTotal())
      // End of build
      ;

    // Create sub-resources based on items
    for (PurchaseOrderItem purchaseOrderItem : purchaseOrder.getPurchaseOrderItems()) {
      Representation publicPurchaseOrderItemRepresentation = supplierPurchaseOrderItemRepresentation.get(purchaseOrderItem);
      purchaseOrderRepresentation.withRepresentation("purchaseOrderItems", publicPurchaseOrderItemRepresentation);
    }

    return purchaseOrderRepresentation;
  }
View Full Code Here


  public Representation get(PaginatedList<Item> items) {

    Preconditions.checkNotNull(items, "items");

    URI self = UriBuilder.fromPath("/admin/item").build();
    Representation itemList = Representations.newPaginatedList(self, items);

    for (Item item : items.list()) {
      Representation itemRepresentation = customerItemRepresentation.get(item);

      itemRepresentation.withProperty("id", item.getId())
        // End of build
        ;

      itemList.withRepresentation("/item/" + item.getId(), itemRepresentation);
    }
View Full Code Here

    // Persist the updated delivery
    delivery = deliveryReadService.saveOrUpdate(delivery);

    // Provide a representation to the client
    Representation representation = new SupplierDeliveryRepresentation().get(delivery);

    return ok(representation);

  }
View Full Code Here

    // Validation
    Preconditions.checkNotNull(publicUser.getCustomer(), "customer");

    Cart cart = publicUser.getCustomer().getCart();

    Representation representation = new PublicCartRepresentation().get(cart);

    return ok(representation);

  }
View Full Code Here

    // Persist the updated cart
    cart = cartDao.saveOrUpdate(cart);

    // Provide a representation to the client
    Representation representation = new PublicCartRepresentation().get(cart);

    return ok(representation);

  }
View Full Code Here

  public Representation get(PaginatedList<Item> items) {

    Preconditions.checkNotNull(items, "items");

    URI self = UriBuilder.fromPath("/admin/item").build();
    Representation itemList = Representations.newPaginatedList(self, items);

    // Use the reduced public fields as embedded resources
    for (Item item : items.list()) {
      Representation itemRepresentation = publicItemRepresentation.get(item);
      itemList.withRepresentation("item", itemRepresentation);
    }

    return itemList;
View Full Code Here

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

    // Build the representation
    Representation roleRepresentation = new DefaultRepresentationFactory().newRepresentation("/role/" + role.getId())
      // Must use individual property entries due to collections
      .withProperty("name", role.getName())
      .withProperty("description", role.getDescription())
      .withProperty("internal",role.isInternal())
      // End of build
      ;

    // Build a sub-Representationrepresenting all the authorities bound to this Role
    Representation authoritiesRepresentation = new DefaultRepresentationFactory().newRepresentation("authorities");
    for (Authority authority : role.getAuthorities()) {
      authoritiesRepresentation.withProperty(authority.name(),Boolean.TRUE);
    }
    roleRepresentation.withRepresentation("authorities", authoritiesRepresentation);

    return roleRepresentation;
View Full Code Here

  public Representation get(PaginatedList<PurchaseOrder> purchaseOrders) {

    Preconditions.checkNotNull(purchaseOrders);

    URI self = UriBuilder.fromPath("/admin/purchase-order").build();
    Representation purchaseOrderList = Representations.newPaginatedList(self, purchaseOrders);

    for (PurchaseOrder purchaseOrder : purchaseOrders.list()) {
      Representation purchaseOrderRepresentation = new SupplierPurchaseOrderRepresentation().get(purchaseOrder);

      purchaseOrderRepresentation.withProperty("id", purchaseOrder.getId())
      // End of build
      ;

      purchaseOrderList.withRepresentation("/purchase-order/" + purchaseOrder.getId(), purchaseOrderRepresentation);
    }
View Full Code Here

      cartTotal = cartTotal.plus(cartItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(cartItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation cartRepresentation= new DefaultRepresentationFactory()
      .newRepresentation(basePath)
        // Do not reveal the customer to non-admins
      .withLink("customer", "/customer")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
      .withProperty("price_total", cartTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", cart.getItemTotal())
      .withProperty("quantity_total", cart.getQuantityTotal())
      // End of build
      ;

    // Create sub-resources based on items
    for (CartItem cartItem : cart.getCartItems()) {
      Representation publicCartItemRepresentation= new PublicCartItemRepresentation().get(cartItem);
      cartRepresentation.withRepresentation("cartitems", publicCartItemRepresentation);
    }

    return cartRepresentation;
  }
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
View Full Code Here

TOP

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

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.