Fetching Usernames based on DB User ID

20 Views Asked by At

We are using OOTB history manager functionality for the audit tracking purpose. The history xml however provides the DB user id instead of the actual user name in MDMCE.

Is there any way we can fetch the user name based on DB user id without connecting to DB from our java classes.

In case we need to do that, how do the java class read the encrypted password details from the db.xml file. In case we don't have the password information provided to the application team, and we need to use the encrypted password to connect to DB, how do we do that?

1

There are 1 best solutions below

0
On

first of all, this seems to be a serious bug of the history manager and therefore it would be great if you could open a PMR so that it gets fixed. 

Until this gets fixed you could just iterate through all the users of the company and retrieve their ID and Username. Since this is "brute force" you could cache the result. The steps would be:

get current user: com.ibm.pim.context.Context::getCurrentUser()
get company object: com.ibm.pim.organization.User::getCompany()
get collection for all users: com.ibm.pim.organization.Company::getUsers() -->  com.ibm.pim.collection.PIMCollection<User>
get iterator for collection: com.ibm.pim.collection.PIMCollection<User>::iterator() --> java.util.Iterator<User>
iterate through all users: java.util.Iterator::hasNext()
retrieve user object: java.util.Iterator::next() --> User
get user ID: com.ibm.pim.organization.User::getId()
get username: com.ibm.pim.organization.User::getUserName()
store in HashMap or other caching mechanism