Search in sources :

Example 11 with NodeId

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

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

the class InternalVersionHistoryImpl method getVersionByLabel.

/**
     * {@inheritDoc}
     */
public synchronized InternalVersion getVersionByLabel(Name label) {
    Name versionName = labelCache.get(label);
    if (versionName == null) {
        return null;
    }
    NodeId id = nameCache.get(versionName);
    InternalVersion v = versionCache.get(id);
    if (v == null) {
        v = createVersionInstance(versionName);
    }
    return v;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name)

Example 13 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 14 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 15 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)

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