Search in sources :

Example 76 with NodeState

use of org.apache.jackrabbit.core.state.NodeState 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 77 with NodeState

use of org.apache.jackrabbit.core.state.NodeState 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 78 with NodeState

use of org.apache.jackrabbit.core.state.NodeState 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 79 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ItemSaveOperation method processShareableNodes.

/**
     * Process all items given in iterator and check whether <code>mix:shareable</code>
     * or (some derived node type) has been added or removed:
     * <ul>
     * <li>If the mixin <code>mix:shareable</code> (or some derived node type),
     * then initialize the shared set inside the state.</li>
     * <li>If the mixin <code>mix:shareable</code> (or some derived node type)
     * has been removed, throw.</li>
     * </ul>
     */
private void processShareableNodes(NodeTypeRegistry registry, Iterable<ItemState> states) throws RepositoryException {
    for (ItemState is : states) {
        if (is.isNode()) {
            NodeState ns = (NodeState) is;
            boolean wasShareable = false;
            if (ns.hasOverlayedState()) {
                NodeState old = (NodeState) ns.getOverlayedState();
                EffectiveNodeType ntOld = getEffectiveNodeType(registry, old);
                wasShareable = ntOld.includesNodeType(NameConstants.MIX_SHAREABLE);
            }
            EffectiveNodeType ntNew = getEffectiveNodeType(registry, ns);
            boolean isShareable = ntNew.includesNodeType(NameConstants.MIX_SHAREABLE);
            if (!wasShareable && isShareable) {
                // mix:shareable has been added
                ns.addShare(ns.getParentId());
            } else if (wasShareable && !isShareable) {
                // mix:shareable has been removed: not supported
                String msg = "Removing mix:shareable is not supported.";
                log.debug(msg);
                throw new UnsupportedRepositoryOperationException(msg);
            }
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemState(org.apache.jackrabbit.core.state.ItemState)

Example 80 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ItemSaveOperation method initVersionHistories.

/**
     * Initialises the version history of all new nodes of node type
     * <code>mix:versionable</code>.
     *
     * @param states
     * @return true if this call generated new transient state; otherwise false
     * @throws RepositoryException
     */
private boolean initVersionHistories(SessionContext context, Iterable<ItemState> states) throws RepositoryException {
    SessionImpl session = context.getSessionImpl();
    ItemManager itemMgr = context.getItemManager();
    // walk through list of transient items and search for new versionable nodes
    boolean createdTransientState = false;
    for (ItemState itemState : states) {
        if (itemState.isNode()) {
            NodeState nodeState = (NodeState) itemState;
            EffectiveNodeType nt = getEffectiveNodeType(context.getRepositoryContext().getNodeTypeRegistry(), nodeState);
            if (nt.includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                if (!nodeState.hasPropertyName(NameConstants.JCR_VERSIONHISTORY)) {
                    NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
                    InternalVersionManager vMgr = session.getInternalVersionManager();
                    /**
                         * check if there's already a version history for that
                         * node; this would e.g. be the case if a versionable
                         * node had been exported, removed and re-imported with
                         * either IMPORT_UUID_COLLISION_REMOVE_EXISTING or
                         * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
                         * otherwise create a new version history
                         */
                    VersionHistoryInfo history = vMgr.getVersionHistory(session, nodeState, null);
                    InternalValue historyId = InternalValue.create(history.getVersionHistoryId());
                    InternalValue versionId = InternalValue.create(history.getRootVersionId());
                    node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, historyId);
                    node.internalSetProperty(NameConstants.JCR_BASEVERSION, versionId);
                    node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
                    node.internalSetProperty(NameConstants.JCR_PREDECESSORS, new InternalValue[] { versionId });
                    createdTransientState = true;
                }
            } else if (nt.includesNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE)) {
                // we need to check the version manager for an existing
                // version history, since simple versioning does not
                // expose it's reference in a property
                InternalVersionManager vMgr = session.getInternalVersionManager();
                vMgr.getVersionHistory(session, nodeState, null);
                // create isCheckedOutProperty if not already exists
                NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
                if (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
                    node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
                    createdTransientState = true;
                }
            }
        }
    }
    return createdTransientState;
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) VersionHistoryInfo(org.apache.jackrabbit.core.version.VersionHistoryInfo) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemState(org.apache.jackrabbit.core.state.ItemState) InternalValue(org.apache.jackrabbit.core.value.InternalValue) InternalVersionManager(org.apache.jackrabbit.core.version.InternalVersionManager)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7