for (ItemState state : changeLog.modifiedStates()) {
if (state instanceof NodeState) {
// Check the next node
NodeState modifiedNodeState = (NodeState) state;
NodeId id = modifiedNodeState.getNodeId();
// Check whether to overlayed state is present for determining diffs
NodeState overlayedState = (NodeState) modifiedNodeState.getOverlayedState();
if (overlayedState == null) {
String message = "Unable to load persistent state for modified node " + id;
log.error(message);
throw new ItemStateException(message);
}
// Check the parent
NodeId parentId = modifiedNodeState.getParentId();
NodeId oldParentId = overlayedState.getParentId();
// The parent should not be deleted
if (parentId != null && changeLog.deleted(parentId)) {
String message = "Parent of node with id " + id + " has been deleted";
log.error(message);
throw new ItemStateException(message);
}
if (parentId != null && changeLog.has(parentId)) {
checkParent(changeLog, modifiedNodeState, parentId);
}
if (!(parentId == null && oldParentId == null)
&& !parentId.equals(oldParentId)) {
// This node (not the root) has been moved; check
// whether the parent has been modified as well
if (changeLog.has(parentId)) {
checkParent(changeLog, modifiedNodeState, parentId);
} else if (!isShareable(modifiedNodeState)) {
String message = "New parent of node " + id + " is not present in the changelog " + id;
log.error(message);
throw new ItemStateException(message);
}
// The old parent must be modified or deleted
if (!changeLog.isModified(oldParentId) && !changeLog.deleted(oldParentId)) {
String message = "Node with id " + id
+ " has been moved, but the original parent is not part of the changelog: "
+ oldParentId;
log.error(message);
throw new ItemStateException(message);
}
}
// Check all assigned children
for (ChildNodeEntry entry : modifiedNodeState.getChildNodeEntries()) {
NodeId childId = entry.getId();
// Check whether this node has a deleted childid
if (changeLog.deleted(childId) && !changeLog.has(childId)) { // Versionable
String message = "Node with id " + id + " has a deleted childid: " + childId;
log.error(message);
throw new ItemStateException(message);
}
if (changeLog.has(childId)) {
NodeState childState = (NodeState) changeLog.get(childId);
checkParent(changeLog, childState, id);
}
}
// Check all children the have been added
for (ChildNodeEntry entry : modifiedNodeState.getAddedChildNodeEntries()) {
NodeId childId = entry.getId();
if (!changeLog.has(childId)) {
String message = "ChildId " + childId + " has been added to parent " + id
+ ", but is not present in the changelog";
log.error(message);
throw new ItemStateException(message);
}
}
// Check all children the have been moved or removed
for (ChildNodeEntry entry : modifiedNodeState.getRemovedChildNodeEntries()) {
NodeId childId = entry.getId();
if (!changeLog.isModified(childId) && !changeLog.deleted(childId)) {
String message = "Child node entry with id " + childId
+ " has been removed, but is not present in the changelog";
log.error(message);
throw new ItemStateException(message);