It's all about the answers!

Ask a question

How to fetch subscribers name and userid for particular workitem through REST SDK API


Himanshu Vashisth (111) | asked Nov 16 '19, 9:39 a.m.

 How to fetch subscribers name and userid for particular workitem through REST SDK API


Comments
Himanshu Vashisth commented Nov 16 '19, 10:09 a.m.

 Below is my code but its showing com.ibm.team.workitem.common.internal.model.Subscriptions incompatible with com.ibm.team.repository.common.IContributorHandle error 


Please help for the same.

IContributorHandle conHandle = (IContributorHandle) wi.getSubscriptions();



//ITeamRepository repo1 = (ITeamRepository) conHandle.getOrigin();



IContributor contrib = (IContributor) repo.itemManager().fetchCompleteItem(conHandle, IItemManager.DEFAULT, null);




System.out.println("Owner" +contrib.getUserId());

 

One answer



permanent link
Ralph Schoon (63.1k33646) | answered Nov 16 '19, 2:59 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 16 '19, 2:59 p.m.
wi.getSubscriptions() returns a collection. The way you cast indicates you do not see the information. See https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ how to set this up to be able to see the info.

There is no magic here. You iterate the subscribers and resolve the handles. The reverse API is explained here https://rsjazz.wordpress.com/2012/08/02/subscribing-to-a-work-item-using-the-java-api/


Comments
Himanshu Vashisth commented Nov 17 '19, 2:36 a.m. | edited Nov 17 '19, 2:40 a.m.

Hi Ralph 

I am getting below error
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy10 incompatible with com.ibm.team.rtc.foundation.api.common.model.IContributor

 

Below is my code : 
public static void Subs(ITeamRepository repo, IWorkItem wi) throws TeamRepositoryException{
  IWorkItem workitem = workitemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, null);

  
    for(IContributorHandle subscriber : workitem.getSubscriptions().getContents())
    {
    IItemManager itemManager = repo.itemManager();
    IContributor contributor = (IContributor) itemManager.fetchCompleteItem(subscriber , IItemManager.DEFAULT, null);
     contributor.getUserid();
    
    }
}


Ralph Schoon commented Nov 18 '19, 1:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is development and not a guessing game. As far as I can tell, you have the following options:
  1. Follow the links I provided and setup a development environment with the SDK that allows you to see the Java code of the SDK and the API.
  2. Use the JavaDoc provided with the Plain java client libraries and look up the interfaces
  3. Run google and search for the countless examples for code here in the forum or elsewhere
You are asking others to do 1,2 or 3 to help you and that is not a great idea. The next question from you is already in the forum.

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.