Search in sources :

Example 96 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 97 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 98 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 99 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)

Example 100 with NodeState

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

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