How to check for existing or removed attachments using the Java Client API
Good morning everyone.
I'm asking for clarification on how to manage attachments in a workitem. I'll start by saying that I've already retrieved them through a few calls... but I have the problem of having to manage them, that is, check their presence or absence. I assumed that using getComment, I could get something, but that's not the case... Also because out of four comments, it only finds two, and more importantly, it doesn't tell me if they've been added or removed. I haven't found any other ways to manage them. Do you have any ideas?
In the meantime, here's what I've already tried, this one to find removed attachments:
List<IAttachmentHandle> attachmentDeletedList = wicn.getReferences().getDeletedAttachments();
for(IAttachmentHandle iDeletedAttHandle : attachmentDeletedList) {
IAttachment deletedAtt = iac.resolveAuditable(iDeletedAttHandle,IAttachment.FULL_PROFILE, null);
But it doesn't work, because even if there's a removal on the WorkItem, it doesn't find it, and the ticket I'm passing is the correct one.
This was to retrieve them all:
List<IReference> referenceList = wicn.getReferences().getReferences(WorkItemEndPoints.ATTACHMENT);
But here too, it only finds two of the four comments, the second and third in chronological order. All things considered, I'd like not to add attachments if I've already done so. Thanks everyone in advance.
Accepted answer
For existing attachments, this has worked for me:
https://rsjazz.wordpress.com/2012/09/21/downloading-attachments-from-work-items/
I also find all attachments here:
https://github.com/jazz-community/work-item-command-line/blob/master/com.ibm.js.team.workitem.commandline/src/main/java/com/ibm/js/team/workitem/commandline/utils/AttachmentUtil.java
https://github.com/jazz-community/work-item-command-line/blob/master/com.ibm.js.team.workitem.commandline/src/main/java/com/ibm/js/team/workitem/commandline/utils/AttachmentUtil.java
I do not know if you can find deleted attachments. The reason for having delete is to get rid of confidential data. There was a difference of removing or deleting an attachment. In the past we had both. E.g. if the attachment is attached to multiple work items Today there is only delete. There was a service tool to get rid of unwanted attachments, when this was possible in the past. I do not know if something like that still exists.