use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryChecker method checkVersionHistory.
private void checkVersionHistory(NodeState node) {
String message = null;
NodeId nid = node.getNodeId();
boolean isVersioned = node.hasPropertyName(JCR_VERSIONHISTORY);
NodeId vhid = null;
try {
String type = isVersioned ? "in-use" : "candidate";
log.debug("Checking " + type + " version history of node {}", nid);
String intro = "Removing references to an inconsistent " + type + " version history of node " + nid;
message = intro + " (getting the VersionInfo)";
VersionHistoryInfo vhi = versionManager.getVersionHistoryInfoForNode(node);
if (vhi != null) {
// get the version history's node ID as early as possible
// so we can attempt a fixup even when the next call fails
vhid = vhi.getVersionHistoryId();
}
message = intro + " (getting the InternalVersionHistory)";
InternalVersionHistory vh = null;
try {
vh = versionManager.getVersionHistoryOfNode(nid);
} catch (ItemNotFoundException ex) {
// it's ok if we get here if the node didn't claim to be versioned
if (isVersioned) {
throw ex;
}
}
if (vh == null) {
if (isVersioned) {
message = intro + "getVersionHistoryOfNode returned null";
throw new InconsistentVersioningState(message);
}
} else {
vhid = vh.getId();
// additional checks, see JCR-3101
message = intro + " (getting the version names failed)";
Name[] versionNames = vh.getVersionNames();
boolean seenRoot = false;
for (Name versionName : versionNames) {
seenRoot |= JCR_ROOTVERSION.equals(versionName);
log.debug("Checking version history of node {}, version {}", nid, versionName);
message = intro + " (getting version " + versionName + " failed)";
InternalVersion v = vh.getVersion(versionName);
message = intro + "(frozen node of root version " + v.getId() + " missing)";
if (null == v.getFrozenNode()) {
throw new InconsistentVersioningState(message);
}
}
if (!seenRoot) {
message = intro + " (root version is missing)";
throw new InconsistentVersioningState(message);
}
}
} catch (InconsistentVersioningState e) {
log.info(message, e);
NodeId nvhid = e.getVersionHistoryNodeId();
if (nvhid != null) {
if (vhid != null && !nvhid.equals(vhid)) {
log.error("vhrid returned with InconsistentVersioningState does not match the id we already had: " + vhid + " vs " + nvhid);
}
vhid = nvhid;
}
removeVersionHistoryReferences(node, vhid);
} catch (Exception e) {
log.info(message, e);
removeVersionHistoryReferences(node, vhid);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class InternalVersionManagerBase method getVersionHistoryOfNode.
/**
* {@inheritDoc}
*/
public InternalVersionHistory getVersionHistoryOfNode(NodeId id) throws RepositoryException {
VersioningLock.ReadLock lock = acquireReadLock();
try {
String uuid = id.toString();
Name name = getName(uuid);
NodeStateEx parent = getParentNode(getHistoryRoot(), uuid, null);
if (parent != null && parent.hasNode(name)) {
NodeStateEx history = parent.getNode(name, 1);
if (history == null) {
throw new InconsistentVersioningState("Unexpected failure to get child node " + name + " on parent node" + parent.getNodeId());
}
return getVersionHistory(history.getNodeId());
} else {
throw new ItemNotFoundException("Version history of node " + id + " not found.");
}
} finally {
lock.release();
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class PathPropertyTest method testGetNode.
/**
* Since JCR 2.0 a path property can be dereferenced if it points to a
* Node.
* TODO: create several tests out of this one
*/
public void testGetNode() throws RepositoryException {
if (!multiple) {
String nodePath = prop.getParent().getPath();
String propName = prop.getName();
// absolute nodes path
prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
String value = prop.getString();
Node n = prop.getNode();
assertEquals("The path of the dereferenced property must be equal to the value", n.getPath(), value);
assertTrue("The property value must be resolved to the correct node.", prop.getParent().isSame(n));
// relative node path
prop.getParent().setProperty(propName, ".", PropertyType.PATH);
n = prop.getNode();
assertTrue("The property value must be resolved to the correct node.", prop.getParent().getNode(".").isSame(n));
// non-existing property path
while (session.nodeExists(nodePath)) {
nodePath += "x";
}
prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
try {
prop.getNode();
fail("Calling Property.getNode() for a PATH value that doesn't have a corresponding Node, ItemNotFoundException is expected");
} catch (ItemNotFoundException e) {
//ok
}
} else {
try {
prop.getNode();
fail("Property.getNode() called on a multivalue property " + "should throw a ValueFormatException.");
} catch (ValueFormatException vfe) {
//ok
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class UpdateTest method testUpdateAddsMissingSubtree.
public void testUpdateAddsMissingSubtree() throws RepositoryException, NotExecutableException {
String srcWorkspace = getAnotherWorkspace();
// get the root node in the second workspace
Session session2 = getHelper().getSuperuserSession(srcWorkspace);
try {
// make sure the source-session has the corresponding node.
Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
// create test node in second workspace
Node aNode2 = testRootW2.addNode(nodeName1, testNodeType);
aNode2.addNode(nodeName2, testNodeType);
aNode2.setProperty(propertyName2, "test");
Property p2 = testRootW2.setProperty(propertyName1, "test");
testRootW2.save();
// call the update method on test node in default workspace
testRootNode.update(srcWorkspace);
// ok check if the child has been added
boolean allPresent = testRootNode.hasNode(nodeName1) && testRootNode.hasNode(nodeName1 + "/" + nodeName2) && testRootNode.hasProperty(nodeName1 + "/" + propertyName2) && testRootNode.hasProperty(propertyName1);
assertTrue("Node updated with Node.update() should have received childrens", allPresent);
} catch (PathNotFoundException e) {
throw new NotExecutableException();
} catch (ItemNotFoundException e) {
throw new NotExecutableException();
} finally {
session2.logout();
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class UpdateTest method testUpdateRemovesExtraProperty.
public void testUpdateRemovesExtraProperty() throws RepositoryException, NotExecutableException {
// create test node in default workspace
testRootNode.setProperty(propertyName2, "test");
testRootNode.save();
String srcWorkspace = getAnotherWorkspace();
// get the root node in the second workspace
Session session2 = getHelper().getSuperuserSession(srcWorkspace);
try {
// make sure the source-session has the corresponding node.
Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
if (testRootW2.hasProperty(propertyName2)) {
throw new NotExecutableException();
}
// call the update method on test node in default workspace
testRootNode.update(srcWorkspace);
// ok first check if node has no longer properties
assertFalse("Node updated with Node.update() should have property removed", testRootNode.hasProperty(propertyName2));
} catch (PathNotFoundException e) {
throw new NotExecutableException();
} catch (ItemNotFoundException e) {
throw new NotExecutableException();
} finally {
session2.logout();
}
}
Aggregations