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

How to create an Approval Descriptor using java api?

Hello,

I am using java apis to create a descrioptor object and search it in IApprovals.
To create a descriptor Object i used the IBM provided code snippet:
..
IApprovals approvals = workItem.getApprovals();         
IApprovalDescriptor descriptor= approvals.createDescriptor(WorkItemApprovals.REVIEW_TYPE.getIdentifier(), fApprovalName);

but when i get the object as
...
approval.getDescriptor().getName()
it is returning null.

Any suggestions on how it can be done? Thanks in advance!




0 votes

Comments

  Could anyone please give me an update on the question i mentioned above?

   Thanks in advance!


Accepted answer

Permanent link
Please see https://rsjazz.wordpress.com/2012/10/01/adding-approvals-to-work-items-using-the-plain-java-client-libraries/ or https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/
Ralph Schoon selected this answer as the correct answer

0 votes

Comments

Thanks for the response.

The above mentioned posts explain how to create an approval Object and save the same. But i need to create an approval Object and check if the workitem already has the approval Object and not save it.

Therefore , when i create an approval Object and without saving it if i get the descriptor name as :

approval.getDescriptor().getName() it returns null

Is there any way i can check if an approval object already exists in the workitem using java api?

Thanks in advance!




 Could anyone please give me an update on the question i mentioned above?

 Thanks in advance!

Obviously you would retrieve all the approvals and then have to go through these. As far as I can tell, the only information you can use to compare are type and name.


One other answer

Permanent link
Some example code:

    /**
     * Tries to find a an approval from the approval data and deletes it if it
     * can be found Removes only the first instance found that matches.
     *
     * @param approvalData
     * @return
     */
    private boolean updateRemoveApproval(ApprovalInputData approvalData) {
        IApprovals approvals = getWorkItem().getApprovals();
        List<IApproval> approvalContent = approvals.getContents();
        for (IApproval anApproval : approvalContent) {
            IApprovalDescriptor descriptor = anApproval.getDescriptor();
            if (descriptor.getTypeIdentifier().equals(
                    approvalData.getApprovalType())
                    && descriptor.getName().equals(
                            approvalData.getApprovalName())) {
                approvals.remove(anApproval);
                approvals.remove(descriptor);
                return true;
            }
        }
        return false;
    }

0 votes

Comments

I have used the similar code as mentioned above. I wanted to eliminate the loops and make a quick search using java comparator.That is the reason i created an approval object and set its name and type to proper values and then used java 's comparator function to search the particular object.Comparator function required the attributes to compare.Therefore when tried to fetch the approval's name using :

approval.getDescriptor().getName()

it returned null.Did it return null as i had not save this approval Object?
Is there any other way to make a quick search?Thanks in advance

I think something similar is in the links:

Please see https://rsjazz.wordpress.com/2012/10/01/adding-approvals-to-work-items-using-the-plain-java-client-libraries/ or https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/

That I provided above already.

            IApprovalDescriptor descriptor = approvals.createDescriptor(
                    WorkItemApprovals.REVIEW_TYPE.getIdentifier(),
                    fApprovalName);
            for (IContributorHandle reviewer : reviewers) {
                IApproval approval = approvals.createApproval(descriptor,
                        reviewer);
                approvals.add(approval);
            }

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: Jul 15 '16, 2:43 a.m.

Question was seen: 2,794 times

Last updated: Sep 23 '16, 10:24 a.m.

Confirmation Cancel Confirm