It's all about the answers!

Ask a question

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


chen fengmiao (7022631) | asked Dec 13 '13, 11:09 p.m.
edited Apr 15 '14, 2:54 a.m. by Ralph Schoon (55.5k23642)

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!


Comments
1
sam detweiler commented Dec 15 '13, 5:51 p.m. | edited Dec 15 '13, 5:52 p.m.

configuration.teamRepository().getUserId()


chen fengmiao commented Dec 16 '13, 8:36 a.m.

Hi,sam detweiler,

  I don't find the method:

configuration.teamRepository().getUserId()

3 answers



permanent link
Lauren Hayward Schaefer (3.3k11127) | answered Dec 16 '13, 8:03 a.m.
JAZZ DEVELOPER
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()

Comments
chen fengmiao commented Dec 16 '13, 8:21 a.m.

Hi, Lauren Hayward Schaefer,

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


Lauren Hayward Schaefer commented Dec 16 '13, 8:25 a.m.
JAZZ DEVELOPER

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


chen fengmiao commented Dec 16 '13, 8:33 a.m.

Hi ,Lauren Hayword Schaefer,

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


Lauren Hayward Schaefer commented Dec 16 '13, 8:42 a.m.
JAZZ DEVELOPER

What type is getUser() returning?


chen fengmiao commented Dec 16 '13, 10:08 a.m.

return IContributorHandle


Lauren Hayward Schaefer commented Dec 16 '13, 11:02 a.m. | edited Dec 16 '13, 11:03 a.m.
JAZZ DEVELOPER

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


chen fengmiao commented Dec 16 '13, 11:23 a.m.

Hi,Lauren Hayward Schaefer,

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

It need implement which interface or extend which class?


Lauren Hayward Schaefer commented Dec 16 '13, 11:49 a.m.
JAZZ DEVELOPER

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
sam detweiler (12.4k6173200) | answered Dec 16 '13, 8:51 a.m.
 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.

Comments
chen fengmiao commented Dec 16 '13, 11:28 a.m.

Hi,sam detweiler,

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


chen fengmiao commented Dec 17 '13, 8:29 a.m.

Hi,sam detweiler,

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


sam detweiler commented Dec 17 '13, 10:37 a.m.

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


your extension also should  extend the AbstractService class


permanent link
Ralph Schoon (55.5k23642) | answered Dec 17 '13, 9:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Comments

Ralph Schoon commented Dec 17 '13, 10:06 a.m. | edited Dec 17 '13, 10:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


chen fengmiao commented Dec 17 '13, 10:14 a.m.

Hi, Ralph Schoon,

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


Ralph Schoon commented Dec 17 '13, 10:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I sent you a couple of compressed articles.


chen fengmiao commented Dec 17 '13, 11:21 a.m.

I already receive your email,Thanks a lot!

Your answer


Register or to post your answer.