Uploading Attachment to WI using server side plugin
I have successfully added attachment to WI using java client side api ,there is nice blog I have used example given in below blog for that
https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/
Now,I am trying to implement upload attachment to WI using server side API but I am not able to find which server side api I have to use to upload attachment to WI.
I have used this createAttachment(projectArea,monitor) method as below:
IAttachment attachment= workItemCommon.createAttachment(projectArea, monitor);
attachment.setName(attachmentFile.getName());
I have read the following forum question regarding How to read file content
https://jazz.net/forum/questions/167302/how-can-i-read-an-attachment-with-the-serverside-api
from this I got idea about how to read content of file,in next step I want to attach that file to WI.
But I am facing problem how I can use this to read attachment and add that attachment to WI.
Please help me with this,how to use createAttachment() method and add attachment or link that attachment to WI.
One answer
Comments
Hi Ralph,
If you carefully read this answer: https://jazz.net/forum/questions/173752/how-to-use-createattachment-to-upload-attachments-on-server-using-rtc-java-api/173755 you can see a small code snippet that is in the client API that is not available in the server API. However, that snippet only uses WorkItemCommon API and you can thus just create that specific method in your advisor. E.g.
private IAttachment myCreateAttachment(IProjectAreaHandle projectArea, IProgressMonitor monitor) throws TeamRepositoryException { Attachment attachment= (Attachment) fAuditableCommon.createAuditable(IAttachment.ITEM_TYPE); attachment.setProjectArea(projectArea); PermissionContext.setDefault(attachment); return attachment; }
I think that should work.
You can find the missing code in com.ibm.team.workitem.common.internal.WorkItemClient
some other code that might be missing is
public IAttachment createAttachment(IProjectAreaHandle projectArea, String name, String description, String contentType, String characterEncoding, InputStream inputStream, IProgressMonitor monitor) throws TeamRepositoryException {IAttachment attachment= createAttachment(projectArea, monitor); attachment.setName(name); attachment.setDescription(description); IContent content= fTeamRepository.contentManager().storeContent(contentType, characterEncoding, inputStream, null, monitor); attachment.setContent(content); return saveAttachment(attachment, monitor); }
I think by using the code that is available on the IWorkItemCommon and copying the code that is exclusively in IWorkItemClient - a small bit - and creating your own method from that, you should be able to do this.