It's all about the answers!

Ask a question

How to create an Approval Descriptor using java api?


Akshata Kulkarni (37219) | asked Jul 15 '16, 2:43 a.m.
edited Jul 15 '16, 3:22 a.m. by Ralph Schoon (63.1k33645)
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!





Comments
Akshata Kulkarni commented Sep 02 '16, 12:55 a.m.

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

   Thanks in advance!

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Jul 15 '16, 3:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Akshata Kulkarni commented Jul 26 '16, 3:39 a.m.

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!





Akshata Kulkarni commented Sep 02 '16, 12:54 a.m.

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

 Thanks in advance!


Ralph Schoon commented Sep 14 '16, 7:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Ralph Schoon (63.1k33645) | answered Sep 14 '16, 7:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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;
    }


Comments
Akshata Kulkarni commented Sep 23 '16, 9:00 a.m.

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


Ralph Schoon commented Sep 23 '16, 10:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 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.