// 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++;
}
}