public void visit(INode node) {
/*
* DO NOT add or delete nodes via editorTreeModel, .....................
* or the CourseEditorTreeNode cetn !! .................................
*/
CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
if (cetn == root && publishNodeIds.contains(cetn.getIdent()) ) {
// root node changed and published
CourseNode clone = (CourseNode)XStreamHelper.xstreamClone(cetn.getCourseNode());
resultingCourseRun.setRootNode(clone);
editorModelModifiedNodes.add(cetn);// TODO:pb: Review Change to fic OLAT-1644
return;
}
if (cetn == root) { // TODO:pb: Review Change to fix OLAT-1644
// root node
CourseNode clone = (CourseNode)XStreamHelper.xstreamClone(cetn.getCourseNode());
resultingCourseRun.setRootNode(clone);
return;
}
/*
* check that root exist in newRunStruct
*/
if (resultingCourseRun.getRootNode() == null) { throw new AssertException("No Root node??"); }
// node is selected by user to be published
boolean publishNode = publishNodeIds.contains(cetn.getIdent());
// this node is already in the runstructure -> keep ident!
boolean alreadyInRun = null != existingRun.getNode(cetn.getCourseNode().getIdent());
// node has changed and exists in the runstructure
boolean dirtyOnly = cetn.isDirty() && !cetn.isDeleted() && !cetn.isNewnode();
boolean unchanged = !cetn.isDirty() && !cetn.isDeleted() && !cetn.isNewnode();
// check if this node is not already somehow no longer interesting
if (skippableNodes.contains(cetn) || editorModelDeletedNodes.contains(cetn)) {
// skip
return;
}
if (!publishNode && alreadyInRun) {
if (unchanged) {
// already published, add it as it is. Silent "re-publish"
addNodeTo(resultingCourseRun, cetn);
} else {
// TODO:pb:REVIEW Change to fix OLAT-1644
// changed in edit but not published => take old from existingRun
addNodeTo(resultingCourseRun, existingRun.getNode(cetn.getIdent()), cetn);
}
return;
} else if (publishNode && !alreadyInRun) {
if (dirtyOnly) {
// publish modified node which was in the run once. Then moved under a
// new node and its former parent is deleted.
addNodeTo(resultingCourseRun, cetn);
editorModelModifiedNodes.add(cetn);
} else if (cetn.isNewnode() && cetn.isDeleted()) {
// publish deletion of a new node
editorModelDeletedNodes.add(cetn);
List getsAlsoDeleted = new ArrayList();
collectSubTreeNodesStartingFrom(cetn, getsAlsoDeleted);
// whole subtree added, marked as being deleted
editorModelDeletedNodes.addAll(getsAlsoDeleted);
return;
} else if (cetn.isNewnode() && !cetn.isDeleted()) {
// publish new node
addNodeTo(resultingCourseRun, cetn);
editorModelInsertedNodes.add(cetn);
return;
} else {
// ...!cetn.isNewnode() && cetn.isDeleted()
// this state is not possible
throw new AssertException("try to publish node [" + cetn.getTitle() + " " + cetn.getIdent()
+ "]which says it is not new but also not in the runstructure.");
}
} else if (publishNode && alreadyInRun) {
if (dirtyOnly) {
// publish modified node
addNodeTo(resultingCourseRun, cetn);
editorModelModifiedNodes.add(cetn);
return;
} else if (!cetn.isNewnode() && cetn.isDeleted()) {
// publish deletion of a node
editorModelDeletedNodes.add(cetn);
List getsAlsoDeleted = new ArrayList();
collectSubTreeNodesStartingFrom(cetn, getsAlsoDeleted);
// whole subtree added, marked as being deleted
editorModelDeletedNodes.addAll(getsAlsoDeleted);
return;
} else if (cetn.isNewnode() && !cetn.isDeleted()) {
// this state is not possible
throw new AssertException(cetn.getTitle() + " - try to publish node which says it is new but also exists in the runstructure.");
} else {
// ...cetn.isNewnode() && cetn.isDeleted()
// this state is not possible
throw new AssertException(cetn.getTitle() + " - try to publish node which says it is new but also exists in the runstructure.");
}
} else {
// ...(!publishNode && !alreadyInRun){
// check condition, and add all subnodes to be skipped
if (!cetn.isNewnode()) {
throw new AssertException(cetn.getTitle()+" - node is not to publish and not in run -> hence it should be isNewnode() == true, but it is not!!"); }
List skippable = new ArrayList();
collectSubTreeNodesStartingFrom(cetn, skippable);
// remember this new node with its subtree as not being published
// there may float a dirty node in the subtree, which got there by
// moving