Search in sources :

Example 71 with VersionException

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

the class NodeImpl method setMixins.

/**
     * Simplified implementation of the {@link org.apache.jackrabbit.api.JackrabbitNode#setMixins(String[])}
     * method that adds all mixin types that are not yet present on this node
     * and removes all mixins that are no longer contained in the specified
     * array. Note, that this implementation will not work exactly like the
     * variant in Jackrabbit 2.x which first created the effective node type
     * and adjusted the set of child items accordingly.
     *
     * @param mixinNames
     * @throws RepositoryException
     */
@Override
public void setMixins(String[] mixinNames) throws RepositoryException {
    final Set<String> oakTypeNames = newLinkedHashSet();
    for (String mixinName : mixinNames) {
        oakTypeNames.add(getOakName(checkNotNull(mixinName)));
    }
    sessionDelegate.performVoid(new ItemWriteOperation<Void>("setMixins") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut()) {
                throw new VersionException(format("Cannot set mixin types. 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.
            PropertyDelegate mixinProp = dlg.getPropertyOrNull(JCR_MIXINTYPES);
            if (mixinProp != null) {
                sessionContext.getAccessManager().checkPermissions(dlg.getTree(), mixinProp.getPropertyState(), Permissions.NODE_TYPE_MANAGEMENT);
            }
        }

        @Override
        public void performVoid() throws RepositoryException {
            dlg.setMixins(oakTypeNames);
        }
    });
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)

Example 72 with VersionException

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

the class NodeImpl method internalSetProperty.

private Property internalSetProperty(final String jcrName, final Value value, final boolean exactTypeMatch) throws RepositoryException {
    final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
    final PropertyState state = createSingleState(oakName, value, Type.fromTag(value.getType(), false));
    return perform(new ItemWriteOperation<Property>("internalSetProperty") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut() && getOPV(dlg.getTree(), state) != OnParentVersionAction.IGNORE) {
                throw new VersionException(format("Cannot set property. Node [%s] is checked in.", getNodePath()));
            }
        }

        @Nonnull
        @Override
        public Property perform() throws RepositoryException {
            return new PropertyImpl(dlg.setProperty(state, exactTypeMatch, false), sessionContext);
        }

        @Override
        public String toString() {
            return format("Setting property [%s/%s]", dlg.getPath(), jcrName);
        }
    });
}
Also used : Nonnull(javax.annotation.Nonnull) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) VersionException(javax.jcr.version.VersionException)

Example 73 with VersionException

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

the class ReadWriteVersionManager method removeVersion.

public void removeVersion(@Nonnull VersionStorage versionStorage, @Nonnull String versionHistoryOakRelPath, @Nonnull String oakVersionName) throws RepositoryException {
    Tree versionHistory = TreeUtil.getTree(versionStorage.getTree(), versionHistoryOakRelPath);
    if (versionHistory == null || !versionHistory.exists()) {
        throw new VersionException("Version history " + versionHistoryOakRelPath + " does not exist on this version storage");
    }
    Tree version = versionHistory.getChild(oakVersionName);
    if (!version.exists()) {
        throw new VersionException("Version " + oakVersionName + " does not exist on this version history");
    }
    version.remove();
    try {
        sessionDelegate.commit(versionStorage.getRoot());
        refresh();
    } catch (CommitFailedException e) {
        versionStorage.refresh();
        throw e.asRepositoryException();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) LabelExistsVersionException(javax.jcr.version.LabelExistsVersionException) VersionException(javax.jcr.version.VersionException)

Example 74 with VersionException

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

the class ReadWriteVersionManager method removeVersionLabel.

public void removeVersionLabel(@Nonnull VersionStorage versionStorage, @Nonnull String versionHistoryOakRelPath, @Nonnull String oakVersionLabel) throws RepositoryException {
    Tree versionHistory = TreeUtil.getTree(checkNotNull(versionStorage.getTree()), checkNotNull(versionHistoryOakRelPath));
    Tree labels = checkNotNull(versionHistory).getChild(JCR_VERSIONLABELS);
    if (!labels.hasProperty(oakVersionLabel)) {
        throw new VersionException("Version label " + oakVersionLabel + " does not exist on this version history");
    }
    labels.removeProperty(oakVersionLabel);
    try {
        sessionDelegate.commit(versionStorage.getRoot());
        refresh();
    } catch (CommitFailedException e) {
        versionStorage.refresh();
        throw e.asRepositoryException();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) LabelExistsVersionException(javax.jcr.version.LabelExistsVersionException) VersionException(javax.jcr.version.VersionException)

Example 75 with VersionException

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

the class NodeImpl method addMixin.

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

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut()) {
                throw new VersionException(format("Cannot add mixin type. Node [%s] is checked in.", getNodePath()));
            }
        }

        @Override
        public void performVoid() throws RepositoryException {
            dlg.addMixin(oakTypeName);
        }
    });
}
Also used : RepositoryException(javax.jcr.RepositoryException) 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