Search in sources :

Example 51 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class InternalVersionHistoryImpl method getVersion.

/**
     * {@inheritDoc}
     */
public synchronized InternalVersion getVersion(Name versionName) throws VersionException {
    NodeId versionId = nameCache.get(versionName);
    if (versionId == null) {
        throw new VersionException("Version " + versionName + " does not exist.");
    }
    InternalVersion v = versionCache.get(versionId);
    if (v == null) {
        v = createVersionInstance(versionName);
    }
    return v;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) VersionException(javax.jcr.version.VersionException)

Example 52 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class InternalVersionManagerBase method internalCheckin.

/**
     * Checks in a node
     *
     * @param history the version history
     * @param node node to checkin
     * @param simple flag indicates simple versioning
     * @param created optional created date.
     * @return internal version
     * @throws javax.jcr.RepositoryException if an error occurs
     * @see javax.jcr.Node#checkin()
     */
protected InternalVersion internalCheckin(InternalVersionHistoryImpl history, NodeStateEx node, boolean simple, Calendar created) throws RepositoryException {
    String versionName = calculateCheckinVersionName(history, node, simple);
    InternalVersionImpl v = history.checkin(NameFactoryImpl.getInstance().create("", versionName), node, created);
    // check for jcr:activity
    if (node.hasProperty(JCR_ACTIVITY)) {
        NodeId actId = node.getPropertyValue(JCR_ACTIVITY).getNodeId();
        InternalActivityImpl act = (InternalActivityImpl) getItem(actId);
        act.addVersion(v);
    }
    return v;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 53 with NodeId

use of org.apache.jackrabbit.core.id.NodeId 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 54 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class VersionIteratorImpl method nextVersion.

/**
     * {@inheritDoc}
     */
public Version nextVersion() {
    if (versions.isEmpty()) {
        throw new NoSuchElementException();
    }
    NodeId id = versions.removeFirst();
    pos++;
    try {
        return (Version) session.getNodeById(id);
    } catch (RepositoryException e) {
        throw new ConcurrentModificationException("Unable to provide element: " + e.toString());
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Version(javax.jcr.version.Version) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) NoSuchElementException(java.util.NoSuchElementException)

Example 55 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class VersionManagerImplBase method checkoutCheckin.

/**
     * Performs a checkin or checkout operation. if <code>checkin</code> is
     * <code>true</code> the node is checked in. if <code>checkout</code> is
     * <code>true</code> the node is checked out. if both flags are <code>true</code>
     * the checkin is performed prior to the checkout and the operation is
     * equivalent to a checkpoint operation.
     *
     * @param state node state
     * @param checkin if <code>true</code> the node is checked in.
     * @param checkout if <code>true</code> the node is checked out.
     * @param created create time of the new version (if any),
     *                or <code>null</code> for the current time
     * @return the node id of the base version or <code>null</code> for a pure
     *         checkout.
     * @throws RepositoryException if an error occurs
     */
protected NodeId checkoutCheckin(NodeStateEx state, boolean checkin, boolean checkout, Calendar created) throws RepositoryException {
    assert (checkin || checkout);
    // check if versionable
    boolean isFull = checkVersionable(state);
    // check flags
    if (isCheckedOut(state)) {
        if (checkout && !checkin) {
            // pure checkout
            String msg = safeGetJCRPath(state) + ": Node is already checked-out. ignoring.";
            log.debug(msg);
            return null;
        }
    } else {
        if (!checkout) {
            // pure checkin
            String msg = safeGetJCRPath(state) + ": Node is already checked-in. ignoring.";
            log.debug(msg);
            if (isFull) {
                return getBaseVersionId(state);
            } else {
                // get base version from version history
                return vMgr.getHeadVersionOfNode(state.getNodeId()).getId();
            }
        }
        checkin = false;
    }
    NodeId baseId = isFull && checkout ? vMgr.canCheckout(state, currentActivity) : null;
    // perform operation
    WriteOperation ops = startWriteOperation();
    try {
        // the 2 cases could be consolidated but is clearer this way
        if (checkin) {
            // check for configuration
            if (state.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION)) {
                // collect the base versions and the the rep:versions property of the configuration
                Set<NodeId> baseVersions = collectBaseVersions(state);
                InternalValue[] vs = new InternalValue[baseVersions.size()];
                int i = 0;
                for (NodeId id : baseVersions) {
                    vs[i++] = InternalValue.create(id);
                }
                state.setPropertyValues(NameConstants.REP_VERSIONS, PropertyType.REFERENCE, vs);
                state.store();
            }
            InternalVersion v = vMgr.checkin(session, state, created);
            baseId = v.getId();
            if (isFull) {
                state.setPropertyValue(NameConstants.JCR_BASEVERSION, InternalValue.create(baseId));
                state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
                state.removeProperty(NameConstants.JCR_ACTIVITY);
            }
        }
        if (checkout) {
            if (isFull) {
                state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[] { InternalValue.create(baseId) });
                if (currentActivity != null) {
                    state.setPropertyValue(NameConstants.JCR_ACTIVITY, InternalValue.create(currentActivity));
                }
            }
        }
        state.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(checkout));
        state.store();
        ops.save();
        return baseId;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)203 RepositoryException (javax.jcr.RepositoryException)68 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)37 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 NodeImpl (org.apache.jackrabbit.core.NodeImpl)20 InternalValue (org.apache.jackrabbit.core.value.InternalValue)20 ArrayList (java.util.ArrayList)19 PropertyId (org.apache.jackrabbit.core.id.PropertyId)16 HashSet (java.util.HashSet)15 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)14 PropertyState (org.apache.jackrabbit.core.state.PropertyState)14 Session (javax.jcr.Session)13 HashMap (java.util.HashMap)12 ItemExistsException (javax.jcr.ItemExistsException)12