Package com.theoryinpractise.halbuilder.api

Examples of com.theoryinpractise.halbuilder.api.Representation


    // 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)
      .withProperty("slug", slug)
      // End of build
      ;

    // Convert the ContactMethodDetails map into primary and secondary property entries
    for (Map.Entry<ItemField, ItemFieldDetail> entry : item.getItemFieldMap().entrySet()) {
      // Determine the property
      String propertyName = entry.getKey().getPropertyNameSingular();
      boolean isLink = entry.getKey().isLink();
      ItemFieldDetail itemFieldDetail = entry.getValue();
      LocalisedText primaryDetail = itemFieldDetail.getPrimaryDetail();

      // TODO Consider how i18n will be transmitted
      // Consider filtering on Locale
      if (isLink) {
        userRepresentation.withLink(propertyName,primaryDetail.getContent());
      } else {
        userRepresentation.withProperty(propertyName, primaryDetail.getContent());
      }
      Set<LocalisedText> secondaryDetails = itemFieldDetail.getSecondaryDetails();
      // TODO Consider if a 1-based field index is the best representation here: array? sub-resource?
      int index = 1;
      for (LocalisedText secondaryDetail : secondaryDetails) {
        if (isLink) {
          userRepresentation.withLink(propertyName + index,secondaryDetail.getContent());
        } else {
          userRepresentation.withProperty(propertyName + index, secondaryDetail.getContent());
        }
        index++;
      }
    }
View Full Code Here


  private final ClientUserRepresentation clientUserRepresentation = new ClientUserRepresentation();

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

    // Build on the minimal representation
    Representation representation = clientUserRepresentation.get(user, principal);

    // Apply restrictions against the more detailed representation
    Preconditions.checkNotNull(user, "user");
    Preconditions.checkNotNull(user.getId(), "id");

    // Add properties
    representation.withProperty("username", user.getUsername());

    // Convert the ContactMethodDetails map into primary and secondary property entries
    for (Map.Entry<ContactMethod, ContactMethodDetail> entry : user.getContactMethodMap().entrySet()) {
      String propertyName = entry.getKey().getPropertyNameSingular();
      ContactMethodDetail contactMethodDetail = entry.getValue();
      String primaryDetail = contactMethodDetail.getPrimaryDetail();

      representation.withProperty(propertyName, primaryDetail);

      // Determine if secondary details should be included
      if (entry.getKey().isSecondaryDetailSupported()) {
        Set<String> secondaryDetails = contactMethodDetail.getSecondaryDetails();
        // TODO Consider if a 1-based field index is the best representation here: array? sub-resource?
        int index = 1;
        for (String secondaryDetail : secondaryDetails) {
          representation.withProperty(propertyName + index, secondaryDetail);
          index++;
        }
      }
    }
View Full Code Here

    // Persist the role
    Role persistentRole = roleReadService.saveOrUpdate(role);

    // Provide a representation to the client
    Representation representation = new AdminRoleRepresentation().get(persistentRole);
    URI location = uriInfo.getAbsolutePathBuilder().path(persistentRole.getId().toString()).build();

    return created(representation, location);

  }
View Full Code Here

    // Persist the item
    Item persistentItem = itemReadService.saveOrUpdate(item);

    // Provide a representation to the client
    Representation representation = new AdminItemRepresentation().get(persistentItem);
    URI location = uriInfo.getAbsolutePathBuilder().path(persistentItem.getId().toString()).build();

    return created(representation, location);

  }
View Full Code Here

    int pageNumber = Integer.valueOf(rawPageNumber.get());

    PaginatedList<Role> roles = roleReadService.getPaginatedList(pageSize, pageNumber);

    // Provide a representation to the client
    Representation representation = new AdminRoleCollectionRepresentation().get(roles);

    return ok(representation);

  }
View Full Code Here

    int pageNumber = Integer.valueOf(rawPageNumber.get());

    PaginatedList<Item> items = itemReadService.getPaginatedList(pageSize, pageNumber);

    // Provide a representation to the client
    Representation representation = new AdminItemCollectionRepresentation().get(items);

    return ok(representation);

  }
View Full Code Here

    // Persist the updated role
    persistentRole = roleReadService.saveOrUpdate(role.get());

    // Provide a representation to the client
    Representation representation = new AdminRoleRepresentation().get(persistentRole);

    return ok(representation);

  }
View Full Code Here

    // Persist the updated role
    persistentRole = roleReadService.saveOrUpdate(role.get());

    // Provide a representation to the client
    Representation representation = new AdminRoleRepresentation().get(persistentRole);

    return ok(representation);

  }
View Full Code Here

    // Persist the updated item
    persistentItem = itemReadService.saveOrUpdate(item.get());

    // Provide a representation to the client
    Representation representation = new AdminItemRepresentation().get(persistentItem);

    return ok(representation);

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