It's all about the answers!

Ask a question

Obtain with java api the current repository (iTeamRepository) and the current user (iContributor)

Mathieu Defianas (15942738) | asked Oct 11 '13, 3:45 p.m.
edited Oct 11 '13, 3:50 p.m.
I use RTC 4.0.3 and I try to create a java plugin on the server side.
On this program, I try to obtain the current user.

I think that this 2 codes should be correct but I don't know how obtain iTeamRepository.
IContributor iContributor = iTeamRepository.loggedInContributor() ;	
IContributorHandle iContributorHandle = auditableCommon.getUser();	
IContributor iContributor = (IContributor) iTeamRepository.itemManager().fetchCompleteItem(iContributorHandle, IItemManager.DEFAULT, monitor) ;
In this 2 examples, the problem is that iTeamRepository is null ...
I have found code this code but it doesn't work on server-side, only on client-side when you create manually a new session.
ITeamRepository iTeamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(auditableCommon.getRepositoryURI()) ;	
Can you help me ?
Thanks a lot.


2 answers

permanent link
Ralph Schoon (63.0k33645) | answered Oct 11 '13, 5:40 p.m.
There are several examples on

Start here:
continue with

and search the blog. shows details. There is more in the blog.

Ralph Schoon commented Oct 12 '13, 7:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER shows how a server extension works. Please be aware, that the server API works different than the client API. You get the service from AbstractService and don't use getClientlibraries(). I am not sure if you need ITeamRepository in the server API.

permanent link
Mathieu Defianas (15942738) | answered Oct 12 '13, 4:19 p.m.
Hello Ralph,
Thanks for all this information mainly the last comment.
In fact, examining your code example, I have found how obtain the current user with this code :
IContributorHandle iContributorHandle = auditableCommon.getUser();
IContributor iContributor = (IContributor) auditableCommon.resolveAuditable(iContributorHandle,ItemProfile.createFullProfile(IContributor.ITEM_TYPE), monitor);
My problem was that I didn't know the method ItemProfile.createFullProfile.

Otherwise, you are right when you said that ITeamRepository is not necessary because this object is a client-side object and not a server-side.

Finally, with your example, I have discovered that your main class extends "AbstractService". Is it important ? In fact, in my code, I don't use this extended class and I have no problem ... Why ??? I don't know.
Thanks for your help Ralph !

Ralph Schoon commented Oct 14 '13, 2:15 a.m.

You want to extend abstract service, especially since it provides you with getService() to get other service classes (analogue to the getClientLibrary() in the client API). It also provides you with access to the user context you are running in (getAuthenticatedContributor()) and other context information. Without it you have no way to access data outside of the domain of your extension, because you can't get at the services needed to retrieve the data.

Mathieu Defianas commented Oct 14 '13, 2:48 a.m.

Thanks Ralph.
Have a nice day !

Your answer

Register or to post your answer.