Search in sources :

Example 41 with NodeId

use of org.apache.jackrabbit.spi.NodeId 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)

Example 42 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class VersionManagerImpl method getVersionableNodeEntry.

public NodeEntry getVersionableNodeEntry(NodeState versionState) throws RepositoryException {
    NodeState ns = versionState.getChildNodeState(NameConstants.JCR_FROZENNODE, Path.INDEX_DEFAULT);
    PropertyState ps = ns.getPropertyState(NameConstants.JCR_FROZENUUID);
    String uniqueID = ps.getValue().getString();
    NodeId versionableId = workspaceManager.getIdFactory().createNodeId(uniqueID);
    return workspaceManager.getHierarchyManager().getNodeEntry(versionableId);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 43 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class VersionManagerImpl method resolveMergeConflict.

public void resolveMergeConflict(NodeState nodeState, NodeState versionState, boolean done) throws RepositoryException {
    NodeId vId = versionState.getNodeId();
    PropertyState mergeFailedState = nodeState.getPropertyState(NameConstants.JCR_MERGEFAILED);
    QValue[] vs = mergeFailedState.getValues();
    NodeId[] mergeFailedIds = new NodeId[vs.length - 1];
    for (int i = 0, j = 0; i < vs.length; i++) {
        NodeId id = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
        if (!id.equals(vId)) {
            mergeFailedIds[j] = id;
            j++;
        }
    // else: the version id is being solved by this call and not
    // part of 'jcr:mergefailed' any more
    }
    PropertyState predecessorState = nodeState.getPropertyState(NameConstants.JCR_PREDECESSORS);
    vs = predecessorState.getValues();
    int noOfPredecessors = (done) ? vs.length + 1 : vs.length;
    NodeId[] predecessorIds = new NodeId[noOfPredecessors];
    int i = 0;
    while (i < vs.length) {
        predecessorIds[i] = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
        i++;
    }
    if (done) {
        predecessorIds[i] = vId;
    }
    Operation op = ResolveMergeConflict.create(nodeState, mergeFailedIds, predecessorIds, done);
    workspaceManager.execute(op);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeId(org.apache.jackrabbit.spi.NodeId) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Checkpoint(org.apache.jackrabbit.jcr2spi.operation.Checkpoint) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 44 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class EventFilterImpl method accept.

/**
     * {@inheritDoc}
     */
public boolean accept(Event event, boolean isLocal) {
    int type = event.getType();
    // check type
    if ((type & eventTypes) == 0) {
        return false;
    }
    // check local flag
    if (isLocal && noLocal) {
        return false;
    }
    // UUIDs, types, and paths do not need to match for persist
    if (event.getType() == Event.PERSIST) {
        return true;
    }
    // check UUIDs
    NodeId parentId = event.getParentId();
    if (uuids != null) {
        if (parentId.getPath() == null) {
            if (!uuids.contains(parentId.getUniqueID())) {
                return false;
            }
        } else {
            return false;
        }
    }
    // check node types
    if (nodeTypeNames != null) {
        Set<Name> eventTypes = new HashSet<Name>();
        eventTypes.addAll(Arrays.asList(event.getMixinTypeNames()));
        eventTypes.add(event.getPrimaryNodeTypeName());
        // create intersection
        eventTypes.retainAll(nodeTypeNames);
        if (eventTypes.isEmpty()) {
            return false;
        }
    }
    // finally check path
    try {
        Path eventPath = event.getPath().getAncestor(1);
        boolean match = eventPath.equals(absPath);
        if (!match && isDeep) {
            match = eventPath.isDescendantOf(absPath);
        }
        return match;
    } catch (RepositoryException e) {
    // should never get here
    }
    // if we get here an exception occurred while checking for the path
    return false;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) HashSet(java.util.HashSet) Name(org.apache.jackrabbit.spi.Name)

Example 45 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class PropertyInfoImpl method createSerializablePropertyInfo.

/**
     * Creates a new serializable property info for the given
     * <code>PropertyInfo</code>.
     *
     * @param propertyInfo
     */
public static PropertyInfo createSerializablePropertyInfo(PropertyInfo propertyInfo, IdFactory idFactory) {
    if (propertyInfo instanceof Serializable) {
        return propertyInfo;
    } else {
        NodeId parentId = propertyInfo.getId().getParentId();
        parentId = idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
        PropertyId propId = idFactory.createPropertyId(parentId, propertyInfo.getId().getName());
        return new PropertyInfoImpl(propertyInfo.getPath(), propId, propertyInfo.getType(), propertyInfo.isMultiValued(), propertyInfo.getValues());
    }
}
Also used : Serializable(java.io.Serializable) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Aggregations

NodeId (org.apache.jackrabbit.spi.NodeId)80 Batch (org.apache.jackrabbit.spi.Batch)35 Name (org.apache.jackrabbit.spi.Name)32 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)23 RepositoryException (javax.jcr.RepositoryException)21 QValue (org.apache.jackrabbit.spi.QValue)21 PropertyId (org.apache.jackrabbit.spi.PropertyId)13 Path (org.apache.jackrabbit.spi.Path)11 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)10 ArrayList (java.util.ArrayList)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)9 IOException (java.io.IOException)6 Node (javax.jcr.Node)5 HttpResponse (org.apache.http.HttpResponse)5 ItemId (org.apache.jackrabbit.spi.ItemId)5 DavException (org.apache.jackrabbit.webdav.DavException)5 InputStream (java.io.InputStream)4 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)4 PathNotFoundException (javax.jcr.PathNotFoundException)3