Search in sources :

Example 31 with RepositoryException

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

the class InternalVersionManagerBase method createInternalVersionItem.

/**
     * Creates an {@link InternalVersionItem} based on the {@link NodeState}
     * identified by <code>id</code>.
     *
     * @param id    the node id of the version item.
     * @return the version item or <code>null</code> if there is no node state
     *         with the given <code>id</code>.
     * @throws RepositoryException if an error occurs while reading from the
     *                             version storage.
     */
protected InternalVersionItem createInternalVersionItem(NodeId id) throws RepositoryException {
    try {
        if (stateMgr.hasItemState(id)) {
            NodeState state = (NodeState) stateMgr.getItemState(id);
            NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
            NodeId parentId = pNode.getParentId();
            InternalVersionItem parent = getItem(parentId);
            Name ntName = state.getNodeTypeName();
            if (ntName.equals(NameConstants.NT_FROZENNODE)) {
                return new InternalFrozenNodeImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSIONEDCHILD)) {
                return new InternalFrozenVHImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSION)) {
                return ((InternalVersionHistory) parent).getVersion(id);
            } else if (ntName.equals(NameConstants.NT_VERSIONHISTORY)) {
                return new InternalVersionHistoryImpl(this, pNode);
            } else if (ntName.equals(NameConstants.NT_ACTIVITY)) {
                return new InternalActivityImpl(this, pNode);
            } else {
                return null;
            }
        } else {
            return null;
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) 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 32 with RepositoryException

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

the class VersionManagerImplBase method checkModify.

/**
     * Checks modify and permissions
     * @param state state to check
     * @param options options to check
     * @param permissions permissions to check
     * @throws RepositoryException if an error occurs
     */
protected void checkModify(NodeStateEx state, int options, int permissions) throws RepositoryException {
    NodeImpl node;
    try {
        node = session.getNodeById(state.getNodeId());
    } catch (RepositoryException e) {
        // ignore
        return;
    }
    context.getItemValidator().checkModify(node, options, permissions);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) RepositoryException(javax.jcr.RepositoryException)

Example 33 with RepositoryException

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

the class VersionManagerImplMerge method merge.

/**
     * Merge the given activity to this workspace
     *
     * @param activity internal activity
     * @param failedIds list of failed ids
     * @throws RepositoryException if an error occurs
     */
protected void merge(InternalActivity activity, List<ItemId> failedIds) throws RepositoryException {
    VersionSet changeSet = activity.getChangeSet();
    WriteOperation ops = startWriteOperation();
    try {
        Iterator<NodeId> iter = changeSet.versions().keySet().iterator();
        while (iter.hasNext()) {
            InternalVersion v = changeSet.versions().remove(iter.next());
            NodeStateEx state = getNodeStateEx(v.getFrozenNode().getFrozenId());
            if (state != null) {
                InternalVersion base = getBaseVersion(state);
                // but merge it anyways
                if (base.isMoreRecent(v)) {
                    failedIds.add(state.getNodeId());
                    // add it to the jcr:mergeFailed property
                    Set<NodeId> set = getMergeFailed(state);
                    set.add(base.getId());
                    setMergeFailed(state, set);
                    state.store();
                } else {
                    for (InternalVersion restored : internalRestore(state, v, changeSet, true)) {
                        changeSet.versions().remove(restored.getVersionHistory().getId());
                    }
                }
            }
            // reset iterator
            iter = changeSet.versions().keySet().iterator();
        }
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 34 with RepositoryException

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

the class VersionHistoryImpl method removeVersion.

/**
     * @see javax.jcr.version.VersionHistory#removeVersion(String)
     */
public void removeVersion(String versionName) throws UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    try {
        // check permissions
        checkVersionManagementPermission();
        sessionContext.getSessionImpl().getInternalVersionManager().removeVersion(getSession(), getInternalVersionHistory(), sessionContext.getQName(versionName));
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException)

Example 35 with RepositoryException

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

the class InternalVersionHistoryImpl method createVersionInstance.

/**
     * Create a version instance.
     * @param name name of the version
     * @return the new internal version
     * @throws IllegalArgumentException if the version does not exist
     */
synchronized InternalVersionImpl createVersionInstance(Name name) {
    try {
        NodeStateEx nodeStateEx = node.getNode(name, 1);
        InternalVersionImpl v = createVersionInstance(nodeStateEx);
        versionCache.put(v.getId(), v);
        vMgr.versionCreated(v);
        // add labels
        for (Name labelName : labelCache.keySet()) {
            Name versionName = labelCache.get(labelName);
            if (v.getName().equals(versionName)) {
                v.internalAddLabel(labelName);
            }
        }
        return v;
    } catch (RepositoryException e) {
        throw new InconsistentVersioningState("Failed to create version " + name + " in VHR " + historyId + ".", historyId, null);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

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