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

How to use createAttachment to upload attachments on server using RTC Java API

Hi,

I was trying to upload attachments on RTC server using Java API (SDK). On the client, there's nice blog for that:
https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/comment-page-1/#comment-4906
So we could use createAttachment to create and attach the file on client (IWorkItemClient). However, on the server API (IWorkItemServer), it's different and createAttachment accept only two parameters (projectArea, monitor). So how can I use createAttachment or other method to upload or create attachment on the server using server Java API? 

Thanks for the help.

Hongwu

1

1 vote



3 answers

Permanent link
As answered on the blog, you use

IWorkItemCommon.createAttachment(projectArea, monitor)

Then you use the code from IWorkItemClient....
      IAttachment attachment= IWorkItemCommon.createAttachment(projectArea, monitor);
        Attachment attachment= (Attachment) fAuditableCommon.createAuditable(IAttachment.ITEM_TYPE);
        attachment.setName(name);
        attachment.setDescription(description);
        IContent content= fTeamRepository.contentManager().storeContent(contentType, characterEncoding, inputStream, null, monitor);
        attachment.setContent(content);
The WorkItemCommon should be available in the server API. The rest should be doable with the server API.

0 votes


Permanent link
Hi Ralph,

Thanks a lot. I am trying to do that on the WI save participating, so now struggling with little "content".  Do you know how to get the contentManager as seems no ITeamRepository on server?

Thanks,
Hongwu

0 votes


Permanent link
You can access the ITeamRepository on the server, I believe, using getOrigin() on an object such as the work item. I am not sure if that is the best way to or if there are other ways to get a content manager in the server API, but this is an answer from Sam: https://jazz.net/forum/questions/66437/problems-accesing-files-content-in-a-server-side-plugin/66440

0 votes

Comments

It's strange that it could not find ITeamRepository or IContentManager in the SDK libraries. 

Not sure how your setup looks like, but I have multiple hits if I do a search for references or a Java class search.

I followed your extension workshop development. Everything seems working fine. Is it because I am using the 3.0.1.x version?

No, independent of the version you should have plenty of hits. ITeamRepository shows several thousand times in my setup. Check if https://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ and the following post https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ help. DId you add the sources to the Java Search as explained in the first lab of the Extensions Workshop? If not, do it again.

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,930

Question asked: Feb 10 '15, 7:50 a.m.

Question was seen: 5,392 times

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

Confirmation Cancel Confirm