It's all about the answers!

Ask a question

Uploading Attachment to WI using server side plugin


Parveen Patel (771427) | asked May 19 '15, 8:49 a.m.
Hi,
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



permanent link
Ralph Schoon (63.5k33646) | answered May 19 '15, 9:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Can you look at https://jazz.net/forum/questions/173752/how-to-use-createattachment-to-upload-attachments-on-server-using-rtc-java-api if that answers your questions?

Comments
Parveen Patel commented May 20 '15, 2:52 a.m.

 Hi Ralph,

Thanks for your response,as given in above forum question I have used createAttachment(projectArea,monitor) method,
but I am struggling at how to create attachment reference as we do in client side code as following:
newAttachment = workItemClient.saveAttachment(newAttachment,monitor);
IItemReference reference = WorkItemLinkType.createAttachmentReference(newAttachment);
workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT,reference);
How we should implement in server plugin.
Please,provide some guidance for this.

Thanks in advance. 


Ralph Schoon commented May 20 '15, 10:53 a.m. | edited May 20 '15, 11:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Ralph Schoon commented May 20 '15, 11:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

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.