use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class DavResourceFactoryImpl method createResourceForItem.
/**
* Tries to retrieve the repository item defined by the locator's resource
* path and build the corresponding WebDAV resource. The following distinction
* is made between items: Version nodes, VersionHistory nodes, root node,
* unspecified nodes and finally property items.
*
* @param locator
* @param sessionImpl
* @return DavResource representing a repository item.
* @throws RepositoryException if {@link javax.jcr.Session#getItem(String)} fails.
*/
private DavResource createResourceForItem(DavResourceLocator locator, JcrDavSession sessionImpl) throws RepositoryException, DavException {
DavResource resource;
Item item = getItem(sessionImpl, locator);
if (item.isNode()) {
// create special resources for Version and VersionHistory
if (item instanceof Version) {
resource = new VersionItemCollection(locator, sessionImpl, this, item);
} else if (item instanceof VersionHistory) {
resource = new VersionHistoryItemCollection(locator, sessionImpl, this, item);
} else {
resource = new VersionControlledItemCollection(locator, sessionImpl, this, item);
}
} else {
resource = new DefaultItemResource(locator, sessionImpl, this, item);
}
return resource;
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class NodeImpl method restore.
/**
* Common internal restore method for the various Node#restore calls.
*
* @param targetNode
* @param relQPath
* @param version
* @param removeExisting
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws VersionException
* @throws ConstraintViolationException
* @throws UnsupportedRepositoryOperationException
* @throws LockException
* @throws InvalidItemStateException
* @throws RepositoryException
*/
private void restore(NodeImpl targetNode, Path relQPath, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
if (relQPath == null) {
/* restore target already exists. */
// target must be versionable
targetNode.checkIsVersionable();
VersionHistory vH = targetNode.getVersionHistory();
// version must be a version of the target node
if (!vH.isSame(version.getContainingHistory())) {
throw new VersionException("Version " + version + " does not correspond to the restore target.");
}
// version must not be the root version
if (vH.getRootVersion().isSame(version)) {
throw new VersionException("Attempt to restore root version.");
}
targetNode.checkIsWritable();
targetNode.checkIsLocked();
} else {
/* If no node exists at relPath then a VersionException is thrown if
the parent node is not checked out. */
if (!targetNode.isCheckedOut()) {
throw new VersionException("Parent " + targetNode.safeGetJCRPath() + " for non-existing restore target '" + LogUtil.safeGetJCRPath(relQPath, session.getPathResolver()) + "' must be checked out.");
}
targetNode.checkIsLocked();
// NOTE: check for nodetype constraint violation is left to the 'server'
}
NodeState versionState = session.getVersionState(version);
session.getVersionStateManager().restore(targetNode.getNodeState(), relQPath, versionState, removeExisting);
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class RepositoryServiceImpl method removeVersionLabel.
/**
* {@inheritDoc}
*/
public void removeVersionLabel(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId, final Name label) throws VersionException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
String jcrLabel;
jcrLabel = sInfo.getNamePathResolver().getJCRName((label));
Node vHistory = getNode(versionHistoryId, sInfo);
if (vHistory instanceof VersionHistory) {
((VersionHistory) vHistory).removeVersionLabel(jcrLabel);
} else {
throw new RepositoryException("versionHistoryId does not reference a VersionHistory node");
}
return null;
}
}, sInfo);
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class RepositoryServiceImpl method addVersionLabel.
/**
* {@inheritDoc}
*/
public void addVersionLabel(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId, final Name label, final boolean moveLabel) throws VersionException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
String jcrLabel;
jcrLabel = sInfo.getNamePathResolver().getJCRName(label);
Node version = getNode(versionId, sInfo);
Node vHistory = getNode(versionHistoryId, sInfo);
if (vHistory instanceof VersionHistory) {
((VersionHistory) vHistory).addVersionLabel(version.getName(), jcrLabel, moveLabel);
} else {
throw new RepositoryException("versionHistoryId does not reference a VersionHistory node");
}
return null;
}
}, sInfo);
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class AbstractRepositoryTest method createVersionable.
protected Node createVersionable(Node parent) throws RepositoryException {
Node versionable = parent.addNode("versionable", "nt:myversionable");
versionable.setProperty("foo", "A");
parent.save();
VersionHistory history = versionable.getVersionHistory();
Version versionA = versionable.checkin();
history.addVersionLabel(versionA.getName(), "labelA", false);
versionable.checkout();
versionable.setProperty("foo", "B");
parent.save();
Version versionB = versionable.checkin();
history.addVersionLabel(versionB.getName(), "labelB", false);
return versionable;
}
Aggregations