use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class RepositoryServiceImpl method removeVersion.
/**
* {@inheritDoc}
*/
public void removeVersion(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId) throws ReferentialIntegrityException, AccessDeniedException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
Node vHistory = getNode(versionHistoryId, sInfo);
Node version = getNode(versionId, sInfo);
if (vHistory instanceof VersionHistory) {
((VersionHistory) vHistory).removeVersion(version.getName());
} else {
throw new RepositoryException("versionHistoryId does not reference a VersionHistor node");
}
return null;
}
}, sInfo);
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class VersionControlledItemCollection method getVersionHistory.
/**
* Returns the {@link 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()
*/
@Override
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
VersionHistory vh = ((Node) item).getVersionHistory();
DavResourceLocator loc = getLocatorFromItem(vh);
return (VersionHistoryResource) createResourceFromLocator(loc);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyVersionHistoryTest method assertExistingHistories.
private static void assertExistingHistories(final Session session, final String... names) throws RepositoryException {
for (final String mixin : MIXINS) {
final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
for (final String name : names) {
final String path = pathPrefix + name;
final VersionHistory history = getVersionHistoryForPath(session, path);
assertNotNull("No history found for " + path, history);
VersionCopyTestUtils.assertLabeledVersions(history);
}
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeCreatesJcrCopiedFrom.
@Test
public void testCopyVersionableNodeCreatesJcrCopiedFrom() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version baseV = toCopy.getBaseVersion();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory copiedVh = copy.getVersionHistory();
assertTrue(copiedVh.hasProperty(VersionConstants.JCR_COPIED_FROM));
Property prop = copiedVh.getProperty(VersionConstants.JCR_COPIED_FROM);
assertEquals(PropertyType.WEAKREFERENCE, prop.getType());
Node copiedFrom = prop.getNode();
assertTrue(baseV.isSame(copiedFrom));
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeClearsVersions.
@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version v1 = toCopy.checkin();
toCopy.checkout();
Version v2 = toCopy.checkin();
toCopy.checkout();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory vh = copy.getVersionHistory();
Version rootV = vh.getRootVersion();
assertEquals(0, rootV.getSuccessors().length);
VersionIterator vItr = vh.getAllVersions();
while (vItr.hasNext()) {
if (!rootV.isSame(vItr.nextVersion())) {
fail("Unexpected version in version history of copied node.");
}
}
try {
vh.getVersion(v1.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
try {
vh.getVersion(v2.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
}
Aggregations