Search in sources :

Example 96 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class HierarchyManagerImpl method getName.

/**
     * {@inheritDoc}
     */
public Name getName(NodeId id, NodeId parentId) throws ItemNotFoundException, RepositoryException {
    NodeState parentState;
    try {
        parentState = (NodeState) getItemState(parentId);
    } catch (NoSuchItemStateException nsis) {
        String msg = "failed to resolve name of " + id;
        log.debug(msg);
        throw new ItemNotFoundException(id.toString());
    } catch (ItemStateException ise) {
        String msg = "failed to resolve name of " + id;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
    ChildNodeEntry entry = getChildNodeEntry(parentState, id);
    if (entry == null) {
        String msg = "failed to resolve name of " + id;
        log.debug(msg);
        throw new ItemNotFoundException(msg);
    }
    return entry.getName();
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 97 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class HierarchyManagerImpl method getName.

/**
     * {@inheritDoc}
     */
public Name getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (itemId.denotesNode()) {
        NodeId nodeId = (NodeId) itemId;
        try {
            NodeState nodeState = (NodeState) getItemState(nodeId);
            NodeId parentId = getParentId(nodeState);
            if (parentId == null) {
                // FIXME
                return EMPTY_NAME;
            }
            return getName(nodeId, parentId);
        } catch (NoSuchItemStateException nsis) {
            String msg = "failed to resolve name of " + nodeId;
            log.debug(msg);
            throw new ItemNotFoundException(nodeId.toString());
        } catch (ItemStateException ise) {
            String msg = "failed to resolve name of " + nodeId;
            log.debug(msg);
            throw new RepositoryException(msg, ise);
        }
    } else {
        return ((PropertyId) itemId).getName();
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 98 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemSaveOperation method restoreTransientItems.

/**
     * walk through list of transient states and re-apply transient changes
     */
private void restoreTransientItems(SessionContext context, Iterable<ItemState> items) {
    ItemManager itemMgr = context.getItemManager();
    SessionItemStateManager stateMgr = context.getItemStateManager();
    for (ItemState itemState : items) {
        ItemId id = itemState.getId();
        ItemImpl item;
        try {
            if (stateMgr.isItemStateInAttic(id)) {
                // If an item has been removed and then again created, the
                // item is lost after persistTransientItems() and the
                // TransientItemStateManager will bark because of a deleted
                // state in its attic. We therefore have to forge a new item
                // instance ourself.
                item = itemMgr.createItemInstance(itemState);
                itemState.setStatus(ItemState.STATUS_NEW);
            } else {
                try {
                    item = itemMgr.getItem(id, false);
                } catch (ItemNotFoundException infe) {
                    // itemState probably represents a 'new' item and the
                    // ItemImpl instance wrapping it has already been gc'ed;
                    // we have to re-create the ItemImpl instance
                    item = itemMgr.createItemInstance(itemState);
                    itemState.setStatus(ItemState.STATUS_NEW);
                }
            }
            // for persistent nodes undo effect of item.makePersistent()
            if (item.isNode()) {
                NodeImpl node = (NodeImpl) item;
                node.restoreTransient((NodeState) itemState);
            } else {
                PropertyImpl prop = (PropertyImpl) item;
                prop.restoreTransient((PropertyState) itemState);
            }
        } catch (RepositoryException re) {
            // something went wrong, log exception and carry on
            String msg = itemMgr.safeGetJCRPath(id) + ": failed to restore transient state";
            if (log.isDebugEnabled()) {
                log.warn(msg, re);
            } else {
                log.warn(msg);
            }
        }
    }
}
Also used : ItemState(org.apache.jackrabbit.core.state.ItemState) RepositoryException(javax.jcr.RepositoryException) SessionItemStateManager(org.apache.jackrabbit.core.state.SessionItemStateManager) ItemId(org.apache.jackrabbit.core.id.ItemId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 99 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemManager method getDefinition.

NodeDefinitionImpl getDefinition(NodeState state) throws RepositoryException {
    if (state.getId().equals(sessionContext.getRootNodeId())) {
        // special handling required for root node
        return rootNodeDef;
    }
    NodeId parentId = state.getParentId();
    if (parentId == null) {
        // removed state has parentId set to null
        // get from overlayed state
        ItemState overlaid = state.getOverlayedState();
        if (overlaid != null) {
            parentId = overlaid.getParentId();
        } else {
            throw new InvalidItemStateException("Could not find parent of node " + state.getNodeId());
        }
    }
    NodeState parentState = null;
    try {
        // access the parent state circumventing permission check, since
        // read permission on the parent isn't required in order to retrieve
        // a node's definition. see also JCR-2418
        ItemData parentData = getItemData(parentId, null, false);
        parentState = (NodeState) parentData.getState();
        if (state.getParentId() == null) {
            // that used to be the actual parent
            if (parentState.getStatus() == ItemState.STATUS_NEW) {
                // force getting parent from attic
                parentState = null;
            } else {
                parentState = (NodeState) parentState.getOverlayedState();
            }
        }
    } catch (ItemNotFoundException e) {
    // parent probably removed, get it from attic. see below
    }
    if (parentState == null) {
        try {
            // use overlayed state if available
            parentState = (NodeState) sism.getAttic().getItemState(parentId).getOverlayedState();
        } catch (ItemStateException ex) {
            throw new RepositoryException(ex);
        }
    }
    // get child node entry
    ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
    if (cne == null) {
        throw new InvalidItemStateException("Could not find child " + state.getNodeId() + " of node " + parentState.getNodeId());
    }
    NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
    try {
        EffectiveNodeType ent = ntReg.getEffectiveNodeType(parentState.getNodeTypeName(), parentState.getMixinTypeNames());
        QNodeDefinition def;
        try {
            def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
        } catch (ConstraintViolationException e) {
            // fallback to child node definition of a nt:unstructured
            ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
            def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
            log.warn("Fallback to nt:unstructured due to unknown child " + "node definition for type '" + state.getNodeTypeName() + "'");
        }
        return sessionContext.getNodeTypeManager().getNodeDefinition(def);
    } catch (NodeTypeConflictException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 100 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException 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);
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) 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