git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/landing-page-library@126791 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
df7a156d6d
commit
71381d47c6
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>landing-page-library</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,4 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="landing-page-library">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
</faceted-project>
|
|
@ -0,0 +1,64 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>landing-page-library</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>landing-page-library</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<liferay.version>6.2.5</liferay.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-java</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,125 @@
|
|||
package org.gcube.portal.landingpage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante, CNR-ISTI
|
||||
*
|
||||
*/
|
||||
public class LandingPageManager {
|
||||
private static final Logger _log = LoggerFactory.getLogger(LandingPageManager.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();
|
||||
|
||||
public static String getLandingPagePath(final HttpServletRequest request) throws PortalException, SystemException {
|
||||
User currentUser = PortalUtil.getUser(request);
|
||||
return getLandingPagePath(request, currentUser);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @param currentUser
|
||||
* @return
|
||||
* @throws PortalException
|
||||
* @throws SystemException
|
||||
*/
|
||||
public static String getLandingPagePath(final HttpServletRequest request, User currentUser) throws PortalException, SystemException {
|
||||
String sitePath = StringPool.BLANK;
|
||||
|
||||
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