Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 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

0 votes


Accepted answer

Permanent link

 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

0 votes

Comments

Thank you Ralph, it worked. 

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Mar 13 '24, 4:18 p.m.

Question was seen: 361 times

Last updated: Mar 14 '24, 10:07 a.m.

Confirmation Cancel Confirm