lockHelper.checkLock(token, associatedObject,
namespaceConfig.getCreateRevisionContentAction());
setDefaultProperties(associatedObject, newRevisionDescriptor);
Uri objectUri = namespace.getUri(token, strUri);
// Retrieve the revision table
NodeRevisionDescriptors revisionDescriptors =
objectUri.getStore()
.retrieveRevisionDescriptors(objectUri);
if (!revisionDescriptors.isVersioned()) {
// Invalid function call : we try to create a revision, but the
// descriptors won't allow it
throw new NodeNotVersionedException(strUri);
}
// Retrieve the old revision descriptor, just to make sure that the old
// revision we base the new one upon really exists
NodeRevisionDescriptor realOldRevisionDescriptor =
objectUri.getStore().retrieveRevisionDescriptor
(objectUri, basedOnRevisionNumber);
// We check that the old revision doesn't have successors, that is we :
// - check to see if it's the latest revision in a branch
// - store that information for later use
NodeRevisionNumber latestNumberInBranch =
revisionDescriptors.getLatestRevision
(realOldRevisionDescriptor.getBranchName());
if (!realOldRevisionDescriptor.getRevisionNumber()
.equals(latestNumberInBranch)) {
throw new RevisionAlreadyExistException
(objectUri.toString(), new NodeRevisionNumber
(basedOnRevisionNumber));
}
// Next, generate the new revision's number
newRevisionDescriptor.setRevisionNumber
(new NodeRevisionNumber(basedOnRevisionNumber));
// Set the creation date
newRevisionDescriptor.setCreationDate(new Date());
// Set the creation user
setCreationUser(token, newRevisionDescriptor);
// Initialize the branch name in the new descriptor
newRevisionDescriptor.setBranchName
(realOldRevisionDescriptor.getBranchName());
// Fire event
if ( ContentEvent.CREATE.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(ContentEvent.CREATE, new ContentEvent(this, token, namespace, objectUri.toString(), revisionDescriptors, newRevisionDescriptor, revisionContent));
// Invoke interceptors
invokeInterceptors(token, revisionDescriptors, newRevisionDescriptor,
revisionContent, PRE_STORE);
// Update the revision graph in the revision descriptors
revisionDescriptors
.addSuccessor(revisionDescriptors.getLatestRevision(newRevisionDescriptor.getBranchName()),
newRevisionDescriptor.getRevisionNumber());
revisionDescriptors
.setSuccessors(newRevisionDescriptor.getRevisionNumber(), new Vector());
revisionDescriptors
.setLatestRevision(newRevisionDescriptor.getBranchName(),
newRevisionDescriptor.getRevisionNumber());
if (revisionContent != null) {
// Storing the new revision contents
objectUri.getStore()
.createRevisionContent(objectUri, newRevisionDescriptor,
revisionContent);
}
// Now creating the revision desriptor in the store
newRevisionDescriptor.setModificationDate(newRevisionDescriptor.getCreationDate());
newRevisionDescriptor.setModificationUser(
securityHelper.getPrincipal(token).getPath().lastSegment());
objectUri.getStore()
.createRevisionDescriptor(objectUri, newRevisionDescriptor);
// We now store the updated revision descriptors
try {
objectUri.getStore()
.storeRevisionDescriptors(objectUri, revisionDescriptors);
} catch (RevisionDescriptorNotFoundException e) {
// Problem ...
e.printStackTrace();
}