It's all about the answers!

Ask a question

how to test if a work item approval has been deleted during a work item save operation?

Krasimir Malchev (56531) | asked Oct 10 '16, 8:47 a.m.
edited Oct 10 '16, 9:56 a.m.
  I've written a simple operation advisor (precondition) which is executed in response to a work item save operation.
  The advisor has to verify if a work item approval has been removed prior to saving the work item.
  For that purpose the advisor gets the old and the new state (of type IWorkItem) of the work item, fetches their approvals and the corresponding approval descriptors, and verifies if all approval descriptors of the old state are present in the new state. If one of the old state approvals is missing in the new state (verified by the descriptors' equals method) the advisor concludes that an approval has been deleted.
 Another test case is: Instead of deleting the existing approval, the tester creates a new one (along with the existing approval).

  In order to make a test I created a story work item with an approval of type "review".
  Then another approval is created and the work item "Save" button is clicked.
  As a result:

  - the list with approvals fetched from the old and the new states of the work item are different objects.
  - the list with approval descriptors, which are fetched from the old and the new states of the work item are different objects.
   - The corresponding IAapproval and IApprovalDescriptor objects are also different (although only a new approval is created and the existing one is not changed. I'd expect that at least the descriptor of the first approval is the same object in both states).
   - There is no unique approval descriptor ID which can be used to compare old and new state approvals.

Is there a way to test if an approval has been deleted prior to saving the work item?

Your help would be really appreciated!

Source code
Environment: RTC 5.0.2
    public void run (AdvisableOperation operation,
                              IProcessConfigurationElement advisorConfig,
                              IAdvisorInfoCollector collector,
                              IProgressMonitor monitor)
            throws TeamRepositoryException {
        workItemServer = getService (IWorkItemServer.class);

        Object data = operation.getOperationData();
        ISaveParameter saveParameter = null;
        if (data instanceof ISaveParameter) {
            saveParameter = (ISaveParameter) data;

            IAuditable oldState = saveParameter.getOldState();
            // test for newly created work item
            if ( (oldState == null)
                 || !(oldState instanceof IWorkItem)) {

            IWorkItem oldStateFull = (IWorkItem)
                      .resolveAuditable ((IWorkItem) oldState,
                                                    IWorkItem.FULL_PROFILE, null);
            IApprovals oldApprovals = oldStateFull.getApprovals();

            IAuditable newState = saveParameter.getNewState();
            if ( (newState == null)
                 || !(newState instanceof IWorkItem)) {
            IWorkItem newStateFull = (IWorkItem)
                      .resolveAuditable ((IWorkItem) newState,
            IApprovals newApprovals = newStateFull.getApprovals();

            List<IApprovalDescriptor> oldDescrList =
            List<IApprovalDescriptor> newDescrList =

            if ( oldDescrList.size() > 0 ) {
                final Iterator<IApprovalDescriptor> itOldList =
                while ( itOldList.hasNext() ) {
                    IApprovalDescriptor oldDescr =;
                    System.out.println("Print old descriptor to compare");
                    printDescriptorInfo( oldDescr, null );
                    final Iterator<IApprovalDescriptor> itNewList =
                    boolean found =false;
                    while (itNewList.hasNext()) {
                        IApprovalDescriptor newDescr =
                        System.out.println("Print new descriptor to compare");
                        printDescriptorInfo ( newDescr, null);
                        if (oldDescr.equals(newDescr) ||
                           (oldDescr == newDescr) ) {
                            found = true;

                    if( !found ) {
                        String[] values = { String.valueOf (oldStateFull.getId()),
                                            oldDescr.getTypeIdentifier() };
                        String description = NLS.bind (
                                "Work item with id ''{0}'' cannot be saved as the approval with name ''{1}'' of type ''{2}'' has been deleted.",
                        IAdvisorInfo error =
                                .createProblemInfo ("Unable to save the work item",
                        collector.addInfo (error);
                    } else {
                        System.out.println ("Approval "
                                                       + oldDescr.getName()
                                                       + "is found in the new work item state");
            } else {
               System.out.println (
                          "No approval descriptors in old state");
        }//if saveParameter

Best Regards

Accepted answer

permanent link
Ralph Schoon (63.1k33646) | answered Oct 10 '16, 10:35 a.m.
edited Oct 10 '16, 10:36 a.m.
As far as I can tell, the only thing you can do is to use the number of approvals, the type and the other available values to determine if the old and the new approval is the same. There is no UUID for any of these interfaces that I would be aware of that could otherwise be used.
Krasimir Malchev selected this answer as the correct answer

Krasimir Malchev commented Oct 10 '16, 10:39 a.m.

Thanks a lot!

Ralph Schoon commented Oct 10 '16, 10:41 a.m.

I have wondered over this also at some point in time. If you want this to change please create an enhancement request.

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.