Search in sources :

Example 46 with NodeId

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

the class RepositoryServiceImpl method restore.

/**
     * {@inheritDoc}
     */
public void restore(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId versionId, final boolean removeExisting) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Version v = (Version) getNode(versionId, sInfo);
            if (hasNode(sessionInfo, nodeId)) {
                Node n = getNode(nodeId, sInfo);
                n.restore(v, removeExisting);
            } else {
                // restore with rel-Path part
                Node n = null;
                Path relPath = null;
                Path path = nodeId.getPath();
                if (nodeId.getUniqueID() != null) {
                    n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
                    relPath = (path.isAbsolute()) ? getPathFactory().getRootPath().computeRelativePath(nodeId.getPath()) : path;
                } else {
                    int degree = 0;
                    while (degree < path.getLength()) {
                        Path ancestorPath = path.getAncestor(degree);
                        NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
                        if (hasNode(sessionInfo, parentId)) {
                            n = getNode(parentId, sInfo);
                            relPath = ancestorPath.computeRelativePath(path);
                        }
                        degree++;
                    }
                }
                if (n == null) {
                    throw new PathNotFoundException("Path not found " + nodeId);
                } else {
                    n.restore(v, sInfo.getNamePathResolver().getJCRPath(relPath), removeExisting);
                }
            }
            return null;
        }
    }, sInfo);
}
Also used : Path(org.apache.jackrabbit.spi.Path) Version(javax.jcr.version.Version) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 47 with NodeId

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

the class NodeEntryImpl method getDeepNodeEntry.

/**
     * @see NodeEntry#getDeepNodeEntry(Path)
     */
public NodeEntry getDeepNodeEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    for (int i = 0; i < elems.length; i++) {
        Path.Element elem = elems[i];
        // check for root element
        if (elem.denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            //    on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // elements -> hierarchy doesn't exist anyway.
            if (entry.getStatus() == Status.NEW) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            /*
                * Unknown entry (not-existing or not yet loaded):
                * Skip all intermediate entries and directly try to load the ItemState
                * (including building the intermediate entries. If that fails
                * ItemNotFoundException is thrown.
                *
                * Since 'path' might be ambiguous (Node or Property):
                * 1) first try Node
                * 2) if the NameElement does not have SNS-index => try Property
                * 3) else throw
                */
            PathBuilder pb = new PathBuilder(getPathFactory());
            for (int j = i; j < elems.length; j++) {
                pb.addLast(elems[j]);
            }
            Path remainingPath = pb.getPath();
            NodeId parentId = entry.getWorkspaceId();
            IdFactory idFactory = factory.getIdFactory();
            NodeId nodeId = idFactory.createNodeId(parentId, remainingPath);
            NodeEntry ne = entry.loadNodeEntry(nodeId);
            if (ne != null) {
                return ne;
            } else {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
        }
    }
    return entry;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 48 with NodeId

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

the class NodeEntryImpl method getNodeEntry.

/**
     * @see NodeEntry#getNodeEntry(Name, int, boolean)
     */
public NodeEntry getNodeEntry(Name nodeName, int index, boolean loadIfNotFound) throws RepositoryException {
    List<NodeEntry> entries = childNodeEntries.get(nodeName);
    NodeEntry cne = null;
    if (entries.size() >= index) {
        // position of entry might differ from index-1 if a SNS with lower
        // index has been transiently removed.
        int eIndex = 1;
        for (int i = 0; i < entries.size() && cne == null; i++) {
            NodeEntry ne = entries.get(i);
            if (EntryValidation.isValidNodeEntry(ne)) {
                if (eIndex == index) {
                    cne = ne;
                }
                eIndex++;
            }
        }
    }
    if (cne == null && loadIfNotFound && !containsAtticChild(entries, nodeName, index) && !childNodeEntries.isComplete()) {
        NodeId cId = getIdFactory().createNodeId(getWorkspaceId(), getPathFactory().create(nodeName, index));
        cne = loadNodeEntry(cId);
    }
    return cne;
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId)

Example 49 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 50 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)

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