Search in sources :

Example 41 with NodeState

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

the class ProtectedItemModifier method addNode.

protected NodeImpl addNode(NodeImpl parentImpl, Name name, Name ntName, NodeId nodeId) throws RepositoryException {
    checkPermission(parentImpl, name, getPermission(true, false));
    // validation: make sure Node is not locked or checked-in.
    parentImpl.checkSetProperty();
    NodeTypeImpl nodeType = parentImpl.sessionContext.getNodeTypeManager().getNodeType(ntName);
    org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl def = parentImpl.getApplicableChildNodeDefinition(name, ntName);
    // check for name collisions
    // TODO: improve. copied from NodeImpl
    NodeState thisState = parentImpl.getNodeState();
    ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
    if (cne != null) {
        // check same-name sibling setting of new node
        if (!def.allowsSameNameSiblings()) {
            throw new ItemExistsException();
        }
        // check same-name sibling setting of existing node
        NodeId newId = cne.getId();
        NodeImpl n = (NodeImpl) parentImpl.sessionContext.getItemManager().getItem(newId);
        if (!n.getDefinition().allowsSameNameSiblings()) {
            throw new ItemExistsException();
        }
    }
    return parentImpl.createChildNode(name, nodeType, nodeId);
}
Also used : NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) 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)

Example 42 with NodeState

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

the class NodeImpl method getSharedSet.

//-------------------------------------------------------< shareable nodes >
/**
     * Returns an iterator over all nodes that are in the shared set of this
     * node. If this node is not shared then the returned iterator contains
     * only this node.
     *
     * @return a <code>NodeIterator</code>
     * @throws RepositoryException if an error occurs.
     * @since JCR 2.0
     */
public NodeIterator getSharedSet() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
    if (!isShareable()) {
        list.add(this);
    } else {
        NodeState state = data.getNodeState();
        for (NodeId parentId : state.getSharedSet()) {
            list.add(itemMgr.getNode(getNodeId(), parentId));
        }
    }
    return new NodeIteratorAdapter(list);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.core.id.NodeId) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter)

Example 43 with NodeState

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

the class PersistenceCopier method copy.

/**
     * Recursively copies the identified node and all its descendants.
     * Explicitly excluded nodes and nodes that have already been copied
     * are automatically skipped.
     *
     * @param id identifier of the node to be copied
     * @throws RepositoryException if the copy operation fails
     */
public void copy(NodeId id) throws RepositoryException {
    if (!exclude.contains(id)) {
        try {
            NodeState node = source.load(id);
            for (ChildNodeEntry entry : node.getChildNodeEntries()) {
                copy(entry.getId());
            }
            copy(node);
            exclude.add(id);
        } catch (ItemStateException e) {
            throw new RepositoryException("Unable to copy " + id, e);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 44 with NodeState

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

the class EventStateCollection method createShareableNodeEvents.

//----------------------------< internal >----------------------------------
private void createShareableNodeEvents(NodeState n, ChangeLog changes, ChangeLogBasedHierarchyMgr hmgr, ItemStateManager stateMgr) throws ItemStateException {
    if (n.isShareable()) {
        // check if a share was added or removed
        for (NodeId parentId : n.getAddedShares()) {
            // ignore primary parent id
            if (n.getParentId().equals(parentId)) {
                continue;
            }
            NodeState parent = (NodeState) changes.get(parentId);
            if (parent == null) {
                // happens when mix:shareable is added to an existing node
                // usually the parent node state is in the change log
                // when a node is added to a shared set -> new child node
                // entry on parent node state.
                parent = (NodeState) stateMgr.getItemState(parentId);
            }
            Name ntName = getNodeType(parent, session).getQName();
            EventState es = EventState.childNodeAdded(parentId, getPath(parentId, hmgr), n.getNodeId(), getNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
            es.setShareableNode(true);
            events.add(es);
        }
        for (NodeId parentId : n.getRemovedShares()) {
            // parent ids that are not primary
            if (n.getParentId().equals(parentId)) {
                continue;
            }
            NodeState parent = null;
            try {
                parent = (NodeState) changes.get(parentId);
            } catch (NoSuchItemStateException e) {
            // parent has been removed as well
            // ignore and retrieve from stateMgr
            }
            if (parent == null) {
                // happens when mix:shareable is removed from an existing
                // node. Usually the parent node state is in the change log
                // when a node is removed to a shared set -> removed child
                // node entry on parent node state.
                parent = (NodeState) stateMgr.getItemState(parentId);
            }
            Name ntName = getNodeType(parent, session).getQName();
            EventState es = EventState.childNodeRemoved(parentId, getZombiePath(parentId, hmgr), n.getNodeId(), getZombieNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
            es.setShareableNode(true);
            events.add(es);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name)

Example 45 with NodeState

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

the class SearchIndexConsistencyCheckTest method testIndexContainsUnknownNode.

public void testIndexContainsUnknownNode() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    NodeId nodeId = new NodeId(0, 0);
    NodeState nodeState = new NodeState(nodeId, null, null, 1, false);
    Iterator<NodeId> remove = Collections.<NodeId>emptyList().iterator();
    Iterator<NodeState> add = Collections.singletonList(nodeState).iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    ConsistencyCheckError error = errors.iterator().next();
    assertEquals("Different node was reported to be unknown", error.id, nodeId);
    consistencyCheck.repair(false);
    assertFalse("Index was not repaired properly", searchIndexContainsNode(searchIndex, nodeId));
    assertTrue("Consistency check still reports errors", searchIndex.runConsistencyCheck().getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

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