[gatein-commits] gatein SVN: r485 - in portal/trunk: web/portal/src/main/webapp/WEB-INF and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Nov 3 18:55:04 EST 2009
Author: mwringe
Date: 2009-11-03 18:55:04 -0500 (Tue, 03 Nov 2009)
New Revision: 485
Added:
portal/trunk/.settings/
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
Log:
Limit userprofile lookup to once per request (GTNPORTAL-60)
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2009-11-03 23:12:36 UTC (rev 484)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2009-11-03 23:55:04 UTC (rev 485)
@@ -36,6 +36,7 @@
<listener>org.exoplatform.portal.application.PortalStatisticLifecycle</listener>
<listener>org.exoplatform.portal.application.PortalApplicationLifecycle</listener>
<listener>org.exoplatform.webui.application.MonitorApplicationLifecycle</listener>
+ <listener>org.exoplatform.portal.application.UserProfileLifecycle</listener>
</application-lifecycle-listeners>
<events>
Added: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java 2009-11-03 23:55:04 UTC (rev 485)
@@ -0,0 +1,74 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.web.application.Application;
+import org.exoplatform.web.application.ApplicationLifecycle;
+import org.exoplatform.webui.application.WebuiRequestContext;
+
+public class UserProfileLifecycle implements ApplicationLifecycle<WebuiRequestContext>
+{
+ public static final String USER_PROFILE_ATTRIBUTE_NAME = "PortalUserProfile";
+
+ private final ThreadLocal<UserProfile> currentUserProfile = new ThreadLocal<UserProfile>();
+
+ @SuppressWarnings("unused")
+ public void onInit(Application app)
+ {
+ //do nothing for now
+ }
+
+ @SuppressWarnings("unused")
+ public void onStartRequest(final Application app, final WebuiRequestContext context) throws Exception
+ {
+ String user = context.getRemoteUser();
+ UserProfile userProfile = null;
+ if (user != null)
+ {
+ ExoContainer exoContainer = app.getApplicationServiceContainer();
+ if (exoContainer != null)
+ {
+ OrganizationService organizationService = (OrganizationService) exoContainer
+ .getComponentInstanceOfType(OrganizationService.class);
+ userProfile = organizationService.getUserProfileHandler().findUserProfileByName(user);
+ }
+
+ }
+
+ currentUserProfile.set(userProfile);
+ context.setAttribute(this.USER_PROFILE_ATTRIBUTE_NAME, userProfile);
+ }
+
+ @SuppressWarnings("unused")
+ public void onEndRequest(Application app, WebuiRequestContext context) throws Exception
+ {
+ currentUserProfile.remove();
+ }
+
+ @SuppressWarnings("unused")
+ public void onDestroy(Application app)
+ {
+ // do nothing for now
+ }
+
+}
\ No newline at end of file
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2009-11-03 23:12:36 UTC (rev 484)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2009-11-03 23:55:04 UTC (rev 485)
@@ -22,6 +22,7 @@
import org.exoplatform.Constants;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.application.UserProfileLifecycle;
import org.exoplatform.portal.config.model.ApplicationType;
import org.exoplatform.portal.config.model.portlet.PortletId;
import org.exoplatform.portal.pom.spi.portlet.Preferences;
@@ -672,15 +673,9 @@
//
StatefulPortletContext<C> preferencesPortletContext = getPortletContext();
- //
- OrganizationService service = getApplicationComponent(OrganizationService.class);
- String user = prc.getRemoteUser();
- UserProfile userProfile = null;
- if (user != null)
- {
- userProfile = service.getUserProfileHandler().findUserProfileByName(user);
- }
-
+ // get the user profile cached in the prc during the start of the request
+ UserProfile userProfile = (UserProfile) prc.getAttribute(UserProfileLifecycle.USER_PROFILE_ATTRIBUTE_NAME);
+
// client context
AbstractClientContext clientContext;
Cookie[] cookies = servletRequest.getCookies();
More information about the gatein-commits
mailing list