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
}
}
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
}
}
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());
}
}
}
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;
}
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
}
}
Aggregations