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 VersionControlledResourceImpl method getVersionHistory.
/**
* Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
* If the node is not versionable an exception is thrown.
*
* @return the {@link VersionHistoryResource} associated with this resource.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
* @see javax.jcr.Node#getVersionHistory()
*/
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (!isVersionControlled()) {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
try {
VersionHistory vh = getNode().getVersionHistory();
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 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 CopyTest method testCopy.
public void testCopy() throws RepositoryException {
Workspace wsp = superuser.getWorkspace();
VersionManager vMgr = wsp.getVersionManager();
String srcPath = versionableNode.getPath();
String dstPath = getProperty("destination");
wsp.copy(srcPath, dstPath);
// check versionable
Node v = superuser.getNode(dstPath);
assertTrue("Copied Node.isNodeType(mix:cersionable) must return true.", v.isNodeType(mixVersionable));
// check different version history
VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
// check if 1 version
assertEquals("Copied node must have 1 version.", 1, getNumberOfVersions(vh2));
// check if jcr:copiedFrom is set correctly
assertTrue("Version history of desination must have a jcr:copiedFrom property", vh2.hasProperty(jcrCopiedFrom));
Node ref = vh2.getProperty(jcrCopiedFrom).getNode();
Version base = vMgr.getBaseVersion(srcPath);
assertTrue("jcr:copiedFrom must point to the base version of the original.", ref.isSame(base));
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class RemoveVersionByLabel method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String path = (String) ctx.get(this.pathKey);
String label = (String) ctx.get(this.labelKey);
if (log.isDebugEnabled()) {
log.debug("Remove version with label " + label + " from node " + path);
}
VersionHistory vh = CommandHelper.getNode(ctx, path).getVersionHistory();
Version v = vh.getVersionByLabel(label);
vh.removeVersion(v.getName());
return false;
}
Aggregations