Search in sources :

Example 51 with UnsupportedRepositoryOperationException

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

the class CheckoutTest method testCheckoutNonVersionableNodeJcr2.

/**
      * Test calling VersionManager.checkout(P) with P denoting the absolute
      * path of a non-versionable node.
      */
public void testCheckoutNonVersionableNodeJcr2() throws RepositoryException {
    VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager();
    String path = nonVersionableNode.getPath();
    try {
        versionManager.checkout(path);
        fail("VersionManager.checkout(P) with P denoting the absolute path of a non-versionable node must throw UnsupportedRepositoryOperationException");
    } catch (UnsupportedRepositoryOperationException e) {
    //success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) VersionManager(javax.jcr.version.VersionManager)

Example 52 with UnsupportedRepositoryOperationException

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

the class NodeTypeManagerImplTest method testUnregisterNodeTypes.

public void testUnregisterNodeTypes() throws RepositoryException {
    NodeTypeTemplate test = ntMgr.createNodeTypeTemplate();
    test.setName("testNodeType2");
    ntMgr.registerNodeType(test, true);
    NodeType nt = ntMgr.getNodeType("testNodeType2");
    assertNotNull(nt);
    assertEquals("testNodeType2", nt.getName());
    boolean supported = false;
    try {
        ntMgr.unregisterNodeType(test.getName());
        supported = true;
    } catch (UnsupportedRepositoryOperationException e) {
    // ok
    } catch (RepositoryException e) {
        // TODO improve
        if (e.getMessage().contains("not yet implemented")) {
        // ok (original message in jr-core)
        } else {
            throw e;
        }
    }
    if (supported) {
        try {
            ntMgr.getNodeType("testNodeType2");
            fail("should not be available any more");
        } catch (NoSuchNodeTypeException e) {
        // success
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 53 with UnsupportedRepositoryOperationException

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

the class EventFactory method fromJCREvent.

public Event fromJCREvent(javax.jcr.observation.Event e) throws RepositoryException {
    Path p = e.getPath() != null ? resolver.getQPath(e.getPath()) : null;
    Path parent = p != null ? p.getAncestor(1) : null;
    int type = e.getType();
    NodeId parentId = parent != null ? idFactory.createNodeId((String) null, parent) : null;
    String identifier = e.getIdentifier();
    ItemId itemId;
    Node node = null;
    if (identifier != null) {
        itemId = idFactory.fromJcrIdentifier(e.getIdentifier());
        try {
            node = session.getItem(e.getPath()).getParent();
        } catch (RepositoryException re) {
        // ignore. TODO improve
        }
    } else {
        switch(type) {
            case Event.NODE_ADDED:
            case Event.NODE_MOVED:
                node = session.getItem(e.getPath()).getParent();
            case Event.NODE_REMOVED:
                itemId = idFactory.createNodeId((String) null, p);
                break;
            case Event.PROPERTY_ADDED:
            case Event.PROPERTY_CHANGED:
                node = session.getItem(e.getPath()).getParent();
            case Event.PROPERTY_REMOVED:
                itemId = idFactory.createPropertyId(parentId, p.getName());
                break;
            case Event.PERSIST:
            default:
                itemId = null;
        }
    }
    Name nodeTypeName = null;
    Name[] mixinTypes = Name.EMPTY_ARRAY;
    if (node != null) {
        try {
            parentId = idFactory.createNodeId(node.getUUID(), null);
        } catch (UnsupportedRepositoryOperationException ex) {
        // not referenceable
        }
        nodeTypeName = resolver.getQName(node.getPrimaryNodeType().getName());
        mixinTypes = getNodeTypeNames(node.getMixinNodeTypes(), resolver);
    }
    Map<Name, QValue> info = new HashMap<Name, QValue>();
    Map<String, Object> jcrInfo = e.getInfo();
    for (Map.Entry<String, Object> entry : jcrInfo.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        Name name = resolver.getQName(key);
        if (value != null) {
            // event information is generated for NODE_MOVED only in which
            // case all values are of type PATH.
            QValue v = ValueFormat.getQValue(value.toString(), PropertyType.PATH, resolver, qValueFactory);
            info.put(name, v);
        } else {
            info.put(name, null);
        }
    }
    return new EventImpl(e.getType(), p, itemId, parentId, nodeTypeName, mixinTypes, e.getUserID(), e.getUserData(), e.getDate(), info);
}
Also used : Path(org.apache.jackrabbit.spi.Path) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) Name(org.apache.jackrabbit.spi.Name) EventImpl(org.apache.jackrabbit.spi.commons.EventImpl) NodeId(org.apache.jackrabbit.spi.NodeId) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with UnsupportedRepositoryOperationException

use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit-oak by apache.

the class ReadWriteVersionManager method checkout.

/**
     * Performs a checkout on a versionable tree.
     *
     * @param workspaceRoot a fresh workspace root without pending changes.
     * @param versionablePath the absolute path to the versionable node to check out.
     * @throws UnsupportedRepositoryOperationException
     *                             if the versionable tree isn't actually
     *                             versionable.
     * @throws RepositoryException if an error occurs while checking the
     *                             node type of the tree.
     * @throws IllegalStateException if the workspaceRoot has pending changes.
     * @throws IllegalArgumentException if the {@code versionablePath} is
     *                             not absolute.
     */
public void checkout(@Nonnull Root workspaceRoot, @Nonnull String versionablePath) throws UnsupportedRepositoryOperationException, InvalidItemStateException, RepositoryException {
    checkState(!workspaceRoot.hasPendingChanges());
    checkArgument(PathUtils.isAbsolute(versionablePath));
    Tree versionable = workspaceRoot.getTree(versionablePath);
    if (!isVersionable(versionable)) {
        throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
    }
    if (!isCheckedOut(versionable)) {
        versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.TRUE, Type.BOOLEAN);
        try {
            workspaceRoot.commit();
            refresh();
        } catch (CommitFailedException e) {
            workspaceRoot.refresh();
            throw e.asRepositoryException();
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 55 with UnsupportedRepositoryOperationException

use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit-oak by apache.

the class ReadWriteVersionManager method checkin.

/**
     * Performs a checkin on a versionable tree and returns the tree that
     * represents the created version.
     *
     * @param versionable the versionable node to check in.
     * @return the created version.
     * @throws InvalidItemStateException if the current root has pending
     *                                   changes.
     * @throws UnsupportedRepositoryOperationException
     *                                   if the versionable tree isn't actually
     *                                   versionable.
     * @throws RepositoryException       if an error occurs while checking the
     *                                   node type of the tree.
     */
@Nonnull
public Tree checkin(@Nonnull Tree versionable) throws RepositoryException, InvalidItemStateException, UnsupportedRepositoryOperationException {
    if (sessionDelegate.hasPendingChanges()) {
        throw new InvalidItemStateException("Unable to perform checkin. " + "Session has pending changes.");
    }
    if (!isVersionable(versionable)) {
        throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
    }
    if (isCheckedOut(versionable)) {
        Tree baseVersion = getExistingBaseVersion(versionable);
        versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.FALSE, Type.BOOLEAN);
        PropertyState created = baseVersion.getProperty(JCR_CREATED);
        if (created != null) {
            long c = ISO8601.parse(created.getValue(Type.DATE)).getTimeInMillis();
            while (System.currentTimeMillis() == c) {
            // busy-wait for System.currentTimeMillis to change
            // so that the new version has a distinct timestamp
            }
        }
        try {
            sessionDelegate.commit();
            refresh();
        } catch (CommitFailedException e) {
            sessionDelegate.refresh(true);
            throw e.asRepositoryException();
        }
    }
    return getExistingBaseVersion(getWorkspaceRoot().getTree(versionable.getPath()));
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Aggregations

UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)57 RepositoryException (javax.jcr.RepositoryException)17 Node (javax.jcr.Node)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 NodeId (org.apache.jackrabbit.core.id.NodeId)8 ArrayList (java.util.ArrayList)7 Workspace (javax.jcr.Workspace)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Session (javax.jcr.Session)4 VersionManager (javax.jcr.version.VersionManager)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 Name (org.apache.jackrabbit.spi.Name)4 Path (org.apache.jackrabbit.spi.Path)4 IOException (java.io.IOException)3 ItemExistsException (javax.jcr.ItemExistsException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeType (javax.jcr.nodetype.NodeType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AccessDeniedException (javax.jcr.AccessDeniedException)2