use of javax.jcr.version.ActivityViolationException in project jackrabbit by apache.
the class InternalVersionManagerImpl method canCheckout.
/**
* {@inheritDoc}
*
* this method currently does no modifications to the persistence and just
* checks if the checkout is valid in respect to a possible activity set on
* the session
*/
public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
NodeId baseId = state.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId();
if (activityId != null) {
// exist in 'this' workspace
if (stateMgr.hasNodeReferences(activityId)) {
try {
NodeReferences refs = stateMgr.getNodeReferences(activityId);
for (PropertyId id : refs.getReferences()) {
if (!state.hasNode(id.getParentId())) {
throw new ActivityViolationException("Unable to checkout. " + "Activity is already used for the same node in " + "another workspace.");
}
}
} catch (ItemStateException e) {
throw new RepositoryException("Error during checkout.", e);
}
}
// If there is a version in H that is not an eventual predecessor of N but
// whose jcr:activity references A, then the checkout fails with an
// ActivityViolationException
InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
InternalVersion version = a.getLatestVersion(history);
if (version != null) {
InternalVersion baseVersion = (InternalVersion) getItem(baseId);
while (baseVersion != null && !baseVersion.getId().equals(version.getId())) {
baseVersion = baseVersion.getLinearPredecessor();
}
if (baseVersion == null) {
throw new ActivityViolationException("Unable to checkout. " + "Activity is used by another version on a different branch: " + version.getName());
}
}
}
return baseId;
}
Aggregations