use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class BatchedItemOperations method checkRemoveNode.
/**
* Checks if removing the given target node from the specifed parent
* is allowed in the current context.
*
* @param targetState
* @param parentId
* @param options bit-wise OR'ed flags specifying the checks that should be
* performed; any combination of the following constants:
* <ul>
* <li><code>{@link #CHECK_ACCESS}</code>: make sure
* current session is granted read access on parent
* and remove privilege on target node</li>
* <li><code>{@link #CHECK_LOCK}</code>: make sure
* there's no foreign lock on parent node</li>
* <li><code>{@link #CHECK_CHECKED_OUT}</code>: make sure
* parent node is checked-out</li>
* <li><code>{@link #CHECK_CONSTRAINTS}</code>:
* make sure no node type constraints would be violated</li>
* <li><code>{@link #CHECK_REFERENCES}</code>:
* make sure no references exist on target node</li>
* <li><code>{@link #CHECK_HOLD}</code>: check for effective holds preventing the add operation</li>
* <li><code>{@link #CHECK_RETENTION}</code>: check for effective retention policy preventing the add operation</li>
* </ul>
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws LockException
* @throws ItemNotFoundException
* @throws ReferentialIntegrityException
* @throws RepositoryException
*/
public void checkRemoveNode(NodeState targetState, NodeId parentId, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException {
if (targetState.getParentId() == null) {
// root or orphaned node
throw new ConstraintViolationException("cannot remove root node");
}
Path targetPath = hierMgr.getPath(targetState.getNodeId());
NodeState parentState = getNodeState(parentId);
Path parentPath = hierMgr.getPath(parentId);
if ((options & CHECK_LOCK) == CHECK_LOCK) {
// make sure there's no foreign lock on parent node
verifyUnlocked(parentPath);
}
if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
// make sure parent node is checked-out
verifyCheckedOut(parentPath);
}
if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
try {
AccessManager accessMgr = context.getAccessManager();
// make sure current session is granted read access on parent node
if (!accessMgr.isGranted(targetPath, Permission.READ)) {
throw new PathNotFoundException(safeGetJCRPath(targetPath));
}
// make sure current session is allowed to remove target node
if (!accessMgr.isGranted(targetPath, Permission.REMOVE_NODE)) {
throw new AccessDeniedException(safeGetJCRPath(targetPath) + ": not allowed to remove node");
}
} catch (ItemNotFoundException infe) {
String msg = "internal error: failed to check access rights for " + safeGetJCRPath(targetPath);
log.debug(msg);
throw new RepositoryException(msg, infe);
}
}
if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
QItemDefinition parentDef = context.getItemManager().getDefinition(parentState).unwrap();
if (parentDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(parentId) + ": cannot remove child node of protected parent node");
}
QItemDefinition targetDef = context.getItemManager().getDefinition(targetState).unwrap();
if (targetDef.isMandatory()) {
throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove mandatory node");
}
if (targetDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove protected node");
}
}
if ((options & CHECK_REFERENCES) == CHECK_REFERENCES) {
EffectiveNodeType ent = getEffectiveNodeType(targetState);
if (ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
NodeId targetId = targetState.getNodeId();
if (stateMgr.hasNodeReferences(targetId)) {
try {
NodeReferences refs = stateMgr.getNodeReferences(targetId);
if (refs.hasReferences()) {
throw new ReferentialIntegrityException(safeGetJCRPath(targetPath) + ": cannot remove node with references");
}
} catch (ItemStateException ise) {
String msg = "internal error: failed to check references on " + safeGetJCRPath(targetPath);
log.error(msg, ise);
throw new RepositoryException(msg, ise);
}
}
}
}
RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
if ((options & CHECK_HOLD) == CHECK_HOLD) {
if (retentionReg.hasEffectiveHold(targetPath, true)) {
throw new RepositoryException("Unable to perform removal. Node is affected by a hold.");
}
}
if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
if (retentionReg.hasEffectiveRetention(targetPath, true)) {
throw new RepositoryException("Unable to perform removal. Node is affected by a retention.");
}
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class CachingHierarchyManager method nodeRemoved.
/**
* {@inheritDoc}
*/
public void nodeRemoved(NodeState state, Name name, int index, NodeId id) {
synchronized (cacheMonitor) {
if (idCache.containsKey(state.getNodeId())) {
// Optimization: ignore notifications for nodes that are not in the cache
try {
Path path = PathFactoryImpl.getInstance().create(getPath(state.getNodeId()), name, index, true);
nodeRemoved(state, path, id);
checkConsistency();
} catch (PathNotFoundException e) {
log.warn("Unable to get path of node " + state.getNodeId() + ", event ignored.");
} catch (MalformedPathException e) {
log.warn("Unable to create path of " + id, e);
} catch (ItemStateException e) {
log.warn("Unable to find item " + id, e);
} catch (ItemNotFoundException e) {
log.warn("Unable to get path of " + state.getNodeId(), e);
} catch (RepositoryException e) {
log.warn("Unable to get path of " + state.getNodeId(), e);
}
} else if (state.getParentId() == null && idCache.containsKey(id)) {
// A top level node was removed
evictAll(id, true);
}
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class CachingHierarchyManager method nodeAdded.
/**
* {@inheritDoc}
*/
public void nodeAdded(NodeState state, Name name, int index, NodeId id) {
synchronized (cacheMonitor) {
if (idCache.containsKey(state.getNodeId())) {
// Optimization: ignore notifications for nodes that are not in the cache
try {
Path path = PathFactoryImpl.getInstance().create(getPath(state.getNodeId()), name, index, true);
nodeAdded(state, path, id);
checkConsistency();
} catch (PathNotFoundException e) {
log.warn("Unable to get path of node " + state.getNodeId() + ", event ignored.");
} catch (MalformedPathException e) {
log.warn("Unable to create path of " + id, e);
} catch (ItemNotFoundException e) {
log.warn("Unable to find item " + state.getNodeId(), e);
} catch (ItemStateException e) {
log.warn("Unable to find item " + id, e);
} catch (RepositoryException e) {
log.warn("Unable to get path of " + state.getNodeId(), e);
}
} else if (state.getParentId() == null && idCache.containsKey(id)) {
// A top level node was added
evictAll(id, true);
}
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class AddNodeOperation method perform.
public Node perform(SessionContext context) throws RepositoryException {
ItemManager itemMgr = context.getItemManager();
// Get the canonical path of the new node
Path path;
try {
path = PathFactoryImpl.getInstance().create(node.getPrimaryPath(), context.getQPath(relPath), true);
} catch (NameException e) {
throw new RepositoryException("Failed to resolve path " + relPath + " relative to " + node, e);
}
// Check that the last path element is a simple name
if (!path.denotesName() || path.getIndex() != Path.INDEX_UNDEFINED) {
throw new RepositoryException("Invalid last path element for adding node " + relPath + " relative to " + node);
}
// Get the parent node instance
NodeImpl parentNode;
Path parentPath = path.getAncestor(1);
try {
parentNode = itemMgr.getNode(parentPath);
} catch (PathNotFoundException e) {
if (itemMgr.propertyExists(parentPath)) {
throw new ConstraintViolationException("Unable to add a child node to property " + context.getJCRPath(parentPath));
}
throw e;
} catch (AccessDeniedException ade) {
throw new PathNotFoundException("Failed to resolve path " + relPath + " relative to " + node);
}
// Resolve node type name (if any)
Name typeName = null;
if (nodeTypeName != null) {
typeName = context.getQName(nodeTypeName);
}
// Check that the given UUID (if any) does not already exist
NodeId id = null;
if (uuid != null) {
id = new NodeId(uuid);
if (itemMgr.itemExists(id)) {
throw new ItemExistsException("A node with this UUID already exists: " + uuid);
}
}
return parentNode.addNode(path.getName(), typeName, id);
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class TraversingNodeResolver method findNode.
/**
* @inheritDoc
*/
@Override
public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException {
String sr = getSearchRoot(ntName);
if (getSession().nodeExists(sr)) {
try {
Node root = getSession().getNode(sr);
Set<Node> matchSet = new HashSet<Node>();
collectNodes(value, Collections.singleton(propertyName), ntName, root.getNodes(), matchSet, true, 1);
NodeIterator it = new NodeIteratorAdapter(matchSet);
if (it.hasNext()) {
return it.nextNode();
}
} catch (PathNotFoundException e) {
// should not get here
log.warn("Error while retrieving node " + sr);
}
}
// else: searchRoot does not exist yet -> omit the search
return null;
}
Aggregations