-
1. Re: Filling UserProfile data initially?
michaelschuetz Dec 6, 2010 9:08 AM (in response to michaelschuetz)Hi my current status:
userProfile-configuration.xml:
###
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
<component>
<key>my.services.UserProfileService</key>
<type>my.services.UserProfileService</type>
<init-params>
<object-param>
<name>userprofiles</name>
<description>description</description>
<object type="my.services.UserProfileConfig"><field name="userProfile">
<collection type="java.util.ArrayList">
<value>
<object type="my.services.UserProfileConfig$UserProfile">
<field name="userName">
<string>refUser</string>
</field>
<field name="newProperty1">
<string>9999</string>
</field>
<field name="newProperty2">
<string>1081</string>
</field>
</object>
</value>
</collection>
</field>
</object>
</object-param>
</init-params>
</component>
</configuration>###
With this, I got ClassNotFoundException for my.services.UserProfileConfig. So added appropriate Jar to gatein.ear/lib.
Now, class will be found and Constructor is called once.
But neiter Setter of UserProfileConfig nor UserProfileService itself will be called?
My Service class:
###
public class UserProfileService {
public UserProfileService(InitParams params) {
System.out.println("############## UserProfileService");ObjectParameter parameter = params.getObjectParam("userprofiles");
System.out.println("######### " + parameter.getObject().getClass());
}}
###
What do I need to do to get UserProfileService being called? Is there something like "OnStartup" configuration?
Really need help on this. Thanks a lot.
regards
Michael
-
2. Re: Filling UserProfile data initially?
michaelschuetz Dec 6, 2010 2:02 PM (in response to michaelschuetz)What do I need to do to get UserProfileService being called? Is there something like "OnStartup" configuration?
OK, I found the solution: Service just needs to implement org.picocontainer.Startable. For further information: http://wiki.exoplatform.org/xwiki/bin/view/Kernel/Service%20Configuration%20for%20Beginners#HStartableinterface
-
3. Re: Filling UserProfile data initially?
ndkhoiits Dec 7, 2010 8:54 PM (in response to michaelschuetz)As i know, GateIn hasn't supported this feature yet in this version
-
4. Re: Filling UserProfile data initially?
michaelschuetz Dec 8, 2010 2:34 PM (in response to ndkhoiits)As i know, GateIn hasn't supported this feature yet in this version
You mean filling UserProfileData initially? Yes, exactly - that's why I did this for my own.
It's pretty straightforward. The important thing to know was having to implement Startable interface.
I perform my stuff in start method, hook into Organization-Service etc.
Here is the important part:
###
final UserProfileHandler userProfileHandler = organizationService.getUserProfileHandler();
final UserHandler userHandler = organizationService.getUserHandler();
for (UserProfileConfig.UserProfile userProfile : userProfiles) {
final String userName = userProfile.getUserName();
final String newProperty1 = userProfile.getNewProperty1();
final String newProperty2 = userProfile.getNewProperty2();
logDebug("Add user profile data: %s, %s, %s", userName, newProperty1, newProperty2);
UserProfile profile = userProfileHandler.findUserProfileByName(userProfile.getUserName());
if (profile == null) {
profile = userProfileHandler.createUserProfileInstance(userProfile.getUserName());
}
// To be sure the internal attributes map is set, we have to use profile.getUserInfoMap()
final Map<String, String> attributes = profile.getUserInfoMap();
attributes.put(NEW_PROPERTY_1_KEY, newProperty1);
attributes.put(NEW_PROPERTY_2_KEY, newProperty2);
final User user = userHandler.findUserByName(userName);
// set UserProfile's first and lastname
if (user != null) {
logDebug("User found: %s, adding first and last name to user profile", user.getFullName());
attributes.put(PortletRequest.P3PUserInfos.USER_NAME_GIVEN.toString(), user.getFirstName());
attributes.put(PortletRequest.P3PUserInfos.USER_NAME_FAMILY.toString(), user.getLastName());
}
userProfileHandler.saveUserProfile(profile, true);}
###
BTW, having handle of userProfileHandler, I do fix some not so nice part: UserProfile's first and last name (see comment "set UserProfile's first and lastname") does not match to Users first and last name. AFAIK, it does not maky any sense having different first or last names for User and UserProfile. Code above fixes this.
Cheers
Michael