Package com.theoryinpractise.halbuilder.api

Examples of com.theoryinpractise.halbuilder.api.Representation


    WebFormAuthenticationDto authenticationRequest) {

    Optional<User> requestedUser = userReadService.getByCredentials(authenticationRequest.getUsername(), authenticationRequest.getPasswordDigest());
    ResourceAsserts.assertPresent(requestedUser,"requestedUser");

    Representation representation = new ClientUserRepresentation().get(requestedUser.get());

    return ok(representation);

  }
View Full Code Here


  @Timed
  public Response retrieveOwnUser(
    @RestrictedTo({Authority.ROLE_SUPPLIER})
    User supplierUser) {

    Representation representation = new SupplierUserRepresentation().get(supplierUser);

    return ok(representation);

  }
View Full Code Here

    User persistentUser = userReadService.saveOrUpdate(supplierUser);

    // Provide a minimal representation to the client
    // so that they can see their secret key as a last resort
    // manual recovery option
    Representation representation = new SupplierUserRepresentation().get(supplierUser);
    URI location = uriInfo.getAbsolutePathBuilder().path(persistentUser.getApiKey()).build();

    return created(representation, location);

  }
View Full Code Here

  @Timed
  public Response retrieveOwnUser(
    @RestrictedTo({Authority.ROLE_CUSTOMER})
    User customerUser) {

    Representation representation = new CustomerUserRepresentation().get(customerUser);

    return ok(representation);

  }
View Full Code Here

    User persistentUser = userReadService.saveOrUpdate(customerUser);

    // Provide a minimal representation to the client
    // so that they can see their secret key as a last resort
    // manual recovery option
    Representation representation = new CustomerUserRepresentation().get(persistentUser);
    URI location = uriInfo.getAbsolutePathBuilder().path(persistentUser.getApiKey()).build();

    return created(representation, location);

  }
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)
      .withProperty("price_total", deliveryTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", delivery.getItemTotal())
      .withProperty("quantity_total", delivery.getQuantityTotal())
      // End of build
      ;

    // Create sub-resources based on items
    for (DeliveryItem deliveryItem : delivery.getDeliveryItems()) {
      Representation publicDeliveryItemRepresentation = supplierDeliveryItemRepresentation.get(deliveryItem);
      deliveryRepresentation.withRepresentation("deliveryitems", publicDeliveryItemRepresentation);
    }

    return deliveryRepresentation;
  }
View Full Code Here

  public Representation get(Delivery delivery) {
    Preconditions.checkNotNull(delivery, "delivery");
    Preconditions.checkNotNull(delivery.getId(), "id");

    // Build on the Customer representation
    Representation userRepresentation = supplierDeliveryRepresentation.get(delivery)
      // Must use individual property entries due to collections
      .withProperty("id", delivery.getId())
      // End of build
      ;
View Full Code Here

  public Representation get(PaginatedList<Delivery> deliveries) {

    Preconditions.checkNotNull(deliveries);

    URI self = UriBuilder.fromPath("/admin/delivery").build();
    Representation deliveryList = Representations.newPaginatedList(self, deliveries);

    for (Delivery delivery : deliveries.list()) {
      Representation deliveryRepresentation = supplierDeliveryRepresentation.get(delivery);

      deliveryRepresentation.withProperty("id", delivery.getId())
      // End of build
      ;

      deliveryList.withRepresentation("/delivery/" + delivery.getId(), deliveryRepresentation);
    }
View Full Code Here

    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());
    }

    // Add the bean
    if (beanOptional.isPresent()) {
      representation.withBean(beanOptional.get());
    }

    // Add the embedded entries
    for (Map.Entry<String, List<Representation>> entry : embedded.entrySet()) {
      List<Representation> embeddedList = entry.getValue();
      // Duplicated keys will be represented as an array
      for (Representation embedded : embeddedList) {
        representation.withRepresentation(entry.getKey(), embedded);
      }
    }

    isBuilt = true;
View Full Code Here

      // TODO Fill in the location of a Delivery by a Supplier
    }
    Delivery delivery = supplierUser.getSupplier().getDeliveries().iterator().next();

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

    return ok(representation);

  }
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.