Search in sources :

Example 31 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class BatchedItemOperations method recursiveRemoveNodeState.

// ------------------------------------------------------< private methods >
/**
 * Recursively removes the given node state including its properties and
 * child nodes.
 * <p>
 * The removal of child nodes is subject to the following checks:
 * access rights, locking & versioning status. Referential integrity
 * (references) is checked on commit.
 * <p>
 * Note that the child node entry refering to <code>targetState</code> is
 * <b><i>not</i></b> automatically removed from <code>targetState</code>'s
 * parent.
 *
 * @param targetState
 * @throws RepositoryException if an error occurs
 */
private void recursiveRemoveNodeState(NodeState targetState) throws RepositoryException {
    if (targetState.hasChildNodeEntries()) {
        // remove child nodes
        // use temp array to avoid ConcurrentModificationException
        ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(targetState.getChildNodeEntries());
        // remove from tail to avoid problems with same-name siblings
        for (int i = tmp.size() - 1; i >= 0; i--) {
            ChildNodeEntry entry = tmp.get(i);
            NodeId nodeId = entry.getId();
            try {
                NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
                // check if child node can be removed
                // (access rights, locking & versioning status as well
                // as retention and hold);
                // referential integrity (references) is checked
                // on commit
                checkRemoveNode(nodeState, targetState.getNodeId(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_HOLD | CHECK_RETENTION);
                // remove child node
                recursiveRemoveNodeState(nodeState);
            } catch (ItemStateException ise) {
                String msg = "internal error: failed to retrieve state of " + nodeId;
                log.debug(msg);
                throw new RepositoryException(msg, ise);
            }
            // remove child node entry
            targetState.removeChildNodeEntry(entry.getName(), entry.getIndex());
        }
    }
    // remove properties
    // use temp set to avoid ConcurrentModificationException
    HashSet<Name> tmp = new HashSet<Name>(targetState.getPropertyNames());
    for (Name propName : tmp) {
        PropertyId propId = new PropertyId(targetState.getNodeId(), propName);
        try {
            PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
            // remove property entry
            targetState.removePropertyName(propId.getName());
            // destroy property state
            stateMgr.destroy(propState);
        } catch (ItemStateException ise) {
            String msg = "internal error: failed to retrieve state of " + propId;
            log.debug(msg);
            throw new RepositoryException(msg, ise);
        }
    }
    // now actually do unlink target state
    targetState.setParentId(null);
    // destroy target state (pass overlayed state since target state
    // might have been modified during unlinking)
    stateMgr.destroy(targetState.getOverlayedState());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NodeId(org.apache.jackrabbit.core.id.NodeId) HashSet(java.util.HashSet)

Example 32 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId 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 33 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class BatchedItemOperations method verifyCheckedOut.

// ----------------------------------------------------< protected methods >
/**
 * Verifies that the node at <code>nodePath</code> is checked-out; throws a
 * <code>VersionException</code> if that's not the case.
 * <p>
 * A node is considered <i>checked-out</i> if it is versionable and
 * checked-out, or is non-versionable but its nearest versionable ancestor
 * is checked-out, or is non-versionable and there are no versionable
 * ancestors.
 *
 * @param nodePath
 * @throws PathNotFoundException
 * @throws VersionException
 * @throws RepositoryException
 */
protected void verifyCheckedOut(Path nodePath) throws PathNotFoundException, VersionException, RepositoryException {
    // search nearest ancestor that is versionable, start with node at nodePath
    /**
     * FIXME should not only rely on existence of jcr:isCheckedOut property
     * but also verify that node.isNodeType("mix:versionable")==true;
     * this would have a negative impact on performance though...
     */
    NodeState nodeState = getNodeState(nodePath);
    while (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
        if (nodePath.denotesRoot()) {
            return;
        }
        nodePath = nodePath.getAncestor(1);
        nodeState = getNodeState(nodePath);
    }
    PropertyId propId = new PropertyId(nodeState.getNodeId(), NameConstants.JCR_ISCHECKEDOUT);
    PropertyState propState;
    try {
        propState = (PropertyState) stateMgr.getItemState(propId);
    } catch (ItemStateException ise) {
        String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(propId);
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
    boolean checkedOut = propState.getValues()[0].getBoolean();
    if (!checkedOut) {
        throw new VersionException(safeGetJCRPath(nodePath) + " is checked-in");
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) VersionException(javax.jcr.version.VersionException)

Example 34 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeImpl method hasProperty.

/**
 * {@inheritDoc}
 */
public boolean hasProperty(String relPath) throws RepositoryException {
    // check state of this instance
    sanityCheck();
    PropertyId id = resolveRelativePropertyPath(relPath);
    if (id != null) {
        return itemMgr.itemExists(id);
    } else {
        return false;
    }
}
Also used : PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 35 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeImpl method onRemove.

protected void onRemove(NodeId parentId) throws RepositoryException {
    // modify the state of 'this', i.e. the target node
    NodeState thisState = (NodeState) getOrCreateTransientItemState();
    // remove this node from its shared set
    if (thisState.isShareable()) {
        if (thisState.removeShare(parentId) > 0) {
            // this state is still connected to some parents, so
            // leave the child node entries and properties
            // set state of this instance to 'invalid'
            data.setStatus(STATUS_INVALIDATED);
            // notify the item manager that this instance has been
            // temporarily invalidated
            itemMgr.itemInvalidated(id, data);
            return;
        }
    }
    if (thisState.hasChildNodeEntries()) {
        // remove child nodes
        // use temp array to avoid ConcurrentModificationException
        ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(thisState.getChildNodeEntries());
        // remove from tail to avoid problems with same-name siblings
        for (int i = tmp.size() - 1; i >= 0; i--) {
            ChildNodeEntry entry = tmp.get(i);
            // recursively remove child node
            NodeId childId = entry.getId();
            // NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId);
            try {
                /* omit the read-permission check upon retrieving the
                       child item as this is an internal call to remove the
                       subtree which may contain (protected) child items which
                       are not visible to the caller of the removal. the actual
                       validation of the remove permission however is only
                       executed during Item.save(). 
                     */
                NodeImpl childNode = itemMgr.getNode(childId, getNodeId(), false);
                childNode.onRemove(thisState.getNodeId());
            // remove the child node entry
            } catch (ItemNotFoundException e) {
                boolean ignoreError = false;
                if (parentId != null && sessionContext.getSessionImpl().autoFixCorruptions()) {
                    // it might be an access right problem
                    // we need to check if the item doesn't exist in the ism
                    ItemStateManager ism = sessionContext.getItemStateManager();
                    if (!ism.hasItemState(childId)) {
                        log.warn("Child named " + entry.getName() + " (index " + entry.getIndex() + ", " + "node id " + childId + ") " + "not found when trying to remove " + getPath() + " " + "(node id " + getNodeId() + ") - ignored", e);
                        ignoreError = true;
                    }
                }
                if (!ignoreError) {
                    throw e;
                }
            }
            thisState.removeChildNodeEntry(childId);
        }
    }
    // remove properties
    // use temp set to avoid ConcurrentModificationException
    HashSet<Name> tmp = new HashSet<Name>(thisState.getPropertyNames());
    for (Name propName : tmp) {
        // remove the property entry
        thisState.removePropertyName(propName);
        // remove property
        PropertyId propId = new PropertyId(thisState.getNodeId(), propName);
        /* omit the read-permission check upon retrieving the
               child item as this is an internal call to remove the
               subtree which may contain (protected) child items which
               are not visible to the caller of the removal. the actual
               validation of the remove permission however is only
               executed during Item.save().
             */
        itemMgr.getItem(propId, false).setRemoved();
    }
    // finally remove this node
    thisState.setParentId(null);
    setRemoved();
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager) ItemNotFoundException(javax.jcr.ItemNotFoundException) HashSet(java.util.HashSet)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4