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 (62.3k●3●36●43)
| 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 Thanks! Ralph. 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.
|