It's all about the answers!

Ask a question

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


1
1
Hongwu Wang (1836) | asked Feb 10 '15, 7:50 a.m.
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

3 answers



permanent link
Ralph Schoon (63.6k33646) | answered Feb 10 '15, 8:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited May 20 '15, 11:02 a.m.
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.

permanent link
Hongwu Wang (1836) | answered Feb 10 '15, 9:29 a.m.
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

permanent link
Ralph Schoon (63.6k33646) | answered Feb 10 '15, 9:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Hongwu Wang commented Feb 10 '15, 10:09 a.m.

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


Ralph Schoon commented Feb 10 '15, 10:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Hongwu Wang commented Feb 10 '15, 10:30 a.m.

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


Ralph Schoon commented Feb 10 '15, 10:46 a.m. | edited Feb 10 '15, 10:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 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.