Search in sources :

Example 6 with Version

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

the class ServerVersionManager method restoreVI.

@Override
public void restoreVI(String absPath, String versionIdentifier, boolean removeExisting) throws RepositoryException, RemoteException {
    try {
        Version version = (Version) session.getNodeByIdentifier(versionIdentifier);
        manager.restore(absPath, version, removeExisting);
    } catch (RepositoryException e) {
        throw getRepositoryException(e);
    }
}
Also used : Version(javax.jcr.version.Version) RemoteVersion(org.apache.jackrabbit.rmi.remote.RemoteVersion) RepositoryException(javax.jcr.RepositoryException)

Example 7 with Version

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

the class VersionHistoryTest method testGetVersion.

/**
     * Test VersionHistory.getVersion(String versionName) if 'versionName' is
     * the name of an existing version (created by Node.checkin()).
     *
     * @see VersionHistory#getVersion(String)
     */
public void testGetVersion() throws RepositoryException {
    Version v = versionManager.checkin(versionableNode.getPath());
    Version v2 = vHistory.getVersion(v.getName());
    assertTrue("VersionHistory.getVersion(String versionName) must return the version that is identified by the versionName specified, if versionName is the name of a version created by Node.checkin().", v.isSame(v2));
}
Also used : Version(javax.jcr.version.Version)

Example 8 with Version

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

the class VersionHistoryTest method testInitiallyGetAllVersionsContainsTheRootVersion.

/**
     * Test if the iterator returned by {@link javax.jcr.version.VersionHistory#getAllVersions()}
     * contains the root version upon creation of the version history.
     *
     * @see javax.jcr.version.VersionHistory#getRootVersion()
     */
public void testInitiallyGetAllVersionsContainsTheRootVersion() throws RepositoryException {
    Version rootVersion = vHistory.getRootVersion();
    boolean isContained = false;
    for (VersionIterator it = vHistory.getAllVersions(); it.hasNext(); ) {
        isContained |= it.nextVersion().isSame(rootVersion);
    }
    assertTrue("root version must be part of the version history", isContained);
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator)

Example 9 with Version

use of javax.jcr.version.Version 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 10 with Version

use of javax.jcr.version.Version 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)

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