It's all about the answers!

Ask a question

Precondition plugin to check if there are any approvals on the WI on transition to a target state.


Vikas Kumar (1313) | asked Mar 13, 4:18 p.m.

 Hello,

I am developing a precondition server side plugin and the requirement is to check if there are any approvals of type "Review" on the WI on transition to a target state. But my code is returning an empty list of approvals even though there are approvals on the workitem. Below is my code:

IWorkItem workingCopy = (IWorkItem) workItemServer.getAuditableCommon()
.resolveAuditable(target, IWorkItem.FULL_PROFILE, monitor)
.getWorkingCopy();
IApprovals approvals = workingCopy.getApprovals();
String reviewType="com.ibm.team.workitem.approvalType.review";
List<IApproval> approvalsList = approvals.getContents();
for(IApproval approval :approvalsList){
IApprovalDescriptor appDesc = approval.getDescriptor();
String approvalTypeNew = appDesc.getTypeIdentifier();
if(approvalTypeNew.equalsIgnoreCase(reviewType))
{
return true;
}
}

Can someone let me know how do I get the approvals if I am doing it wrong.

Thanks

Accepted answer


permanent link
Ralph Schoon (63.5k33646) | answered Mar 14, 3:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I don't know what that unformatted mess of code does. In general what you would do is
Get the approvals.

        IApprovals wiApprovals = newState.getApprovals();
        List<iapprovaldescriptor> descriptors = wiApprovals.getDescriptors();
        if (descriptors.isEmpty()) {
            return; // Nothing to do
        }

</iapprovaldescriptor>


Check if the Approval Type is of interest
        for (IApprovalDescriptor descriptor : descriptors) {
            String approvalType = descriptor.getTypeIdentifier();
            if (WorkItemApprovals.REVIEW_TYPE.getIdentifier().equals(approvalType)) {


Check the state
        // If there is a review check for cumulative state approved
        if (reviewDescriptor != null) {
            // There is an approval and there is a review
            if (WorkItemApprovals.APPROVED_STATE.getIdentifier()
                    .equals(reviewDescriptor.getCumulativeStateIdentifier())) {
                // Review is approved, nothing to check
                return;
            }

There are examples for the API involved on https://rsjazz.wordpress.com . Use the search field in the top right. I can't access my blog at the moment.

Vikas Kumar selected this answer as the correct answer

Comments
Vikas Kumar commented Mar 14, 10:07 a.m.

Thank you Ralph, it worked. 

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.