Search in sources :

Example 46 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException 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)

Example 47 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class InternalXAVersionManager method makeLocalCopy.

/**
     * Make a local copy of an internal version item. This will recreate the
     * (global) version item with state information from our own state
     * manager.
     * @param history source
     * @return the new copy
     * @throws RepositoryException if an error occurs
     */
private InternalVersionHistoryImpl makeLocalCopy(InternalVersionHistoryImpl history) throws RepositoryException {
    VersioningLock.ReadLock lock = acquireReadLock();
    try {
        NodeState state = (NodeState) stateMgr.getItemState(history.getId());
        NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
        return new InternalVersionHistoryImpl(this, stateEx);
    } catch (ItemStateException e) {
        throw new RepositoryException("Unable to make local copy", e);
    } finally {
        lock.release();
    }
}
Also used : VirtualNodeState(org.apache.jackrabbit.core.virtual.VirtualNodeState) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 48 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class InternalXAVersionManager method makeLocalCopy.

/**
     * Make a local copy of an internal version item. This will recreate the
     * (global) version item with state information from our own state
     * manager.
     * @param act source
     * @return the new copy
     * @throws RepositoryException if an error occurs
     */
private InternalActivityImpl makeLocalCopy(InternalActivityImpl act) throws RepositoryException {
    VersioningLock.ReadLock lock = acquireReadLock();
    try {
        NodeState state = (NodeState) stateMgr.getItemState(act.getId());
        NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
        return new InternalActivityImpl(this, stateEx);
    } catch (ItemStateException e) {
        throw new RepositoryException("Unable to make local copy", e);
    } finally {
        lock.release();
    }
}
Also used : VirtualNodeState(org.apache.jackrabbit.core.virtual.VirtualNodeState) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 49 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class InternalVersionManagerBase method internalCreateActivity.

/**
     * Creates a new activity.
     *
     * @param title title of the new activity
     * @return the id of the newly created activity
     * @throws RepositoryException if an error occurs
     */
NodeStateEx internalCreateActivity(String title) throws RepositoryException {
    WriteOperation operation = startWriteOperation();
    try {
        // create deep path
        NodeId activityId = nodeIdFactory.newNodeId();
        NodeStateEx parent = getParentNode(getActivitiesRoot(), activityId.toString(), NameConstants.REP_ACTIVITIES);
        Name name = getName(activityId.toString());
        // create new activity node in the persistent state
        NodeStateEx pNode = InternalActivityImpl.create(parent, name, activityId, title);
        // end update
        operation.save();
        log.debug("Created new activity " + activityId + " with title " + title + ".");
        return pNode;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        operation.close();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 50 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class VersionItemStateManager method setNodeReferences.

/**
     * Sets the
     * @param references
     * @return
     */
public boolean setNodeReferences(ChangeLog references) {
    try {
        ChangeLog log = new ChangeLog();
        for (NodeReferences source : references.modifiedRefs()) {
            // filter out version storage intern ones
            NodeReferences target = new NodeReferences(source.getTargetId());
            for (PropertyId id : source.getReferences()) {
                if (!hasNonVirtualItemState(id.getParentId())) {
                    target.addReference(id);
                }
            }
            log.modified(target);
        }
        if (log.hasUpdates()) {
            pMgr.store(log);
        }
        return true;
    } catch (ItemStateException e) {
        log.error("Error while setting references: " + e.toString());
        return false;
    }
}
Also used : NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)141 RepositoryException (javax.jcr.RepositoryException)87 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)86 NodeId (org.apache.jackrabbit.core.id.NodeId)44 NodeState (org.apache.jackrabbit.core.state.NodeState)39 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)31 IOException (java.io.IOException)28 InvalidItemStateException (javax.jcr.InvalidItemStateException)27 PropertyState (org.apache.jackrabbit.core.state.PropertyState)24 SQLException (java.sql.SQLException)23 PropertyId (org.apache.jackrabbit.core.id.PropertyId)22 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)19 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)19 Name (org.apache.jackrabbit.spi.Name)17 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 InternalValue (org.apache.jackrabbit.core.value.InternalValue)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)13 InputStream (java.io.InputStream)12