It's all about the answers!

Ask a question

Add Subscriber to a Work item from JAVA API.


Muthukumar C (32712433) | asked May 29 '12, 9:40 a.m.
Hi All,

I am trying to add a Subscriber through java API. I am succeeded partially. My code snippet is as follows.


IContributorHandle user = SourceWI.getCreator();
System.out.println(user.toString());
SourceWI.getSubscriptions().add(user);


But My requirement is that how to pass User Id of my own..
Ofcoourse, i will pass the User ID which is existing in the repository.

Thanks

Accepted answer


permanent link
Andrew Niefer (6235) | answered May 30 '12, 12:21 p.m.
JAZZ DEVELOPER
edited Jun 05 '12, 11:32 a.m.
Hi All,

I am trying to add a Subscriber through java API. I am succeeded partially. My code snippet is as follows.
IContributorHandle user = SourceWI.getCreator();
System.out.println(user.toString());
SourceWI.getSubscriptions().add(user);


But My requirement is that how to pass User Id of my own..
Of course, i will pass the User ID which is existing in the repository.

Thanks


On the client side, there is IContributorManager.fetchContributorByUserId(String userId, IProgressMonitor monitor). You can get the contributor manager from the repository with ITeamRepository.contributorManager().

On the server side, there is IContributorService.fetchContributorByUserId(String userId) which returns an IContributorHandle.  If your code is in a service, you can add a dependency on IContributorService and use IAbstractScmService#getService to get it.  Otherwise you might be able to use OsgiServicesManager.INSTANCE.getService.
Muthukumar C selected this answer as the correct answer

3 other answers



permanent link
Muthukumar C (32712433) | answered May 31 '12, 1:53 a.m.
Hi,

I think your code is for Client side. I want to implement this as Server side plugin code.

Thanks

Hi All,

I am trying to add a Subscriber through java API. I am succeeded partially. My code snippet is as follows.


IContributorHandle user = SourceWI.getCreator();
System.out.println(user.toString());
SourceWI.getSubscriptions().add(user);


But My requirement is that how to pass User Id of my own..
Ofcoourse, i will pass the User ID which is existing in the repository.

Thanks


There is IContributorManager.fetchContributorByUserId(String userId, IProgressMonitor monitor). You can get the contributor manager from the repository with ITeamRepository.contributorManager()

Comments
Andrew Niefer commented Jun 05 '12, 11:33 a.m.
JAZZ DEVELOPER

I edited my post above to add server side information (IContributorService)


permanent link
Muthukumar C (32712433) | answered Jun 13 '12, 6:27 a.m.
Hi All.

Here is the working code to add a Given user id as subscriber [Server Side]

IContributorService IConService = getService(IContributorService.class);
IContributorHandle user = IConService.fetchContributorByUserId("myuserid");
WorkItem.getSubscriptions().add(user);

NOTE :  Its assumed that we are passing the exiting user id. else, a condition to be added to throw User does not exists error message.

Thanks to all !!!


permanent link
Nicolás Rodríguez (3141424) | answered Jul 26 '12, 6:18 p.m.
Hi

I am getting an error when I use the line:

IContributorService IConService = getService(IContributorService.class); 

the exception says: the service cant be found,Do you know why this can be happenning ?

I am using this line in a class that extends from AbstractService and implements IOperationParticipant

Your answer


Register or to post your answer.