// custom fields
Map<Field.Name, Field> fields = item.getSpace().getMetadata().getFields();
for(Field.Name fieldName : item.getSpace().getMetadata().getFieldOrder()) {
Object value = item.getValue(fieldName);
if(value != null) {
Field field = fields.get(fieldName);
Element customField = root.addElement(fieldName.getText());
customField.addAttribute("label", field.getLabel());
if(field.isDropDownType()) {
customField.addAttribute("optionId", value + "");
}
customField.addText(item.getCustomValue(fieldName));
}
}
// timestamp
Element timestamp = root.addElement("timestamp");
timestamp.addText(DateUtils.formatTimeStamp(item.getTimeStamp()));
// history
if (item.getHistory() != null) {
Element historyRoot = root.addElement("history");
for(History history : item.getHistory()) {
Element event = historyRoot.addElement("event");
// index
event.addAttribute("eventId", (history.getIndex() + 1) + "");
// logged by
Element historyLoggedBy = event.addElement("loggedBy");
// historyLoggedBy.addAttribute("userId", history.getLoggedBy().getId() + "");
historyLoggedBy.addText(history.getLoggedBy().getName());
// status
if(history.getStatus() != null) {
Element historyStatus = event.addElement("status");
historyStatus.addAttribute("statusId", history.getStatus() + "");
historyStatus.addText(history.getStatusValue());
}
// assigned to
if(history.getAssignedTo() != null) {
Element historyAssignedTo = event.addElement("assignedTo");
// historyAssignedTo.addAttribute("userId", history.getAssignedTo().getId() + "");
historyAssignedTo.addText(history.getAssignedTo().getName());
}
// attachment
if(history.getAttachment() != null) {
Element historyAttachment = event.addElement("attachment");
historyAttachment.addAttribute("attachmentId", history.getAttachment().getId() + "");
historyAttachment.addText(history.getAttachment().getFileName());
}
// comment
if(history.getComment() != null) {
Element historyComment = event.addElement("comment");
historyComment.addText(history.getComment());
}
// timestamp
Element historyTimestamp = event.addElement("timestamp");
historyTimestamp.addText(DateUtils.formatTimeStamp(history.getTimeStamp()));
// custom fields
List<Field> editable = item.getSpace().getMetadata().getEditableFields();
for(Field field : editable) {
Object value = history.getValue(field.getName());
if(value != null) {
Element historyCustomField = event.addElement(field.getName().getText());
historyCustomField.addAttribute("label", field.getLabel());
if(field.isDropDownType()) {
historyCustomField.addAttribute("optionId", value + "");
}
historyCustomField.addText(history.getCustomValue(field.getName()));
}
}
}
}
return root;