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!
3 answers
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
java.lang.String
|
getUserId()
Returns the user id being used to login to this repository. |
ITeamRepository
|
teamRepository()
Returns the repository associated with this configuration. |
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.
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
Hi, Ralph Schoon,
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,
I sent you a couple of compressed articles.
I already receive your email,Thanks a lot!
Comments
sam detweiler
Dec 15 '13, 5:52 p.m.configuration.teamRepository().getUserId()
1 vote
chen fengmiao
Dec 16 '13, 8:36 a.m.Hi,sam detweiler,
I don't find the method: