* @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;
}