Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Extending UserProfile object
Bowker
Has anyone successfully extended the UserProfile object for storing profile data and if so how?
We need to add a few fields and don't see an obvious way to extend and use the new fields.
Find more posts tagged with
Comments
PaulW
Did you ever get an answer on this Dan?
Bowker
Yes - I ended up in a private conversation with someone (who unless they want to disclose will remain anonymous) and they posted this:
(Let me first say that I have passed this specific task off to another developer, so I don't believe we've implemented it yet.)
***************** From an anonymous source *****************
Ok now that it is clear what you are trying to do, here is what you will need (ignore the guides as I mentioned earlier they are out-of-date in some areas):
Note: I am using Java class names that makes sense to explain the concept, feel free to rename them as you see fit.
It is also ASSUMED that all of these custom user profile attributes are residing in some DB or LDAP outside of standard OOTB LiveSite User Profile DB. Typically, most enterprise-class implementations will NOT use LS OOTB UserProfile Database as most clients will have their own LDAP or CRM databases that house everything that they need. So let me know if this is not the case for your requirement.
1.) Under LiveSite Toolkit (LSTK) - livesite_customer_src directory - Create a custom Java class (i.e. CustomUserProfile.java) that extends OOTB com.interwoven.livesite.p13n.model.UserProfile. In this class, all you need is getters/setters for each one of your custom user profile attributes.
- Example:
[PHP]public String getTypeOfInvestor(){ return this.typeOfInvestor;}
public void setTypeOfInvestor(String typeOfInvestor){this.typeOfInvestor = typeOfInvestor;}
[/PHP]
2.) Under LSTK, create a custom Java class (i.e. CustomUserProfileFactory) that extends OOTB com.interwoven.livesite.spring.p13n.impl.SpringUse rProfileFactory. IN this class you need a few things:
- create a constructor that simply calls the super class' constructor (i.e super())
- create a getUserProfileClass() method that returns super class' class (i.e. super.getUserProfileClass())
- create an init() method - again simply call super class' init method.
- create a getInstance(HttpServletRequest request) method. In this method, get the userProfile instance from super class (i.e. super.getInstance(request)) and cast it to CustomUserProfile. Next set the "default" values of all of your custom user profile parameters on this instance. (i.e. userProfile.setTypeOfInvestor("some-default-value") )
3.) Now that we have our CustomUserProfile, CustomUserProfileFactory classes ready, you'll have to make "register" these with LiveSite and make it aware of these custom classes. Standard spring bean configuration in "customer-resource-config.xml" file.
4.) Under LSTK, create a Login Controller class (i.e. LoginController). Please keep in mind that you could use the OOTB Login class and extend/modify it to meet your needs. In any case, in this class, whenever the "login" event happens, you'll validate the user's credentials and then set ALL user profile attributes including any custom attributes (i.e. typeOfInvestor). Example (this is psuedo code only):
[PHP]
public ForwardAction login(RequestContext context){
ForwardAction fAction = someLoginMethodThatValidatesUserORLoginFromOOTBCla ss(context);
CustomUserProfile customUserProfile = getUserProfile(context); /***** This should return the CustomUserProfile object as we configured that in previous step. In case it doesn't, you'll just have to cast it. This is one thing that I don't recall and I don't have a TS instance up right now to validate it. */
String typeOfInvestor = someCustomMethodToRetrieveTypeOfInvestorFromSomeBa ckendDatabaseORWhereeverItMayBe(context);
customUserProfile.setTypeOfInvestor(typeOfInvestor );
}
[/PHP]
***** At this point, you are all set from Java code and runtime perspective. So you'll do your standard build.bat/.sh.
5.) Now you'll have to configure the TS UI so that when your content contributors create targeting rules they can leverage these custom attributes. For example, your content contributors may want to create a rule like this: if visitor's "type of investor" is "personal" then show them context/DCR X else show them content/DCR Y. Process of extending (customizing) the targeting UI is called Verbalization. If you have access to SitePub Dev Guide (specifically TeamSite SitePublisher 7.2 Developer Guide Revision 1), chapter 11 talks about this process in-depth along with some examples. I'll say read that chapter and look at some of the OOTB verbalization files and you'll get a good idea how to do this. If you run into any issues send me a note with specific questions.
Under step 4 and around line 3 where it retrieves the userProfile, I mis-typed that line. Here is what it should look like:
[PHP]
CustomUserProfile userProfile = (CustomUserProfile)context.getSession().getUserPro file();
[/PHP]
PaulW
Thanks for taking the time to write the response. Ill post back with the results of what I discover.
PaulW
worked like a charm. thanks dan. Only additional detail ill add for other people is the specific details of wiring up the beans.
[html]
parent="p13n.DefaultUserProfile"
class="com.customer.p13n.model.CustomUserProfile"/>
parent="p13n.UserProfileFactory"
class="com.customer.p13n.model.CustomUserProfileFactory">
[/html]
PaulW
one other thing - I had to explicitly set CustomUserProfile to prototype. It does NOT inherit this form parent bean. it defaults to being a singleton.
chnkumar
Hi,
When a user registers, new fields values will be inserted into DB? I don't see any hibernate column mapping here.
Please advise.
Thanks
Narayan