Search in sources :

Example 36 with VersionIterator

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

the class RestoreTest method testRestoreInvalidVersion2.

/**
 * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
 *
 * @throws RepositoryException
 */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionableNode.restore(invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 37 with VersionIterator

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

the class RestoreTest method testRestoreInvalidVersion2Jcr2.

/**
 * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
 *
 * @throws RepositoryException
 */
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionManager.restore(versionableNode.getPath(), invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 38 with VersionIterator

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

the class VersionHistoryResourceImpl method initProperties.

// --------------------------------------------------------------------------
/**
 * Fill the property set for this resource.
 */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        // change resource type defined by default item collection
        properties.add(new ResourceType(new int[] { ResourceType.COLLECTION, ResourceType.VERSION_HISTORY }));
        // required root-version property for version-history resource
        try {
            String rootVersionHref = getLocatorFromNode(((VersionHistory) getNode()).getRootVersion()).getHref(false);
            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
        // required, protected version-set property for version-history resource
        try {
            VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
            ArrayList<Version> l = new ArrayList<Version>();
            while (vIter.hasNext()) {
                l.add(vIter.nextVersion());
            }
            properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, l.toArray(new Version[l.size()]), true, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) ResourceType(org.apache.jackrabbit.webdav.property.ResourceType) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 39 with VersionIterator

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

the class LsVersions method execute.

/**
 * {@inheritDoc}
 */
public boolean execute(Context ctx) throws Exception {
    String path = (String) ctx.get(this.pathKey);
    Node n = CommandHelper.getNode(ctx, path);
    // header
    int[] width = new int[] { 20, 50 };
    String[] header = new String[] { bundle.getString("word.version"), bundle.getString("word.labels") };
    // print header
    PrintHelper.printRow(ctx, width, header);
    // print separator
    PrintHelper.printSeparatorRow(ctx, width, '-');
    VersionIterator iter = n.getVersionHistory().getAllVersions();
    while (iter.hasNext()) {
        Version v = iter.nextVersion();
        Collection row = new ArrayList();
        row.add(v.getName());
        row.add(Arrays.asList(n.getVersionHistory().getVersionLabels(v)));
        PrintHelper.printRow(ctx, width, row);
    }
    return false;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) Collection(java.util.Collection)

Example 40 with VersionIterator

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

the class RemoveVersionTest method testRemoveAllVersions.

/**
 * Creates 3 versions and removes them afterwards. Checks if version history
 * was purged, too.
 *
 * Tests error reported in JCR-2601
 *
 * @throws Exception if an error occurs
 */
public void testRemoveAllVersions() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    superuser.save();
    String path = n.getPath();
    // create some versions
    VersionManager mgr = superuser.getWorkspace().getVersionManager();
    // v1.0
    mgr.checkpoint(path);
    // v1.1
    mgr.checkpoint(path);
    // v1.2
    mgr.checkpoint(path);
    // get version history
    VersionHistory vh = mgr.getVersionHistory(path);
    String id = vh.getIdentifier();
    // remove versionable node
    n.remove();
    superuser.save();
    // get the names of the versions
    List<String> names = new LinkedList<String>();
    VersionIterator vit = vh.getAllVersions();
    while (vit.hasNext()) {
        Version v = vit.nextVersion();
        if (!v.getName().equals("jcr:rootVersion")) {
            names.add(v.getName());
        }
    }
    assertEquals("Number of versions", 3, names.size());
    // remove all versions
    for (String name : names) {
        vh.removeVersion(name);
    }
    // assert that version history is gone
    try {
        superuser.getNodeByIdentifier(id);
        fail("Version history not removed after last version was removed.");
    } catch (RepositoryException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) LinkedList(java.util.LinkedList)

Aggregations

VersionIterator (javax.jcr.version.VersionIterator)45 Version (javax.jcr.version.Version)31 VersionHistory (javax.jcr.version.VersionHistory)23 Node (javax.jcr.Node)18 RepositoryException (javax.jcr.RepositoryException)12 VersionManager (javax.jcr.version.VersionManager)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 Session (javax.jcr.Session)8 Resource (org.apache.sling.api.resource.Resource)7 VersionException (javax.jcr.version.VersionException)5 Iterator (java.util.Iterator)4 NodeType (javax.jcr.nodetype.NodeType)4 List (java.util.List)3 NodeIterator (javax.jcr.NodeIterator)3 Workspace (javax.jcr.Workspace)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 KyloVersion (com.thinkbiganalytics.KyloVersion)2 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)2