Search in sources :

Example 21 with EffectiveNodeType

use of org.apache.jackrabbit.core.nodetype.EffectiveNodeType 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 22 with EffectiveNodeType

use of org.apache.jackrabbit.core.nodetype.EffectiveNodeType 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 23 with EffectiveNodeType

use of org.apache.jackrabbit.core.nodetype.EffectiveNodeType in project jackrabbit by apache.

the class ItemManager method getDefinition.

PropertyDefinitionImpl getDefinition(PropertyState state) throws RepositoryException {
    // see also: JCR-2408
    if (state.getStatus() == ItemState.STATUS_EXISTING_REMOVED && state.getName().equals(NameConstants.JCR_UUID)) {
        NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
        QPropertyDefinition def = ntReg.getEffectiveNodeType(NameConstants.MIX_REFERENCEABLE).getApplicablePropertyDef(state.getName(), state.getType());
        return sessionContext.getNodeTypeManager().getPropertyDefinition(def);
    }
    try {
        // retrieve parent in 2 steps in order to avoid the check for
        // read permissions on the parent which isn't required in order
        // to read the property's definition. see also JCR-2418.
        ItemData parentData = getItemData(state.getParentId(), null, false);
        NodeImpl parent = (NodeImpl) createItemInstance(parentData);
        return parent.getApplicablePropertyDefinition(state.getName(), state.getType(), state.isMultiValued(), true);
    } catch (ItemNotFoundException e) {
    // parent probably removed, get it from attic
    }
    try {
        NodeState parent = (NodeState) sism.getAttic().getItemState(state.getParentId()).getOverlayedState();
        NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
        EffectiveNodeType ent = ntReg.getEffectiveNodeType(parent.getNodeTypeName(), parent.getMixinTypeNames());
        QPropertyDefinition def;
        try {
            def = ent.getApplicablePropertyDef(state.getName(), state.getType(), state.isMultiValued());
        } catch (ConstraintViolationException e) {
            ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
            def = ent.getApplicablePropertyDef(state.getName(), state.getType(), state.isMultiValued());
            log.warn("Fallback to nt:unstructured due to unknown property " + "definition for '" + state.getName() + "'");
        }
        return sessionContext.getNodeTypeManager().getPropertyDefinition(def);
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } catch (NodeTypeConflictException e) {
        throw new RepositoryException(e);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) 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 24 with EffectiveNodeType

use of org.apache.jackrabbit.core.nodetype.EffectiveNodeType in project jackrabbit by apache.

the class NodeImpl method isNodeType.

/**
     * Same as {@link Node#isNodeType(String)} except that it takes a
     * <code>Name</code> instead of a <code>String</code>.
     *
     * @param ntName name of node type
     * @return <code>true</code> if this node is of the specified node type;
     *         otherwise <code>false</code>
     */
public boolean isNodeType(Name ntName) throws RepositoryException {
    // first do trivial checks without using type hierarchy
    Name primary = data.getNodeState().getNodeTypeName();
    if (ntName.equals(primary)) {
        return true;
    }
    Set<Name> mixins = data.getNodeState().getMixinTypeNames();
    if (mixins.contains(ntName)) {
        return true;
    }
    // check effective node type
    try {
        NodeTypeRegistry registry = sessionContext.getNodeTypeRegistry();
        EffectiveNodeType type = registry.getEffectiveNodeType(primary, mixins);
        return type.includesNodeType(ntName);
    } catch (NodeTypeConflictException e) {
        String msg = "Failed to build effective node type for " + this;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Aggregations

EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)24 NodeState (org.apache.jackrabbit.core.state.NodeState)16 RepositoryException (javax.jcr.RepositoryException)15 Name (org.apache.jackrabbit.spi.Name)14 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)13 NodeTypeConflictException (org.apache.jackrabbit.core.nodetype.NodeTypeConflictException)10 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)10 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)10 NodeId (org.apache.jackrabbit.core.id.NodeId)9 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)9 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)7 ItemExistsException (javax.jcr.ItemExistsException)6 PropertyId (org.apache.jackrabbit.core.id.PropertyId)6 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)6 QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)6 HashSet (java.util.HashSet)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PropertyState (org.apache.jackrabbit.core.state.PropertyState)5 Path (org.apache.jackrabbit.spi.Path)5