Search in sources :

Example 91 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class RepositoryServiceImpl method checkin.

/**
     * {@inheritDoc}
     */
public NodeId checkin(final SessionInfo sessionInfo, final NodeId nodeId) throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Version newVersion = (Version) executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            return getNode(nodeId, getSessionInfoImpl(sessionInfo)).checkin();
        }
    }, sInfo);
    return idFactory.createNodeId(newVersion);
}
Also used : Version(javax.jcr.version.Version)

Example 92 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class XATest method testXAVersionsThoroughly.

/**
     * Tests a couple of checkin/restore/remove operations on different
     * workspaces and different transactions.
     *
     * @throws Exception
     */
public void testXAVersionsThoroughly() throws Exception {
    Session s1 = superuser;
    Session s2 = getHelper().getSuperuserSession(workspaceName);
    // add node and save
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    n1.addMixin(mixVersionable);
    testRootNode.save();
    if (!s2.itemExists(testRootNode.getPath())) {
        s2.getRootNode().addNode(testRootNode.getName());
        s2.save();
    }
    s2.getWorkspace().clone(s1.getWorkspace().getName(), n1.getPath(), n1.getPath(), true);
    Node n2 = (Node) s2.getItem(n1.getPath());
    //log.println("---------------------------------------");
    String phase = "init";
    Version v1_1 = n1.getBaseVersion();
    Version v2_1 = n2.getBaseVersion();
    check(v1_1, phase, "jcr:rootVersion", 0);
    check(v2_1, phase, "jcr:rootVersion", 0);
    //log.println("--------checkout/checkin n1 (uncommitted)----------");
    phase = "checkin N1 uncomitted.";
    UserTransaction tx = new UserTransactionImpl(s1);
    tx.begin();
    n1.checkout();
    n1.checkin();
    Version v1_2 = n1.getBaseVersion();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 0);
    check(v1_2, phase, "1.0", 0);
    //log.println("--------checkout/checkin n1 (comitted)----------");
    phase = "checkin N1 committed.";
    tx.commit();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 0);
    //log.println("--------restore n2 (uncommitted) ----------");
    phase = "restore N2 uncommitted.";
    tx = new UserTransactionImpl(s2);
    tx.begin();
    n2.restore("1.0", false);
    Version v2_2 = n2.getBaseVersion();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 0);
    check(v2_2, phase, "1.0", 0);
    //log.println("--------restore n2 (comitted) ----------");
    phase = "restore N2 committed.";
    tx.commit();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 0);
    check(v2_2, phase, "1.0", 0);
    //log.println("--------checkout/checkin n2 (uncommitted) ----------");
    phase = "checkin N2 uncommitted.";
    tx = new UserTransactionImpl(s2);
    tx.begin();
    n2.checkout();
    n2.checkin();
    Version v2_3 = n2.getBaseVersion();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 0);
    check(v2_2, phase, "1.0", 1);
    check(v2_3, phase, "1.1", 0);
    //log.println("--------checkout/checkin n2 (committed) ----------");
    phase = "checkin N2 committed.";
    tx.commit();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 1);
    check(v2_2, phase, "1.0", 1);
    check(v2_3, phase, "1.1", 0);
    //log.println("--------checkout/checkin n1 (uncommitted) ----------");
    phase = "checkin N1 uncommitted.";
    tx = new UserTransactionImpl(s1);
    tx.begin();
    n1.checkout();
    n1.checkin();
    Version v1_3 = n1.getBaseVersion();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 2);
    check(v2_2, phase, "1.0", 1);
    check(v2_3, phase, "1.1", 0);
    check(v1_3, phase, "1.0.0", 0);
    //log.println("--------checkout/checkin n1 (committed) ----------");
    phase = "checkin N1 committed.";
    tx.commit();
    check(v1_1, phase, "jcr:rootVersion", 1);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", 2);
    check(v2_2, phase, "1.0", 2);
    check(v2_3, phase, "1.1", 0);
    check(v1_3, phase, "1.0.0", 0);
    //log.println("--------remove n1-1.0 (uncommitted) ----------");
    phase = "remove N1 1.0 uncommitted.";
    tx = new UserTransactionImpl(s1);
    tx.begin();
    n1.getVersionHistory().removeVersion("1.0");
    check(v1_1, phase, "jcr:rootVersion", 2);
    check(v2_1, phase, "jcr:rootVersion", 1);
    check(v1_2, phase, "1.0", -1);
    check(v2_2, phase, "1.0", 2);
    check(v2_3, phase, "1.1", 0);
    check(v1_3, phase, "1.0.0", 0);
    //log.println("--------remove n1-1.0  (committed) ----------");
    phase = "remove N1 1.0 committed.";
    tx.commit();
    check(v1_1, phase, "jcr:rootVersion", 2);
    check(v2_1, phase, "jcr:rootVersion", 2);
    check(v1_2, phase, "1.0", -1);
    check(v2_2, phase, "1.0", -1);
    check(v2_3, phase, "1.1", 0);
    check(v1_3, phase, "1.0.0", 0);
    //s1.logout();
    s2.logout();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 93 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class XATest method testRemoveVersion.

/**
     * Test removed version gets invalid for other users on commit.
     */
public void testRemoveVersion() throws Exception {
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser);
    // add node and save
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    testRootNode.save();
    // reference node in other session
    Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
    // create two versions, reference first version in other session
    n.checkin();
    Version vOther = nOther.getBaseVersion();
    n.checkout();
    n.checkin();
    // start transaction
    utx.begin();
    // remove version and commit
    n.getVersionHistory().removeVersion(vOther.getName());
    // commit
    utx.commit();
    // assert: version has become invalid
    try {
        vOther.getPredecessors();
        fail("Removed version still operational.");
    } catch (RepositoryException e) {
    // expected
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Version(javax.jcr.version.Version) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 94 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class VersionControlledItemCollection method update.

/**
     * Perform an update on this resource. Depending on the format of the <code>updateInfo</code>
     * this is translated to one of the following methods defined by the JCR API:
     * <ul>
     * <li>{@link Node#restore(javax.jcr.version.Version, boolean)}</li>
     * <li>{@link Node#restore(javax.jcr.version.Version, String, boolean)}</li>
     * <li>{@link Node#restoreByLabel(String, boolean)}</li>
     * <li>{@link Node#update(String)}</li>
     * </ul>
     * <p>
     * Limitation: note that the <code>MultiStatus</code> returned by this method
     * will not list any nodes that have been removed due to an Uuid conflict.
     *
     * @param updateInfo
     * @return
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
     */
//TODO: with jcr the node must not be versionable in order to perform Node.update.
@Override
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
    if (updateInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        Node node = (Node) item;
        Element udElem = updateInfo.getUpdateElement();
        boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);
        // register eventListener in order to be able to report the modified resources.
        EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
        registerEventListener(el, node.getPath());
        // perform the update/restore according to the update info
        if (updateInfo.getVersionHref() != null) {
            String[] hrefs = updateInfo.getVersionHref();
            if (hrefs.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body missing version href or containing multiple version hrefs.");
            }
            String versionPath = getLocatorFromHref(hrefs[0]).getRepositoryPath();
            String versionName = getItemName(versionPath);
            String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
            if (relPath == null) {
                // restore version by name
                node.restore(versionName, removeExisting);
            } else if (node.hasNode(relPath)) {
                Version v = node.getNode(relPath).getVersionHistory().getVersion(versionName);
                node.restore(v, relPath, removeExisting);
            } else {
                Version v = (Version) getRepositorySession().getNode(versionPath);
                node.restore(v, relPath, removeExisting);
            }
        } else if (updateInfo.getLabelName() != null) {
            String[] labels = updateInfo.getLabelName();
            if (labels.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: Multiple labels specified.");
            }
            node.restoreByLabel(labels[0], removeExisting);
        } else if (updateInfo.getWorkspaceHref() != null) {
            String href = obtainAbsolutePathFromUri(updateInfo.getWorkspaceHref());
            String workspaceName = getLocatorFromHref(href).getWorkspaceName();
            node.update(workspaceName);
        } else {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");
        }
        // unregister the event listener again
        unregisterEventListener(el);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Element(org.w3c.dom.Element) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) EventListener(javax.jcr.observation.EventListener)

Example 95 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class MergeDoneMergeTest method testMergeNodeDoneMerge.

/**
     * Node.doneMerge(V) throws VersionException if V is not among the Vs in the
     * jcr:mergeFailed prop. <br> with adding it to jcr:predecessors.<br>
     * Branches will be joined.<br>
     */
public void testMergeNodeDoneMerge() throws RepositoryException {
    // create 2 independent versions for a node and its corresponding node
    // so merge fails for this node
    // default workspace
    Node originalNode = testRootNode.getNode(nodeName1);
    originalNode.checkout();
    originalNode.checkin();
    // second workspace
    nodeToMerge.checkin();
    // "merge" the clonedNode with the newNode from the default workspace
    nodeToMerge.checkout();
    nodeToMerge.merge(workspace.getName(), true);
    // get predecessors
    Version[] predecessors = nodeToMerge.getBaseVersion().getPredecessors();
    // get mergeFailed property
    Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
    Value[] mergeFailedReferences = mergeFailedProperty.getValues();
    for (int i = 0; i < mergeFailedReferences.length; i++) {
        String uuid = mergeFailedReferences[i].getString();
        nodeToMerge.doneMerge((Version) superuser.getNodeByUUID(uuid));
    }
    // check mergeFailed property - reference moved to predecessor
    if (nodeToMerge.hasProperty(jcrMergeFailed)) {
        Property mergeFailedPropertyAfterCancelMerge = nodeToMerge.getProperty(jcrMergeFailed);
        Value[] mergeFailedReferencesAfterCancelMerge = mergeFailedPropertyAfterCancelMerge.getValues();
        assertTrue(mergeFailedReferences.length > mergeFailedReferencesAfterCancelMerge.length);
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Value(javax.jcr.Value) Property(javax.jcr.Property)

Aggregations

Version (javax.jcr.version.Version)265 Node (javax.jcr.Node)155 VersionManager (javax.jcr.version.VersionManager)65 RepositoryException (javax.jcr.RepositoryException)45 VersionHistory (javax.jcr.version.VersionHistory)29 VersionException (javax.jcr.version.VersionException)25 NodeIterator (javax.jcr.NodeIterator)23 Session (javax.jcr.Session)19 Test (org.junit.Test)19 Property (javax.jcr.Property)16 VersionIterator (javax.jcr.version.VersionIterator)16 Value (javax.jcr.Value)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)14 ItemExistsException (javax.jcr.ItemExistsException)13 HashSet (java.util.HashSet)12 NodeDefinition (javax.jcr.nodetype.NodeDefinition)12 ArrayList (java.util.ArrayList)11 Set (java.util.Set)7 DavException (org.apache.jackrabbit.webdav.DavException)7 UserTransaction (javax.transaction.UserTransaction)6