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
This commit is contained in:
parent
ec655fdf1e
commit
5853d8dfec
|
@ -4,6 +4,9 @@
|
|||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<dependent-module archiveName="landing-page-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/landing-page-library/landing-page-library">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<property name="context-root" value="landing-page-hook"/>
|
||||
<property name="java-output-path" value="/landing-page-hook/target/classes"/>
|
||||
</wb-module>
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -28,10 +28,9 @@
|
|||
</profiles>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>landing-page-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
|
|
|
@ -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<VirtualHost> 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<Group> 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<Group> getSites(final long userId) throws PortalException, SystemException {
|
||||
List<Group> sites = new ArrayList<Group>();
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue