use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class WorkspaceImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos) throws RepositoryException {
if (aborted) {
// the import has been aborted, get outta here...
return;
}
boolean succeeded = false;
NodeState parent;
try {
// check sanity of workspace/session first
wsp.sanityCheck();
parent = parents.peek();
// process node
NodeState node = null;
NodeId id = nodeInfo.getId();
Name nodeName = nodeInfo.getName();
Name ntName = nodeInfo.getNodeTypeName();
Name[] mixins = nodeInfo.getMixinNames();
if (parent == null) {
// parent node was skipped, skip this child node too
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping node " + nodeName);
return;
}
if (parent.hasChildNodeEntry(nodeName)) {
// a node with that name already exists...
ChildNodeEntry entry = parent.getChildNodeEntry(nodeName, 1);
NodeId idExisting = entry.getId();
NodeState existing = (NodeState) itemOps.getItemState(idExisting);
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, existing.getNodeTypeName(), parent);
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings,
// check for potential conflicts
EffectiveNodeType entExisting = itemOps.getEffectiveNodeType(existing);
if (def.isProtected() && entExisting.includesNodeType(ntName)) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + itemOps.safeGetJCRPath(existing.getNodeId()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(ntName)) {
// this node has already been auto-created,
// no need to create it
node = existing;
} else {
// (see http://issues.apache.org/jira/browse/JCR-1128)
if (!(idExisting.equals(id) && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
throw new ItemExistsException(itemOps.safeGetJCRPath(existing.getNodeId()));
}
// fall through
}
}
}
if (node == null) {
// there's no node with that name...
if (id == null) {
// no potential uuid conflict, always create new node
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;
}
// check if new node can be added (check access rights &
// node type constraints only, assume locking & versioning status
// and retention/hold has already been checked on ancestor)
itemOps.checkAddNode(parent, nodeName, ntName, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
// do create new node
node = itemOps.createNodeState(parent, nodeName, ntName, mixins, null, def);
} else {
// potential uuid conflict
try {
NodeState conflicting = itemOps.getNodeState(id);
// resolve uuid conflict
node = resolveUUIDConflict(parent, conflicting, nodeInfo);
if (node == null) {
// no new node has been created, so skip this node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping existing node: " + nodeName);
return;
}
} catch (ItemNotFoundException e) {
// create new with given uuid
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;
}
// check if new node can be added (check access rights &
// node type constraints only, assume locking & versioning status
// and retention/hold has already been checked on ancestor)
itemOps.checkAddNode(parent, nodeName, ntName, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
// do create new node
node = itemOps.createNodeState(parent, nodeName, ntName, mixins, id, def);
}
}
}
// process properties
for (PropInfo propInfo : propInfos) {
processProperty(node, propInfo);
}
// store affected nodes
itemOps.store(node);
itemOps.store(parent);
// push current node onto stack of parents
parents.push(node);
succeeded = true;
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
aborted = true;
itemOps.cancel();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class VersionManagerImplBase method collectBaseVersions.
/**
* Collects the base versions for the workspace configuration referenced by
* the given config node.
* @param config the config
* @return the id of the new base version
* @throws RepositoryException if an error occurs
*/
private Set<NodeId> collectBaseVersions(NodeStateEx config) throws RepositoryException {
NodeId rootId = config.getPropertyValue(NameConstants.JCR_ROOT).getNodeId();
NodeStateEx root = getNodeStateEx(rootId);
if (root == null) {
String msg = "Configuration root node for " + safeGetJCRPath(config) + " not found.";
log.error(msg);
throw new ItemNotFoundException(msg);
}
Set<NodeId> baseVersions = new HashSet<NodeId>();
collectBaseVersions(root, baseVersions);
return baseVersions;
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class AccessManagerTest method testCheckPermissionWithUnknowId.
public void testCheckPermissionWithUnknowId() throws RepositoryException, NotExecutableException {
Session s = getHelper().getReadOnlySession();
NodeId id = NodeId.randomId();
try {
AccessManager acMgr = getAccessManager(s);
acMgr.checkPermission(id, AccessManager.READ);
fail("AccessManager.checkPermission should throw ItemNotFoundException with a random (unknown) item id.");
} catch (ItemNotFoundException e) {
// ok
} finally {
s.logout();
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class VersionTest method testReadVersionInfo.
public void testReadVersionInfo() throws RepositoryException, NotExecutableException {
Node n = createVersionableNode(testRootNode);
modifyPrivileges(VERSION_STORAGE_PATH, Privilege.JCR_READ, false);
Node n2 = (Node) getTestSession().getItem(n.getPath());
try {
n2.getVersionHistory();
fail();
} catch (AccessDeniedException e) {
// success
} catch (ItemNotFoundException e) {
// success as well
}
try {
n2.getBaseVersion();
fail();
} catch (AccessDeniedException e) {
// success
} catch (ItemNotFoundException e) {
// success as well
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class VersionTest method testReadVersionInfo3.
public void testReadVersionInfo3() throws RepositoryException, NotExecutableException {
Node trn = getTestNode();
modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
modifyPrivileges(trn.getPath(), Privilege.JCR_NODE_TYPE_MANAGEMENT, true);
modifyPrivileges(trn.getPath(), Privilege.JCR_VERSION_MANAGEMENT, true);
modifyPrivileges(VERSION_STORAGE_PATH, Privilege.JCR_READ, false);
Node n = createVersionableNode(trn);
assertTrue(n.isNodeType(mixVersionable));
assertFalse(n.isModified());
try {
n.getVersionHistory();
n.getBaseVersion();
fail("No READ permission in the version storage");
} catch (AccessDeniedException e) {
// success
log.debug(e.getMessage());
} catch (ItemNotFoundException e) {
// success
log.debug(e.getMessage());
}
}
Aggregations