Forum and FAQ applications are to show some information about posters. The way to retrieve that information is pluggable through the ContactProvider component.
For public internet websites, users can provide personal information, such as personal email address and location. To enable, simply override the ContactProvider component in your configuration.
Configure the profile-configuration.xml
file as shown below:
<component>
<key>org.exoplatform.forum.common.user.ContactProvider</key>
<!-- <type>org.exoplatform.forum.common.user.DefaultContactProvider</type> -->
<type>org.exoplatform.forum.ext.common.SocialContactProvider</type>
</component>
You can get the ContactProvider as follows:
public static CommonContact getPersonalContact(String userId) {
try {
if(userId.indexOf(Utils.DELETED) > 0) return new CommonContact();
ContactProvider provider = (ContactProvider) PortalContainer.getComponent(ContactProvider.class) ;
return provider.getCommonContact(userId);
} catch (Exception e) {
return new CommonContact();
}
}
In eXo Platform, when using ContactProvider
, you can use the
SocialContactProvider
classes
which gets users' profiles by userId via the
IdentityManager
class.
public CommonContact getCommonContact(String userId) {
CommonContact contact = new CommonContact();
try {
IdentityManager identityM = (IdentityManager) PortalContainer.getInstance().getComponentInstanceOfType(IdentityManager.class);
Identity userIdentity = identityM.getIdentity(OrganizationIdentityProvider.NAME, userId, true);
Profile profile = userIdentity.getProfile();
if (profile.contains(Profile.EMAIL)) {
contact.setEmailAddress(profile.getProperty(Profile.EMAIL).toString());
}
if (profile.contains(Profile.FIRST_NAME)) {
contact.setFirstName(profile.getProperty(Profile.FIRST_NAME).toString());
}
if (profile.contains(Profile.LAST_NAME)) {
contact.setLastName(profile.getProperty(Profile.LAST_NAME).toString());
}
contact.setAvatarUrl(profile.getAvatarImageSource());
if (profile.contains(Profile.GENDER)) {
contact.setGender(profile.getProperty(Profile.GENDER).toString());
}
if (profile.contains(Profile.CONTACT_PHONES)) {
contact.setPhone(profile.getProperty(Profile.CONTACT_PHONES).toString());
}
if (profile.contains(Profile.URL)) {
contact.setWebSite(profile.getProperty(Profile.URL).toString());
}
} catch (Exception e) {
if (LOG.isErrorEnabled()) LOG.error(String.format("can not load contact from eXo Social Profile with user [%s]", userId), e);
}
return contact;
}
The information which is get by the user includes:
Name | Type | Description |
---|---|---|
String
|
Email of user. | |
firstName |
String
|
First name of user. |
lastName |
String
|
Last name of user. |
The information which is get via UserProfile includes:
Attribute | Type | Description |
---|---|---|
user.other-info.avatar.url |
String
|
The path containing the user's avatar. |
user.bdate |
String
|
The user's birthday. |
user.home-info.postal.city |
String
|
The home city of user. |
user.home-info.postal.country |
String
|
The home country of user. |
user.gender |
String
|
The user's gender. |
user.jobtitle |
String
|
The user's job. |
user.home-info.telecom.telephone.number |
String
|
The home phone number of user. |
user.business-info.telecom. telephone.number |
String
|
The mobile number of user. |
user.home-info.online.uri |
String
|
The individual websites of user. |