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

How can I get the current user name as logged in user

this my java code:

package org.example.attributecustomization;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.common.IWorkItemCommon;
import com.ibm.team.workitem.common.internal.attributeValueProviders.IConfiguration;
import com.ibm.team.workitem.common.internal.attributeValueProviders.IValueProvider;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IWorkItem;

public class MySecondValueProvider implements IValueProvider<String> {

 
 @Override
 public String getValue(IAttribute attribute, IWorkItem workItem,
   IWorkItemCommon workItemCommon, IConfiguration configuration, IProgressMonitor monitor)
   throws TeamRepositoryException {
  // TODO Auto-generated method stub
  
  return workItemCommon.getAuditableCommon().getUser().getItemId().getUuidValue();
 }

}

I want to get the current user name ,but these code only get the user's UUID.

How can I do? Thank you!

0 votes

Comments

configuration.teamRepository().getUserId()

1 vote

Hi,sam detweiler,

  I don't find the method:

configuration.teamRepository().getUserId()



3 answers

Permanent link
You might also poke around at what methods are available on your return statement.  When you have an IContributor, you can access the getUserId() method.  If getUser() gets you an IContributor object, you might be able to do something like workItemCommon.getAuditableCommon().getUser().getUserId()

0 votes

Comments

Hi, Lauren Hayward Schaefer,

   I want to get the user's name ,not the user's id,what can I do?

IContributor also has a getName() method.  If getUser() gets you an IContributor object, I'd try workItemCommon.getAuditableCommon().getUser().getName().

Hi ,Lauren Hayword Schaefer,

    Thank your answer. but I don't find your provide method.

What type is getUser() returning?

return IContributorHandle

I think what you'll need to do is use the IContributorHandle to get the IContributor and then you can call getUser().  I'm not sure if you'll have access to these particular api's, but you should be able to do something along the lines of the following to get your IContributor:

IRepositoryItemService itemService = getService(IRepositoryItemService.class);
return (IContributor) itemService.fetchItem(workItemCommon.getAuditableCommon().getUser(), null);

Hi,Lauren Hayward Schaefer,

  the method "getService(IRepositoryItemService.class); "  how can I get it?

It need implement which interface or extend which class?

Check out this forum post for more info how to fetch items: https://jazz.net/forum/questions/69960/how-to-use-getcreator

showing 5 of 8 show 3 more comments

Permanent link
 hm.. on the ITeamRepository class

 java.lang.String getUserId()  
          Returns the user id being used to login to this repository.
 
on the IConfiguration class
 ITeamRepository teamRepository()  
          Returns the repository associated with this configuration.

0 votes

Comments

Hi,sam detweiler,

You see I don't find the method teamRepository():

Hi,sam detweiler,

   where can I find your provide API method? And How I get rtc api document?Please help me ,thank you!

 I used the javadoc which is available as part of the rtc product downloads. 


your extension also should  extend the AbstractService class


Permanent link
See https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ for how to use the Eclipse PDE and the SDK for searching. Although described for the client, it works the same for the server SDK. See https://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ for how to setup the SDK.

You need to code like
	private IContributor getContributorFromHandle(IContributorHandle handle) throws TeamRepositoryException{
		return (IContributor) fRepositoryItemService.fetchItem(handle, IRepositoryItemService.COMPLETE);
	}

	fRepositoryItemService=getService(IRepositoryItemService.class);


Not sure if I have an example here, but: https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ shows some of the code. You get getService by extending AbstractService.

0 votes

Comments

If you are in China and potentially some other countries, Wordpress is banned - by the government. I have readers from China, but they apparently use a VPN or other solution to get to what they are not supposed to be getting at.

Hi, Ralph Schoon,

  Could you send this page's  content to my email:chenfengmiao@sina.cn
Thanks a lot!

I sent you a couple of compressed articles.

I already receive your email,Thanks a lot!

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,936
× 411

Question asked: Dec 13 '13, 11:09 p.m.

Question was seen: 6,986 times

Last updated: Apr 15 '14, 2:54 a.m.

Confirmation Cancel Confirm