Search in sources :

Example 36 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class AbstractImportXmlTest method createReferenceableNode.

/**
     * Creates a node with given name below the testRootNode which will be
     * referenced by the node nodeName2 and returns the UUID assigned to the
     * created node.
     *
     * @param name
     * @return
     * @throws RepositoryException
     * @throws NotExecutableException if the created node is not referenceable
     * and cannot be made referenceable by adding mix:referenceable.
     */
public String createReferenceableNode(String name) throws RepositoryException, NotExecutableException {
    // remove a yet existing node at the target
    try {
        Node node = testRootNode.getNode(name);
        node.remove();
        session.save();
    } catch (PathNotFoundException pnfe) {
    // ok
    }
    // a referenceable node
    Node n1 = testRootNode.addNode(name, testNodeType);
    if (!n1.isNodeType(mixReferenceable) && !n1.canAddMixin(mixReferenceable)) {
        n1.remove();
        session.save();
        throw new NotExecutableException("node type " + testNodeType + " does not support mix:referenceable");
    }
    n1.addMixin(mixReferenceable);
    // make sure jcr:uuid is available
    testRootNode.getSession().save();
    return n1.getUUID();
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 37 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class QueryImpl method storeAsNode.

/**
     * @see Query#storeAsNode(String)
     */
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
    NamePathResolver resolver = mgrProvider.getNamePathResolver();
    try {
        Path p = resolver.getQPath(absPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException(absPath + " is not an absolute path");
        }
        String jcrParent = resolver.getJCRPath(p.getAncestor(1));
        if (!session.itemExists(jcrParent)) {
            throw new PathNotFoundException(jcrParent);
        }
        String relPath = resolver.getJCRPath(p).substring(1);
        String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
        Node queryNode = session.getRootNode().addNode(relPath, ntName);
        // set properties
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
        node = queryNode;
        return node;
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 38 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createPropertyState.

/**
     * Creates the PropertyState with information retrieved from the <code>RepositoryService</code>.
     */
public PropertyState createPropertyState(PropertyId propertyId, PropertyEntry entry) throws ItemNotFoundException, RepositoryException {
    try {
        // Get item info from cache and use it if up to date
        Entry<PropertyInfo> cached = cache.getPropertyInfo(propertyId);
        ItemInfo info;
        if (isUpToDate(cached, entry)) {
            info = cached.info;
        } else {
            // otherwise retrieve item info from service and cache the whole batch
            Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, propertyId);
            info = first(infos, cache, entry.getGeneration());
            if (info == null || info.denotesNode()) {
                throw new ItemNotFoundException("PropertyId: " + propertyId);
            }
        }
        assertMatchingPath(info, entry);
        return createPropertyState((PropertyInfo) info, entry);
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(e);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) PathNotFoundException(javax.jcr.PathNotFoundException) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 39 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createNodeState.

/**
     * Creates the node with information retrieved from the <code>RepositoryService</code>.
     */
public NodeState createNodeState(NodeId nodeId, NodeEntry entry) throws ItemNotFoundException, RepositoryException {
    try {
        Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
        ItemInfo info;
        if (isUpToDate(cached, entry)) {
            info = cached.info;
        } else {
            // otherwise retrieve item info from service and cache the whole batch
            Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, nodeId);
            info = first(infos, cache, entry.getGeneration());
            if (info == null || !info.denotesNode()) {
                throw new ItemNotFoundException("NodeId: " + nodeId);
            }
        }
        assertMatchingPath(info, entry);
        return createNodeState((NodeInfo) info, entry);
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(e);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 40 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createDeepNodeState.

/**
     * Creates the node with information retrieved from the <code>RepositoryService</code>.
     * Intermediate entries are created as needed.
     */
public NodeState createDeepNodeState(NodeId nodeId, NodeEntry anyParent) throws ItemNotFoundException, RepositoryException {
    try {
        // Get item info from cache
        Iterator<? extends ItemInfo> infos = null;
        Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
        ItemInfo info;
        if (cached == null) {
            // or from service if not in cache
            infos = service.getItemInfos(sessionInfo, nodeId);
            info = first(infos, null, 0);
            if (info == null || !info.denotesNode()) {
                throw new ItemNotFoundException("NodeId: " + nodeId);
            }
        } else {
            info = cached.info;
        }
        // Build the hierarchy entry for the item info
        HierarchyEntry entry = createHierarchyEntries(info, anyParent);
        if (entry == null || !entry.denotesNode()) {
            throw new ItemNotFoundException("HierarchyEntry does not belong to any existing ItemInfo. No ItemState was created.");
        } else {
            // Now we can check whether the item info from the cache is up to date
            long generation = entry.getGeneration();
            if (isOutdated(cached, entry)) {
                // if not, retrieve the item info from the service and put the whole batch into the cache
                infos = service.getItemInfos(sessionInfo, nodeId);
                info = first(infos, cache, generation);
            } else if (infos != null) {
                // Otherwise put the whole batch retrieved from the service earlier into the cache
                cache.put(info, generation);
                first(infos, cache, generation);
            }
            assertMatchingPath(info, entry);
            return createNodeState((NodeInfo) info, (NodeEntry) entry);
        }
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(e);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PathNotFoundException(javax.jcr.PathNotFoundException) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6