How to create an Approval Descriptor using java api?
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!
Accepted answer
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?
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
/**
* 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
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); }
Comments
Akshata Kulkarni
Sep 02 '16, 12:55 a.m.Could anyone please give me an update on the question i mentioned above?