Search in sources :

Example 1 with VersionManager

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

the class ServerWorkspace method getVersionManager.

public RemoteVersionManager getVersionManager() throws RepositoryException, RemoteException {
    try {
        if (remoteVersionManager == null) {
            VersionManager versionManager = workspace.getVersionManager();
            remoteVersionManager = getFactory().getRemoteVersionManager(workspace.getSession(), versionManager);
        }
        return remoteVersionManager;
    } catch (RepositoryException ex) {
        throw getRepositoryException(ex);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) RemoteVersionManager(org.apache.jackrabbit.rmi.remote.RemoteVersionManager) VersionManager(javax.jcr.version.VersionManager)

Example 2 with VersionManager

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

the class VersionHistoryTest method testGetAllFrozenNodes.

/**
     * Test that {@link VersionHistory#getAllFrozenNodes()} returns an iterator
     * containing the frozen nodes of all versions that have been created by
     * {@link VersionManager#checkpoint(String)}.
     *
     * @see javax.jcr.version.VersionHistory#getAllFrozenNodes()
     * @since JCR 2.0
     */
public void testGetAllFrozenNodes() throws RepositoryException {
    VersionManager vm = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    int cnt = 2;
    for (int i = 0; i < cnt; i++) {
        vm.checkpoint(path);
    }
    Set<String> frozenIds = new HashSet<String>();
    for (VersionIterator it = vm.getVersionHistory(path).getAllVersions(); it.hasNext(); ) {
        Version v = it.nextVersion();
        frozenIds.add(v.getFrozenNode().getIdentifier());
    }
    Set<String> test = new HashSet<String>();
    for (NodeIterator it = vHistory.getAllFrozenNodes(); it.hasNext(); ) {
        Node n = it.nextNode();
        assertTrue("Node " + n.getPath() + " must be of type frozen node", n.isNodeType("nt:frozenNode"));
        test.add(n.getIdentifier());
    }
    assertEquals("getAllFrozenNodes must return the IDs of all frozen nodes", frozenIds, test);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionManager(javax.jcr.version.VersionManager) HashSet(java.util.HashSet)

Example 3 with VersionManager

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

the class VersionLabelTest method testGetVersionLabelsForVersionJcr2.

/**
     * Test VersionHistory.getVersionLabels(Version) only returns all labels present
     * for the specified version.
     *
     * @throws RepositoryException
     * @see VersionHistory#getVersionLabels(javax.jcr.version.Version)
     */
public void testGetVersionLabelsForVersionJcr2() throws RepositoryException {
    Set<String> testLabels = new HashSet<String>(Arrays.asList(vHistory.getVersionLabels(version)));
    vHistory.addVersionLabel(version.getName(), versionLabel, false);
    testLabels.add(versionLabel);
    // add a version label to another version (not added to the testLabel set)
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    versionManager.checkout(path);
    Version v = versionManager.checkin(path);
    vHistory.addVersionLabel(v.getName(), versionLabel2, false);
    String[] labels = vHistory.getVersionLabels(version);
    for (int i = 0; i < labels.length; i++) {
        String l = labels[i];
        if (!testLabels.contains(l)) {
            fail("VersionHistory.getVersionLabels(Version) must only return labels, that have been added for this version.");
        }
        testLabels.remove(l);
    }
    assertTrue("VersionHistory.getVersionLabels(Version)  must return all labels, that have been added for this version.", testLabels.isEmpty());
}
Also used : Version(javax.jcr.version.Version) VersionManager(javax.jcr.version.VersionManager) HashSet(java.util.HashSet)

Example 4 with VersionManager

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

the class OnParentVersionAbortTest method testRestorePropJcr2.

/**
     * Test the restore of a OnParentVersion-ABORT property
     *
     * @throws javax.jcr.RepositoryException
     */
public void testRestorePropJcr2() throws RepositoryException {
    try {
        VersionManager versionManager = p.getSession().getWorkspace().getVersionManager();
        String path = p.getParent().getPath();
        versionManager.checkout(path);
        versionManager.checkin(path);
        fail("On checkin of N which has a property with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown.");
    } catch (VersionException e) {
    // success
    }
}
Also used : VersionManager(javax.jcr.version.VersionManager) VersionException(javax.jcr.version.VersionException)

Example 5 with VersionManager

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

the class MergeSubNodeTest method disable_testMergeNodeBestEffortTrueJcr2.

/**
     * VersionManager.merge(): bestEffort is true &gt; (sub)node which could not be merged
     * are not affected.<br>
     */
public void disable_testMergeNodeBestEffortTrueJcr2() throws RepositoryException {
    // create 2 new nodes with two independent versions
    // so merge fails for this node
    Node originalNode = testRootNode.getNode(nodeName1);
    VersionManager originalVersionManager = originalNode.getSession().getWorkspace().getVersionManager();
    String originalPath = originalNode.getPath();
    originalVersionManager.checkout(originalPath);
    Node subNode = originalNode.getNode(nodeName2);
    // will be unchanged after merge
    originalVersionManager.checkout(subNode.getPath());
    subNode.setProperty(propertyName1, CHANGED_STRING);
    // will be updated
    originalNode.setProperty(propertyName1, CHANGED_STRING);
    superuser.save();
    originalVersionManager.checkin(subNode.getPath());
    originalVersionManager.checkin(originalPath);
    VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
    Node subNodeW2 = nodeToMerge.getNode(nodeName2);
    versionManager.checkout(subNodeW2.getPath());
    subNodeW2.setProperty(propertyName1, CHANGED_STRING);
    superuserW2.save();
    versionManager.checkin(subNodeW2.getPath());
    versionManager.checkout(nodeToMerge.getPath());
    // merge, besteffort set to true
    versionManager.merge(nodeToMerge.getPath(), workspace.getName(), true);
    // sub node should not be touched because merging failed
    assertTrue(subNodeW2.getProperty(propertyName1).getString().equals(""));
    // test root node should be touched because update
    assertFalse(nodeToMerge.getProperty(propertyName1).getString().equals(nodeToMerge.getName()));
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2