Package org.multibit.mbm.client.interfaces.rest.api.item

Examples of org.multibit.mbm.client.interfaces.rest.api.item.ItemDto


      .retrieveBySku("0575088893");

    // Assert
    assertTrue(optionalItem.isPresent());

    ItemDto actualItem = optionalItem.get();

    assertEquals("0575088893",actualItem.getSKU());
    assertEquals("The Quantum Thief",actualItem.getOptionalProperties().get("title"));
  }
View Full Code Here


    List<ItemDto> clientItems = Lists.newArrayList();
    for (Map.Entry<String, ReadableRepresentation> itemResource : rr.getResources()) {

      List<Link> links = itemResource.getValue().getLinks();

      ItemDto clientItem = ClientItemHandler.buildClientItem(itemResource.getValue().getProperties(), links);

      clientItems.add(clientItem);
    }

    return clientItems;
View Full Code Here

    ReadableRepresentation rr = unmarshalHal(hal);

    Map<String, Object> properties = rr.getProperties();
    List<Link> links = rr.getLinks();

    ItemDto item = buildClientItem(properties, links);

    return Optional.of(item);
  }
View Full Code Here

   * @param links      The HAL links
   *
   * @return A PublicItem
   */
  public static ItemDto buildClientItem(Map<String, Object> properties, List<Link> links) {
    ItemDto item = new ItemDto();

    // Mandatory properties (will cause IllegalStateException if not present)
    item.setSKU(getMandatoryPropertyAsString("sku", properties));
    item.setPrice(getMandatoryPropertyAsString("price", properties));
    item.setTaxRate(getMandatoryPropertyAsString("tax_rate", properties));

    // Optional direct properties
    if (properties.containsKey("gtin")) {
      Object gtin = properties.get("gtin");
      if (gtin != null) {
        item.setGTIN((String) gtin);
      }
    }

    // Optional properties
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
      if ("sku".equals(entry.getKey()) ||
        "gtin".equals(entry.getKey()) ||
        "price".equals(entry.getKey()) ||
        "tax_rate".equals(entry.getKey())) {
        continue;
      }
      item.getOptionalProperties().put(entry.getKey(), (String) entry.getValue());
    }

    // Optional links
    for (Link link : links) {
      item.getOptionalProperties().put(link.getRel(), link.getHref());
    }

    return item;
  }
View Full Code Here

*/
public class CopyItem implements DomainAdapter<ItemDto, Item> {

  @Override
  public ItemDto on(Item item) {
    ItemDto dto = new ItemDto();

    dto.setId(item.getId().toString());

    dto.setGTIN(item.getGTIN());
    dto.setSKU(item.getSKU());

    dto.setPrice(item.getLocalPrice().toString());
    dto.setTaxRate(String.valueOf(item.getTaxRate()));

    for (Map.Entry<ItemField, ItemFieldDetail> entry: item.getItemFieldMap().entrySet()) {

      String name = entry.getKey().getPropertyNameSingular();
      String value = entry.getValue().getPrimaryDetail().getContent();

      dto.getOptionalProperties().put(name,value);

    }

    return dto;
  }
View Full Code Here

TOP

Related Classes of org.multibit.mbm.client.interfaces.rest.api.item.ItemDto

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.