How to check for user existence in jazz repository using Java API
I can add users to members section in team area.
But before the user get added , I want to put a check if the user is valid user and exists in jazz repository. How to put this check if the user exists in jazz repository ? Any example syntax would be of great help.
Part of code which adds the user:
ITeamArea TA = (ITeamArea)teamRepository.itemManager().fetchCompleteItem(newTAHandle,ItemManager.DEFAULT,monitor);
IContributor contributor = teamRepository.contributorManager().fetchContributorByUserId("user_id",monitor);
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy)service.getWorkingCopyManager().createPrivateWorkingCopy(TA);
//adding the user here and want to put a check here
areaWc.getTeam().addContributorsSettingRoleCast(
new IContributor[] {contributor},
new IRole[] {roles});
|
Accepted answer
Ralph Schoon (63.4k●3●36●46)
| answered Jul 11 '13, 4:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
If the User with that ID would not exist, your .fetchContributorByUserId() call would not return a value and probably trow an exception you could catch.
Kaushambi Singh selected this answer as the correct answer
Comments
Kaushambi Singh
commented Jul 11 '13, 8:18 a.m.
Thanks! Ralph.
Kaushambi Singh
commented Jul 12 '13, 6:02 a.m.
Hi Ralph, your answer fits for my questions completely but I also wanted to know how to make that check in general for any other scenario? How can we check if userId exists in jazz repository or not? As I see it, you have the teamRepository.contributorManager() available. You can either use teamRepository.contributorManager().fetchAllContributors(monitor) to fetch all contributors that are registered to the repository, this contains archived users as well. Or you have some ID and can use fetchContributorByID and you will get the contributor if one exists for the ID or an exception if not.
|
One other answer
Why the return value of fetchContributorByUserId() is not null(in fact, it is never null by design) but throwing an exception when the input parameter "userID" does not exist/match in the repository?
The design of RTC user management API is poor!
Comments To document that in case of possible errors no null value is returned and to throw exceptions in error cases is a very clean design. Exceptions can also be easily used together with try/catch by a capable developer to implement control flows.
Albert Yao
commented Jul 12 '17, 12:43 a.m.
3ks, Ralph!
I know the way of controling flows using together with try/catch in Java exception,
but I just do not like it, it looks like intricately and not directly.
|
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.