Search in sources :

Example 86 with ItemNotFoundException

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();
        }
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 87 with ItemNotFoundException

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;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException) HashSet(java.util.HashSet)

Example 88 with ItemNotFoundException

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();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 89 with ItemNotFoundException

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
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 90 with ItemNotFoundException

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());
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)139 RepositoryException (javax.jcr.RepositoryException)61 Node (javax.jcr.Node)44 Path (org.apache.jackrabbit.spi.Path)25 PathNotFoundException (javax.jcr.PathNotFoundException)23 NodeId (org.apache.jackrabbit.core.id.NodeId)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)16 IOException (java.io.IOException)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodeState (org.apache.jackrabbit.core.state.NodeState)14 Name (org.apache.jackrabbit.spi.Name)14 AccessDeniedException (javax.jcr.AccessDeniedException)13 HttpResponse (org.apache.http.HttpResponse)13 DavException (org.apache.jackrabbit.webdav.DavException)13 ItemExistsException (javax.jcr.ItemExistsException)12 Session (javax.jcr.Session)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)10