use of javax.jcr.version.VersionHistory 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.VersionHistory in project jackrabbit by apache.
the class VersionResourceImpl method getVersionHistory.
/**
* Returns the {@link VersionHistory} associated with the repository version.
* Note: in contrast to a versionable node, the version history of a version
* item is always represented by its nearest ancestor.
*
* @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
* @see javax.jcr.Item#getParent()
*/
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
VersionHistory vh = getVersionHistoryItem();
DavResourceLocator loc = getLocatorFromNode(vh);
DavResource vhr = createResourceFromLocator(loc);
if (vhr instanceof VersionHistoryResource) {
return (VersionHistoryResource) vhr;
} else {
// severe error since resource factory doesn't behave correctly.
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class ResourceFactoryImpl method createResource.
/**
* Tries to retrieve the repository item defined by the locator's resource
* path and build the corresponding WebDAV resource. If the repository
* supports the versioning option different resources are created for
* version, versionhistory and common nodes.
*
* @param node
* @param locator
* @param session
* @return
* @throws DavException
*/
private DavResource createResource(Node node, DavResourceLocator locator, DavSession session) throws DavException {
JcrDavSession.checkImplementation(session);
JcrDavSession sessionImpl = (JcrDavSession) session;
DavResource resource;
if (versioningSupported(sessionImpl.getRepositorySession())) {
// create special resources for Version and VersionHistory
if (node instanceof Version) {
resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
} else if (node instanceof VersionHistory) {
resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
} else {
resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
}
} else {
resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
}
return resource;
}
use of javax.jcr.version.VersionHistory 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
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class VersionHistoryItemCollection method initProperties.
/**
* Fill the property set for this resource.
*/
@Override
protected void initProperties() {
super.initProperties();
// change resource type defined by default item collection
properties.add(new ResourceType(ResourceType.VERSION_HISTORY));
// jcr specific property pointing to the node this history belongs to
try {
properties.add(new DefaultDavProperty<String>(JCR_VERSIONABLEUUID, ((VersionHistory) item).getVersionableIdentifier()));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
Aggregations