Search in sources :

Example 76 with VersionException

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

the class NodeImpl method removeMixin.

@Override
public void removeMixin(final String mixinName) throws RepositoryException {
    final String oakTypeName = getOakName(checkNotNull(mixinName));
    sessionDelegate.performVoid(new ItemWriteOperation<Void>("removeMixin") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut()) {
                throw new VersionException(format("Cannot remove mixin type. Node [%s] is checked in.", getNodePath()));
            }
            // check for NODE_TYPE_MANAGEMENT permission here as we cannot
            // distinguish between a combination of removeMixin and addMixin
            // and Node#remove plus subsequent addNode when it comes to
            // autocreated properties like jcr:create, jcr:uuid and so forth.
            Set<String> mixins = newLinkedHashSet(getNames(dlg.getTree(), JCR_MIXINTYPES));
            if (!mixins.isEmpty() && mixins.remove(getOakName(mixinName))) {
                PropertyState prop = PropertyStates.createProperty(JCR_MIXINTYPES, mixins, NAMES);
                sessionContext.getAccessManager().checkPermissions(dlg.getTree(), prop, Permissions.NODE_TYPE_MANAGEMENT);
            }
        }

        @Override
        public void performVoid() throws RepositoryException {
            dlg.removeMixin(oakTypeName);
        }
    });
}
Also used : Set(java.util.Set) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 77 with VersionException

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

the class OpvAbortTest method testDirectChild.

public void testDirectChild() throws Exception {
    testRootNode.addMixin("OpvAbortTest");
    Node n = testRootNode.addNode("child", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    assertEquals(OnParentVersionAction.ABORT, n.getDefinition().getOnParentVersion());
    superuser.save();
    try {
        vMgr.checkpoint(testRootNode.getPath());
        fail();
    } catch (VersionException e) {
    // success
    } finally {
        superuser.refresh(false);
    }
}
Also used : Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 78 with VersionException

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

the class VersionableTest method testReadOnlyAfterCheckin.

public void testReadOnlyAfterCheckin() throws RepositoryException {
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    node.addMixin(mixVersionable);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    if (!node.isCheckedOut()) {
        vMgr.checkout(node.getPath());
    }
    superuser.refresh(false);
    node.setProperty(propertyName1, "foo");
    superuser.save();
    vMgr.checkin(node.getPath());
    try {
        node.setProperty(propertyName1, "bar");
        fail("setProperty() must fail on a checked-in node");
    } catch (VersionException e) {
    // expected
    }
    try {
        node.setProperty(propertyName1, (String) null);
        fail("setProperty(..., null) must fail on a checked-in node");
    } catch (VersionException e) {
    // expected
    }
    try {
        Property prop = node.getProperty(propertyName1);
        assertNotNull(prop);
        prop.setValue("bar");
        fail("Property.setValue() must fail on a checked-in node");
    } catch (VersionException e) {
    // expected
    }
    try {
        Property prop = node.getProperty(propertyName1);
        assertNotNull(prop);
        prop.remove();
        fail("Property.remove() must fail on a checked-in node");
    } catch (VersionException e) {
    // expected
    }
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) Property(javax.jcr.Property) VersionException(javax.jcr.version.VersionException)

Aggregations

VersionException (javax.jcr.version.VersionException)78 Node (javax.jcr.Node)25 Version (javax.jcr.version.Version)25 RepositoryException (javax.jcr.RepositoryException)19 Name (org.apache.jackrabbit.spi.Name)8 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 Property (javax.jcr.Property)6 Session (javax.jcr.Session)6 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)6 VersionIterator (javax.jcr.version.VersionIterator)5 VersionManager (javax.jcr.version.VersionManager)5 NodeId (org.apache.jackrabbit.core.id.NodeId)5 Nonnull (javax.annotation.Nonnull)4 ItemExistsException (javax.jcr.ItemExistsException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 RetentionManager (javax.jcr.retention.RetentionManager)4 LabelExistsVersionException (javax.jcr.version.LabelExistsVersionException)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4