Package com.theoryinpractise.halbuilder

Examples of com.theoryinpractise.halbuilder.DefaultRepresentationFactory


  /**
   * @return A {@link RepresentationFactory} configured for production use
   */
  protected static RepresentationFactory getRepresentationFactory() {
    return new DefaultRepresentationFactory();
  }
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

      deliveryTotal = deliveryTotal.plus(deliveryItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(deliveryItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation deliveryRepresentation = new DefaultRepresentationFactory()
      .newRepresentation(basePath)
      // Do not reveal the supplier to non-admins
      .withLink("supplier","/supplier")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
View Full Code Here

  public Representation build() {

    validateState();

    // Representation is a DTO so requires a default constructor
    DefaultRepresentationFactory factory = new DefaultRepresentationFactory();

    final Representation representation;

    // Check for pagination links
    if (paginationOptional.isPresent()) {
      Pagination pagination = paginationOptional.get();

      // Build a self URI with pagination parameters
      URI paginatedSelf = UriBuilder
        .fromUri(self)
        .queryParam("pn", pagination.getCurrentPage())
        .queryParam("ps",pagination.getResultsPerPage())
        .build();

      representation = factory.newRepresentation(paginatedSelf);
      representation
        .withLink("first", UriBuilder
          .fromUri(self)
          .queryParam("pn", 1)
          .queryParam("ps", pagination.getResultsPerPage())
          .build())
        .withLink("previous", UriBuilder
          .fromUri(self)
          .queryParam("pn", pagination.getPreviousPage())
          .queryParam("ps", pagination.getResultsPerPage())
          .build())
        .withLink("current", UriBuilder
          .fromUri(self)
          .queryParam("pn", pagination.getPreviousPage())
          .queryParam("ps", pagination.getResultsPerPage())
          .build())
        .withLink("next", UriBuilder
          .fromUri(self)
          .queryParam("pn", pagination.getNextPage())
          .queryParam("ps", pagination.getResultsPerPage())
          .build())
        .withLink("last", UriBuilder
          .fromUri(self)
          .queryParam("pn", pagination.getTotalPages())
          .queryParam("ps", pagination.getResultsPerPage())
          .build());
    } else {
      representation = factory.newRepresentation(self);
    }

    // Add any links
    for (Map.Entry<String, String> entry : links.entrySet()) {
      representation.withLink(entry.getKey(), entry.getValue());
View Full Code Here

  /**
   * @return A {@link Representation} from the default factory
   */
  private static Representation newRepresentation(URI self) {
    return new DefaultRepresentationFactory().newRepresentation(self);
  }
View Full Code Here

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

    String basePath = "/suppliers/" + supplier.getId();

    // Create top-level resource
    return new DefaultRepresentationFactory()
      .newRepresentation(basePath)
      .withLink("user","/users/" + supplier.getUser().getId());
  }
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

      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)
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);
View Full Code Here

TOP

Related Classes of com.theoryinpractise.halbuilder.DefaultRepresentationFactory

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.