*/
public GanttChartData readGanttObjects(final GanttChartDO obj)
{
final TaskTree taskTree = taskDao.getTaskTree();
final GanttChartData ganttChartData = Task2GanttTaskConverter.convertToGanttObjectTree(taskTree, obj.getTask());
final XmlObjectReader reader = new XmlObjectReader() {
@Override
protected Object newInstance(final Class< ? > clazz, final Element el, final String attrName, final String attrValue)
{
if ("predecessor".equals(attrName) == true && XmlConstants.NULL_IDENTIFIER.equals(attrValue) == true) {
// Field should set to null.
return Status.IGNORE;
}
if (GanttTask.class.isAssignableFrom(clazz) == true) {
final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el);
if (ganttObject == null) {
return new GanttTaskImpl(); // Gantt task not related to a ProjectForge task.
}
return ganttObject;
} else if (Collection.class.isAssignableFrom(clazz) == true) {
final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el.getParent());
if (ganttObject != null && ganttObject.getChildren() != null) {
return ganttObject.getChildren();
}
}
return null;
}
@Override
protected boolean addCollectionEntry(final Collection< ? > col, final Object obj, final Element el)
{
if (obj instanceof GanttTask == false) {
return false;
}
final GanttTask ganttTask = (GanttTask)obj;
if (ganttChartData.findById(ganttTask.getId()) != null) {
// GanttTask already added to the Gantt object tree.
return true;
}
if (taskTree.getTaskById((Integer)ganttTask.getId()) != null) {
// External task, so ignore it:
return true;
}
return false;
}
@Override
protected void setField(final Field field, final Object obj, final Object value, final Element element, final String key,
final String attrValue)
{
if (XmlConstants.NULL_IDENTIFIER.equals(attrValue) == true) {
// Overwrite value from task with null.
setField(field, obj, null);
return;
}
super.setField(field, obj, value, element, key, attrValue);
}
};
reader.setAliasMap(getXmlGanttObjectAliasMap()).setIgnoreEmptyCollections(true);
reader.read(obj.getGanttObjectsAsXml()); // Ignore the return value. If the task tree has changed, the task tree of root rules.
return ganttChartData;
}