From 5853d8dfec300ad418eb28fdeb48d18e8ff35521 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Tue, 5 Apr 2016 15:25:38 +0000 Subject: [PATCH] moved code to landing page library git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/landing-page-hook@126792 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 3 + pom.xml | 7 +- .../portal/events/LandingPageAction.java | 107 +----------------- 3 files changed, 10 insertions(+), 107 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 9349422..a0e8b37 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,6 +4,9 @@ + + uses + diff --git a/pom.xml b/pom.xml index 73c60f6..682887f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,10 +28,9 @@ - org.gcube.common.portal - portal-manager - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) - provided + org.gcube.portal + landing-page-library + [1.0.0-SNAPSHOT,) com.liferay.portal diff --git a/src/main/java/org/gcube/portal/events/LandingPageAction.java b/src/main/java/org/gcube/portal/events/LandingPageAction.java index d86fdf1..77ad78f 100644 --- a/src/main/java/org/gcube/portal/events/LandingPageAction.java +++ b/src/main/java/org/gcube/portal/events/LandingPageAction.java @@ -1,12 +1,10 @@ package org.gcube.portal.events; -import java.util.ArrayList; -import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.gcube.portal.landingpage.LandingPageManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,28 +13,13 @@ import com.liferay.portal.kernel.events.ActionException; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.struts.LastPath; -import com.liferay.portal.kernel.util.PropsKeys; -import com.liferay.portal.kernel.util.PropsUtil; -import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.WebKeys; -import com.liferay.portal.model.Group; -import com.liferay.portal.model.User; -import com.liferay.portal.model.VirtualHost; -import com.liferay.portal.service.GroupLocalServiceUtil; -import com.liferay.portal.service.LayoutSetLocalServiceUtil; -import com.liferay.portal.service.UserLocalServiceUtil; -import com.liferay.portal.service.VirtualHostLocalServiceUtil; -import com.liferay.portal.util.PortalUtil; public class LandingPageAction extends Action { private static final Logger _log = LoggerFactory.getLogger(LandingPageAction.class); - - public static final String GUEST_GROUP_FRIENDLY_URL = "/guest"; - public static final String PRIVATE_GROUP_SERVLET_MAPPING = PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING); - public static final String PORTAL_CONTEXT = PortalUtil.getPathContext(); - + @Override public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException { @@ -61,90 +44,8 @@ public class LandingPageAction extends Action { */ private String getCustomLandingPage(final HttpServletRequest request) throws PortalException, SystemException { String customLandingPagePath =""; - customLandingPagePath = getLandingPagePath(request); + customLandingPagePath = LandingPageManager.getLandingPagePath(request); _log.info("Private Site LandingPage Path = " + customLandingPagePath); return customLandingPagePath; - } - - - public static String getLandingPagePath(final HttpServletRequest request) throws PortalException, SystemException { - String sitePath = StringPool.BLANK; - - User currentUser = PortalUtil.getUser(request); - - String currentVirtualHost = request.getServerName(); - _log.debug("currentHost is " + currentVirtualHost); - Group site = null; - List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount()); - for (VirtualHost virtualHost : vHosts) { - _log.debug("Found " + virtualHost.getHostname()); - if (virtualHost.getHostname().compareTo("localhost") != 0 && - virtualHost.getLayoutSetId() != 0 && - virtualHost.getHostname().compareTo(currentVirtualHost) == 0) { - long layoutSetId = virtualHost.getLayoutSetId(); - site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup(); - _log.debug("Found match! Your site is " + site.getName()); - List userSites = getSites(currentUser.getUserId()); - boolean isRegistered = false; - for (Group group : userSites) { - if (group.getGroupId() == site.getGroupId()) { - isRegistered = true; - _log.debug("user " + currentUser.getFullName() + " is registered to " + site.getName() + ". redirecting ..."); - break; - } - } - if (! isRegistered) - _log.debug("But user " + currentUser.getFullName() + " is not registered to " + site.getName() + ". going to register ..."); - registerUserToSite(currentUser, site); - break; - } - } - if (site.getPrivateLayoutsPageCount() > 0) { - sitePath = getGroupFriendlyURL(request, site); - } else { - _log.debug(site.getName() + " site doesn't have any private page. Default landing page will be used"); - } - return sitePath; - } - /** - * this method is used to register the user to the group if does not belong to it yet - * IMPORTANT: it does not add the user to the Site's private pages if the Site Membership type is different from Private - * @param user - * @param site - * @throws SystemException - */ - private static void registerUserToSite(User user, Group site) throws SystemException { - UserLocalServiceUtil.addGroupUser(site.getGroupId(), user.getUserId()); - _log.debug("User " + user.getScreenName() +" registered to " + site.getName()); - } - - public static List getSites(final long userId) throws PortalException, SystemException { - List sites = new ArrayList(); - for (Group group : GroupLocalServiceUtil.getUserGroups(userId)) { - if (group.isRegularSite() - && !GUEST_GROUP_FRIENDLY_URL.equalsIgnoreCase(group.getFriendlyURL())) { - sites.add(group); - } - } - return sites; - } - - /** - * @param request - * @param currentGroup - * @param isPrivate - * @param isUser - * @return - * @throws PortalException - * @throws SystemException - */ - public static String getGroupFriendlyURL(final HttpServletRequest request, final Group currentGroup) throws PortalException, SystemException { - String friendlyURL = PRIVATE_GROUP_SERVLET_MAPPING; - StringBundler sb = new StringBundler(); - sb.append(PORTAL_CONTEXT); - sb.append(friendlyURL); - sb.append(currentGroup.getFriendlyURL()); - return sb.toString(); - } - + } } \ No newline at end of file