Search in sources :

Example 21 with RepositoryException

use of javax.jcr.RepositoryException 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 22 with RepositoryException

use of javax.jcr.RepositoryException 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 23 with RepositoryException

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

the class InternalVersionHistoryImpl method checkin.

/**
     * Checks in a node. It creates a new version with the given name and freezes
     * the state of the given node.
     *
     * @param name new version name
     * @param src source node to version
     * @param created optional created date
     * @return the newly created version
     * @throws RepositoryException if an error occurs
     */
synchronized InternalVersionImpl checkin(Name name, NodeStateEx src, Calendar created) throws RepositoryException {
    // copy predecessors from src node
    InternalValue[] predecessors;
    if (src.hasProperty(NameConstants.JCR_PREDECESSORS)) {
        predecessors = src.getPropertyValues(NameConstants.JCR_PREDECESSORS);
        // check all predecessors
        for (InternalValue pred : predecessors) {
            NodeId predId = pred.getNodeId();
            // check if version exist
            if (!nameCache.containsValue(predId)) {
                throw new RepositoryException("Invalid predecessor in source node: " + predId);
            }
        }
    } else {
        // with simple versioning, the node does not contain a predecessors
        // property and we just use the 'head' version as predecessor
        Iterator<NodeId> iter = nameCache.values().iterator();
        NodeId last = null;
        while (iter.hasNext()) {
            last = iter.next();
        }
        if (last == null) {
            // should never happen
            last = rootVersion.getId();
        }
        predecessors = new InternalValue[] { InternalValue.create(last) };
    }
    NodeId versionId = vMgr.getNodeIdFactory().newNodeId();
    NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);
    // check for jcr:activity
    if (src.hasProperty(NameConstants.JCR_ACTIVITY)) {
        InternalValue act = src.getPropertyValue(NameConstants.JCR_ACTIVITY);
        vNode.setPropertyValue(NameConstants.JCR_ACTIVITY, act);
    }
    // initialize 'created', 'predecessors' and 'successors'
    if (created == null) {
        created = getCurrentTime();
    }
    vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(created));
    vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, predecessors);
    vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
    // checkin source node
    InternalFrozenNodeImpl.checkin(vNode, NameConstants.JCR_FROZENNODE, src);
    // update version graph
    boolean isConfiguration = src.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION);
    InternalVersionImpl version = isConfiguration ? new InternalBaselineImpl(this, vNode, name) : new InternalVersionImpl(this, vNode, name);
    version.internalAttach();
    // and store
    node.store();
    vMgr.versionCreated(version);
    // update cache
    versionCache.put(version.getId(), version);
    nameCache.put(version.getName(), version.getId());
    return version;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue)

Example 24 with RepositoryException

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

the class InternalVersionManagerBase method startWriteOperation.

/**
     * Starts a write operation by acquiring the write lock and setting the
     * item state manager to the "edit" state. If something goes wrong, the
     * write lock is released and an exception is thrown.
     * <p>
     * The pattern for using this method and the returned helper instance is:
     * <pre>
     *     WriteOperation operation = startWriteOperation();
     *     try {
     *         ...
     *         operation.save(); // if everything is OK
     *         ...
     *     } catch (...) {
     *         ...
     *     } finally {
     *         operation.close();
     *     }
     * </pre>
     *
     * @return write operation helper
     * @throws RepositoryException if the write operation could not be started
     */
private WriteOperation startWriteOperation() throws RepositoryException {
    boolean success = false;
    VersioningLock.WriteLock lock = acquireWriteLock();
    try {
        stateMgr.edit();
        success = true;
        return new WriteOperation(lock);
    } catch (IllegalStateException e) {
        throw new RepositoryException("Unable to start edit operation.", e);
    } finally {
        if (!success) {
            lock.release();
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException)

Example 25 with RepositoryException

use of javax.jcr.RepositoryException 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)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50