-
1. Re: How can I retrieve the email address of a user ?
mstruk Apr 1, 2010 9:08 PM (in response to goschan)According to Portlet 2.0 Specification PLT.21.2 you should get the user's email (if it's available) by using the following code:
{code}
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String userEmail = (userInfo!=null) ? (String)
userInfo.get(PortletRequest.P3PUserInfos.USER_HOMEINFO_ONLINE_EMAIL) : null;if (userEmail == null)
{
userEmail = (userInfo!=null) ? (String)
userInfo.get(PortletRequest.P3PUserInfos.USER_BUSINESSINFO_ONLINE_EMAIL) : null;
}{code}
However, at the moment GateIn doesn't make it available in this way (file a feature request here).
Using GateIn specific API you can get it by:
{code}
PortalContainer container = PortalContainer.getInstance();
OrganizationService orgService = (OrganizationService) container.getComponentInstanceOfType(OrganizationService.class);UserHandler userHandler = orgService.getUserHandler();
User user = userHandler.findUserByName(request.getUserPrincipal().getName());
String email = user.getEmail();
{code}
Where 'request' is RenderRequest.
I didn't test this, but maybe it will work
- marko
-
2. Re: How can I retrieve the email address of a user ?
goschan Apr 2, 2010 1:06 AM (in response to mstruk)Thank you, it works
PortalContainer container = PortalContainer.getInstance(); OrganizationService orgService = (OrganizationService) container.getComponentInstanceOfType(OrganizationService.class); UserHandler userHandler = orgService.getUserHandler(); User user = null; try { user = userHandler.findUserByName(FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String email = user.getEmail();
Now I want to retrieve all the users of one group. Do youknow how can I do that?
Thank you.
-
3. Re: How can I retrieve the email address of a user ?
mstruk Apr 2, 2010 9:28 AM (in response to goschan)Take a look at UserHandler class. You have many methods there. This one looks promising:
{code}
public ListAccess<User> findUsersByGroupId(String groupId) throws Exception;
{code}
- marko
-
4. Re: How can I retrieve the email address of a user ?
joco May 19, 2010 1:15 PM (in response to goschan)Hi Benjamin!
I tried your code, but I don't know which classes or packages do I need to import. For example I've already imported org.exoplatform.services.organization.OrganizationService class, but the getComponentInstanceOfType method on container variable is not recognised by my environment (NetBeans 6.8). I also tried to look for the UserHandler class, but unfortunately I did not manage to find it.
Could you please, provide me all imports needed for your example (or the whole .java file, which you works for you)?
Thanks a lot
Jozsef
-
5. Re: How can I retrieve the email address of a user ?
trong.tran May 20, 2010 5:45 AM (in response to joco)the org.exoplatform.container.PortalContainer is located in the exo.kernel.container project.
you can look for its binaries at : http://repository.jboss.com/maven2/org/exoplatform/kernel/exo.kernel.container/
-
6. Re: How can I retrieve the email address of a user ?
joco May 21, 2010 3:51 AM (in response to trong.tran)thanks a lot