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.
Comments
Hi Ralph, first of all, thanks for the reply and sorry for the duplicate question. It wasn't my intention, but everything crashed while I was posting it and I didn't notice.
That said, I looked at those APIs you mentioned and started with them, but there's one thing (maybe it's my fault) I can't find, but you've shown me some additional resources that I'll look for...
Meanwhile, I have a question: when scrolling through the attachments, I have no way of finding the name, except by "reading" the comments, and the comments are for each attachment. So if I attach the same file twice with the same name, I get two identical comments, but for the same purpose, they're different, so I don't have the control I'm looking for... And more specifically, I'd like to attach some files to the ticket, but if I've already attached them, don't repeat the operation. Likewise, I can remove them if necessary, provided I haven't already done so. In the meantime, thanks. I'll take a look at the link you sent me.
Don't worry about the duplicate question. This happens.
With respect to the API and implementation, it is what it is. It might not be ideal. If you have suggestions, you can create an idea on the IBM Ideas portal.