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