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
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.
Comments
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!