Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Uploading Attachment to WI using server side plugin

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.


0 votes



One answer

Permanent link
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?

0 votes

Comments

 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. 

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.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936

Question asked: May 19 '15, 8:49 a.m.

Question was seen: 2,513 times

Last updated: May 20 '15, 11:07 a.m.

Confirmation Cancel Confirm