Require comments
In RTC 2.0.0.2, is there a way to require a user to enter a comment before saving a work item in a specific state?
I did not see this built-in in the require properties in the Project Configuration.
Is there a way, using the Java API, to get the old copy of the work item and the new copy so that I can compare the comments to see if the user added one (while possibly removing other comments)?
I did not see this built-in in the require properties in the Project Configuration.
Is there a way, using the Java API, to get the old copy of the work item and the new copy so that I can compare the comments to see if the user added one (while possibly removing other comments)?
One answer
In RTC 2.0.0.2, is there a way to require a user to enter a comment before saving a work item in a specific state?
I did not see this built-in in the require properties in the Project Configuration.
Is there a way, using the Java API, to get the old copy of the work item and the new copy so that I can compare the comments to see if the user added one (while possibly removing other comments)?
You can use an IOperationAdvisor to check it.
And the code itself would be something like this (please review it because I didn't test it at all):
public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
// New state comments
IWorkItem workItem = (IWorkItem) saveParameter.getNewState();;
IComments newComments = workItem.getComments();
// Old state comments
IWorkItem oldWorkItem = (IWorkItem) saveParameter.getOldState();
IComments oldComments = (oldWorkItem != null) ? oldWorkItem.getComments(): null;
boolean addedComment = false;
if ((newComments != null) && (newComments.getContents().length > 0)) {
if (oldComments==null || oldComments.getContents().length == 0) {
addedComment = true;
} else {
IComment lastOldComment = oldComments.getContents()[oldComments.getContents().length-1];
IComment lastNewComment = newComments.getContents()[newComments.getContents().length-1];
addedComment = lastNewComment.getCreationDate().after(lastOldComment.getCreationDate());
}
}
if (!addedComment) {
IAdvisorInfo info = collector.createProblemInfo("You have to add a new comment", "You have to add a new comment", "error");
collector.addInfo(info);
}
}
}