/**
* Ignores all field values in output which are equal to the values of the corresponding task.
*/
private XmlObjectWriter getXmlGanttObjectWriter()
{
final XmlObjectWriter xmlGanttObjectWriter = new XmlObjectWriter() {
@Override
protected boolean ignoreField(final Object obj, final Field field)
{
if (super.ignoreField(obj, field) == true) {
return true;
}
if (obj instanceof GanttTask) {
final TaskTree taskTree = taskDao.getTaskTree();
final String fieldName = field.getName();
if ("id".equals(fieldName) == true) {
// Id should always be equals and needed in output for the identification of the gantt object.
return false;
}
if ("description".equals(fieldName) == true) {
return true;
}
final GanttTask ganttObject = (GanttTask) obj;
final TaskDO task = taskTree.getTaskById((Integer) ganttObject.getId());
if (task != null) {
if ("predecessor".equals(field.getName()) == true) {
// Predecessor unmodified?
return NumberHelper.isEqual((Integer) ganttObject.getPredecessorId(), task.getGanttPredecessorId());
}
String taskFieldname = fieldMapping.get(fieldName);
if (taskFieldname == null) {
taskFieldname = fieldName;
}
for (final Field taskField : taskFields) {
if (taskFieldname.equals(taskField.getName()) == true) {
final Object value = BeanHelper.getFieldValue(obj, field);
final Object taskValue = BeanHelper.getFieldValue(task, taskField);
if (value instanceof BigDecimal) {
// Needed, because 10.0 is not equal to 10.000 (if scale is different).
return NumberHelper.isEqual((BigDecimal) value, (BigDecimal) taskValue);
}
return ObjectUtils.equals(value, taskValue) == true;
}
}
}
}
return false;
}
@Override
protected void writeField(final Field field, final Object obj, final Object fieldValue, final XmlField annotation,
final Element element)
{
if (GanttTask.class.isAssignableFrom(field.getDeclaringClass()) == true) {
final String fieldName = field.getName();
if ("id".equals(fieldName) == false) {
final TaskTree taskTree = taskDao.getTaskTree();
final GanttTask ganttObject = (GanttTask) obj;
final TaskDO task = taskTree.getTaskById((Integer) ganttObject.getId());
if (task != null) {
String taskFieldname = fieldMapping.get(fieldName);
if (taskFieldname == null) {
taskFieldname = fieldName;
}
for (final Field taskField : taskFields) {
if (taskFieldname.equals(taskField.getName()) == true) {
final Object value = BeanHelper.getFieldValue(obj, field);
final Object taskValue = BeanHelper.getFieldValue(task, taskField);
if (taskValue != null && value == null) {
// Reader should interpret this as null, so value from task will be overwritten by null.
element.addAttribute(field.getName(), XmlConstants.NULL_IDENTIFIER);
return;
}
}
}
}
}
}
super.writeField(field, obj, fieldValue, annotation, element);
}
};
xmlGanttObjectWriter.setAliasMap(getXmlGanttObjectAliasMap());
return xmlGanttObjectWriter;
}