Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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}); 

1

1 vote


Accepted answer

Permanent link
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

0 votes

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.

Or am I misunderstanding the question?


One other answer

Permanent link

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!

0 votes

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.

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

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941

Question asked: Jul 11 '13, 3:21 a.m.

Question was seen: 4,216 times

Last updated: Jul 12 '17, 12:43 a.m.

Confirmation Cancel Confirm