Search in sources :

Example 1 with ActivityViolationException

use of javax.jcr.version.ActivityViolationException in project jackrabbit by apache.

the class InternalVersionManagerImpl method canCheckout.

/**
     * {@inheritDoc}
     *
     * this method currently does no modifications to the persistence and just
     * checks if the checkout is valid in respect to a possible activity set on
     * the session
     */
public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
    NodeId baseId = state.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId();
    if (activityId != null) {
        // exist in 'this' workspace
        if (stateMgr.hasNodeReferences(activityId)) {
            try {
                NodeReferences refs = stateMgr.getNodeReferences(activityId);
                for (PropertyId id : refs.getReferences()) {
                    if (!state.hasNode(id.getParentId())) {
                        throw new ActivityViolationException("Unable to checkout. " + "Activity is already used for the same node in " + "another workspace.");
                    }
                }
            } catch (ItemStateException e) {
                throw new RepositoryException("Error during checkout.", e);
            }
        }
        // If there is a version in H that is not an eventual predecessor of N but
        // whose jcr:activity references A, then the checkout fails with an
        // ActivityViolationException
        InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
        NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
        InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
        InternalVersion version = a.getLatestVersion(history);
        if (version != null) {
            InternalVersion baseVersion = (InternalVersion) getItem(baseId);
            while (baseVersion != null && !baseVersion.getId().equals(version.getId())) {
                baseVersion = baseVersion.getLinearPredecessor();
            }
            if (baseVersion == null) {
                throw new ActivityViolationException("Unable to checkout. " + "Activity is used by another version on a different branch: " + version.getName());
            }
        }
    }
    return baseId;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ActivityViolationException(javax.jcr.version.ActivityViolationException) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

InvalidItemStateException (javax.jcr.InvalidItemStateException)1 RepositoryException (javax.jcr.RepositoryException)1 ActivityViolationException (javax.jcr.version.ActivityViolationException)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 PropertyId (org.apache.jackrabbit.core.id.PropertyId)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)1