continue;
}
try {
// analyze child node bundles
final NodePropBundle childBundle = pm.loadBundle(childNodeId);
String message = null;
if (childBundle == null) {
// double check whether we still exist and the child entry is still there
bundle = pm.loadBundle(id);
if (bundle != null) {
boolean stillThere = false;
for (NodePropBundle.ChildNodeEntry entryRetry : bundle.getChildNodeEntries()) {
if (entryRetry.getId().equals(childNodeId)) {
stillThere = true;
break;
}
}
if (stillThere) {
message = "NodeState '" + id
+ "' references inexistent child" + " '"
+ entry.getName() + "' with id " + "'"
+ childNodeId + "'";
log.error(message);
missingChildren.add(entry);
}
} else {
return;
}
} else {
NodeId cp = childBundle.getParentId();
if (!id.equals(cp)) {
// double check whether the child entry is still there
bundle = pm.loadBundle(id);
if (bundle != null) {
boolean stillThere = false;
for (NodePropBundle.ChildNodeEntry entryRetry : bundle.getChildNodeEntries()) {
if (entryRetry.getId().equals(childNodeId)) {
stillThere = true;
break;
}
}
if (stillThere) {
// indeed we have a disconnected child
message = "ChildNode has invalid parent id: '" + cp + "' (instead of '" + id + "')";
log.error(message);
disconnectedChildren.add(entry);
}
} else {
return;
}
}
}
if (message != null) {
addMessage(reports, id, message);
}
} catch (ItemStateException e) {
// problem already logged (loadBundle called with
// logDetailedErrors=true)
addMessage(reports, id, e.getMessage());
}
}
// remove child node entry (if fixing is enabled)
if (fix && (!missingChildren.isEmpty() || !disconnectedChildren.isEmpty())) {
for (NodePropBundle.ChildNodeEntry entry : missingChildren) {
bundle.getChildNodeEntries().remove(entry);
}
for (NodePropBundle.ChildNodeEntry entry : disconnectedChildren) {
bundle.getChildNodeEntries().remove(entry);
}
fixBundle(bundle);
}
// check parent reference
NodeId parentId = bundle.getParentId();
try {
// skip root nodes (that point to itself)
if (parentId != null && !id.toString().endsWith("babecafebabe")) {
NodePropBundle parentBundle = pm.loadBundle(parentId);
if (parentBundle == null) {
// double check whether we still exist and the parent is still the same
bundle = pm.loadBundle(id);
if (bundle != null) {
if (parentId.equals(bundle.getParentId())) {
String message = "NodeState '" + id
+ "' references inexistent parent id '" + parentId
+ "'";
log.error(message);
addMessage(reports, id, message);
if (fix && lostNFoundId != null) {
// add a child to lost+found
NodePropBundle lfBundle = pm.loadBundle(lostNFoundId);
lfBundle.markOld();
String nodeName = id + "-" + System.currentTimeMillis();
lfBundle.addChildNodeEntry(NF.create("", nodeName), id);
pm.storeBundle(lfBundle);
pm.evictBundle(lostNFoundId);
// set lost+found parent
bundle.setParentId(lostNFoundId);