Search in sources :

Example 1 with EffectiveNodeTypeProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
     * @see OperationVisitor#visit(SetPrimaryType)
     */
public void visit(SetPrimaryType operation) throws ConstraintViolationException, RepositoryException {
    // NOTE: nodestate is only modified upon save of the changes!
    Name primaryName = operation.getPrimaryTypeName();
    NodeState nState = operation.getNodeState();
    NodeEntry nEntry = nState.getNodeEntry();
    // detect obvious node type conflicts
    EffectiveNodeTypeProvider entProvider = mgrProvider.getEffectiveNodeTypeProvider();
    // try to build new effective node type (will throw in case of conflicts)
    Name[] mixins = nState.getMixinTypeNames();
    List<Name> all = new ArrayList<Name>(Arrays.asList(mixins));
    all.add(primaryName);
    // retrieve effective to assert validity of arguments
    entProvider.getEffectiveNodeType(all.toArray(new Name[all.size()]));
    // modify the value of the jcr:primaryType property entry without
    // changing the node state itself
    PropertyEntry pEntry = nEntry.getPropertyEntry(NameConstants.JCR_PRIMARYTYPE);
    PropertyState pState = pEntry.getPropertyState();
    setPropertyStateValue(pState, getQValues(new Name[] { primaryName }, qValueFactory), PropertyType.NAME, operation.getOptions());
    // mark the affected node state modified and remember the operation
    nState.markModified();
    transientStateMgr.addOperation(operation);
}
Also used : EffectiveNodeTypeProvider(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name)

Example 2 with EffectiveNodeTypeProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider in project jackrabbit by apache.

the class SessionImporter method startNode.

/**
     * {@inheritDoc}
     */
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos, NamePathResolver resolver) throws RepositoryException {
    if (isClosed()) {
        // workspace-importer only: ignore if import has been aborted before.
        return;
    }
    checkSession();
    NodeState parent = parents.peek();
    if (parent == null) {
        // parent node was skipped, skip this child node also
        // push null onto stack for skipped node
        parents.push(null);
        log.debug("Skipping node '" + nodeInfo.getName() + "'.");
        return;
    }
    NodeEntry parentEntry = (NodeEntry) parent.getHierarchyEntry();
    NodeState nodeState = null;
    if (parentEntry.hasNodeEntry(nodeInfo.getName())) {
        try {
            // a valid child node with that name already exists
            NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
            NodeState existing = entry.getNodeState();
            QNodeDefinition def = existing.getDefinition();
            if (!def.allowsSameNameSiblings()) {
                // existing doesn't allow same-name siblings, check for conflicts
                EffectiveNodeTypeProvider provider = session.getEffectiveNodeTypeProvider();
                Name[] ntNames = existing.getAllNodeTypeNames();
                EffectiveNodeType entExisting = provider.getEffectiveNodeType(ntNames);
                if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                    // skip protected node
                    // push null onto stack for skipped node
                    parents.push(null);
                    log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
                    return;
                }
                if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                    // this node has already been auto-created, no need to create it
                    nodeState = existing;
                } else {
                    throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
                }
            }
        } catch (ItemNotFoundException e) {
        // 'existing' doesn't exist any more -> ignore
        }
    }
    if (nodeState == null) {
        // node does not exist -> create new one
        if (nodeInfo.getUUID() == null) {
            // no potential uuid conflict, add new node from given info
            nodeState = importNode(nodeInfo, parent);
        } else {
            // make sure the import does not define a uuid without having
            // a primaryType or mixin that makes the new node referenceable
            checkIncludesMixReferenceable(nodeInfo);
            // potential uuid conflict
            try {
                NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
                NodeEntry conflicting = session.getHierarchyManager().getNodeEntry(conflictingId);
                // assert that the entry is available
                conflicting.getItemState();
                nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
            } catch (ItemNotFoundException e) {
                // no conflict: create new with given uuid
                nodeState = importNode(nodeInfo, parent);
            }
        }
    }
    // node state may be 'null' if applicable def is protected
    if (nodeState != null) {
        // process properties
        for (PropInfo pi : propInfos) {
            importProperty(pi, nodeState, resolver);
        }
    }
    // push current nodeState onto stack of parents
    parents.push(nodeState);
}
Also used : EffectiveNodeTypeProvider(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider) EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.spi.NodeId) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)2 EffectiveNodeTypeProvider (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider)2 Name (org.apache.jackrabbit.spi.Name)2 ArrayList (java.util.ArrayList)1 ItemExistsException (javax.jcr.ItemExistsException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 PropertyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry)1 EffectiveNodeType (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType)1 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1