It's all about the answers!

Ask a question

we can retrieve contributor handle by email?


lakshmi jyothsna (37117) | asked Jun 20 '17, 11:26 a.m.

 Hi ,


Is it possible to retrieve the contributor handle by email.
we tried as follows :

IContributorHandle fromContributor =
(IContributorHandle)rtcRepository.contributorManager().fetchContributorByUserId("email", nullProgressMonitor);

but it didn't works. Please suggest me how to proceed.

Thanks in advance!

Accepted answer


permanent link
Pascal Hürlimann (16) | answered Jun 20 '17, 4:12 p.m.

Fetching contributors like that will only work if your user ids are actually emails. If you have other user ids but have access to their emails, you have to use a different approach.

This is sort-of pseudo code, but mostly translates to working code. Also, this assumes you're using the server sdk. I've split the functions up to make their intent clear. The first function gets all contributors and iterates over them to find the one matching the email in question. The second function uses framework capabilities to try and retrieve all available contributors. The empty parameters filter nothing, which should return everyone.

public IContributor getByEmail(String email) {
    IContributor[] contributors = getContributors();

for (IContributor contributor : contributors) {
if (contributor.getEmailAddress().equalsIgnoreCase(email)) {
return contributor;
}
}
return null;
}

private IContributor[] getContributors() {
    IContributorRestService.ParmsGetContributors parameter = 
new IContributorRestService.ParmsGetContributors();

try {
return contributorRestService.getContributors(parameter);
} catch (TeamRepositoryException e) {
return new IContributor[0];
}
}

lakshmi jyothsna selected this answer as the correct answer

Comments
lakshmi jyothsna commented Jun 20 '17, 11:32 p.m. | edited Jun 21 '17, 4:09 a.m.

 Hi Pascal,


Thanks for your reply. I will try the suggestion . 


lakshmi jyothsna commented Jun 22 '17, 1:55 a.m. | edited Nov 16 '17, 9:20 a.m.

 

HI Pascal ,

I followed your suggestion , but in the second function :
private IContributor[] getContributors() {
    IContributorRestService.ParmsGetContributors parameter = 
new IContributorRestService.ParmsGetContributors();

try {
return contributorRestService.getContributors(parameter);
} catch (TeamRepositoryException e) {
return new IContributor[0];
}
}

 how can i initialize the  contributorRestService.getContributors(parameter); ?

If i  did initialization as :  
   IContributorRestService contributorRestService = (IContributorRestService)rtcRepository.getClientLibrary(getClass());
it returns " null " value. So i am unable to find the contributors list in repository  . please suggest me how can i  proceed.? 
Thanks in advance. !!


One other answer



permanent link
Ralph Schoon (63.3k33646) | answered Jun 21 '17, 4:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 You can use Query models as explained here to find items by other values than the key.

See the blog post 

Query Models or how to find stuff with the RTC Java API

 section 

Get contributor by user name

 you would use com.ibm.team.repository.common.model.query.BaseContributorQueryModel.emailAddress() instead of com.ibm.team.repository.common.model.query.BaseContributorQueryModel.name()


Comments
lakshmi jyothsna commented Jun 22 '17, 1:58 a.m.

 Hi  Ralph,


Thanks for reply ! I followed your suggestion but i end up in infinite loop. Please suggest any other possibility.

Thanks in advance.


Ralph Schoon commented Jun 22 '17, 2:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 If you can't get that example working and if you can't provide precise information about what blocks you, I can not help you. There is no other option I am aware of either.´Good luck.

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.