It's all about the answers!

Ask a question

Require comments


Steven Melcher (6012831) | asked Jul 29 '11, 2:57 p.m.
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)?

One answer



permanent link
Eduardo Bello (4401922) | answered Jul 29 '11, 5:09 p.m.
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);
}
}
}

Your answer


Register or to post your answer.