removed ASL Session, ported to gCube Client Context

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/my-vres@134136 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-14 17:01:53 +00:00
parent 6a1fe04ec7
commit 660ddada36
5 changed files with 16 additions and 66 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/my-vres-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/my-vres-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/my-vres-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/my-vres-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -38,5 +38,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/my-vres-2.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/my-vres-2.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -5,7 +5,7 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependent-module archiveName="gcube-widgets-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

18
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>my-vres</artifactId>
<packaging>war</packaging>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<name>My VREs Portlet</name>
<description>
gCube My VREs Portlet shows only the VO and VREs a user is member of, divided by category.
@ -57,18 +57,10 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
@ -78,6 +70,14 @@
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>

View File

@ -6,13 +6,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlet.user.my_vres.client.MyVREsService;
import org.gcube.portlet.user.my_vres.shared.UserBelonging;
import org.gcube.portlet.user.my_vres.shared.VRE;
@ -44,24 +40,10 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
public static final String ADD_MORE_CATEGORY = "Add More";
public static final String ADD_MORE_IMAGE_PATH= "images/More.png";
private ASLSession getASLSession() {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("USER IS NULL setting test.user");
user = "test.user";
}
else {
_log.info("LIFERAY PORTAL DETECTED user=" + user);
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
@Override
public String getSiteLandingPagePath() {
String user = getASLSession().getUsername();
_log.debug("user=" + user + " has no VREs");
String toReturn = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+GCubePortalConstants.VRES_EXPLORE_FRIENDLY_URL;
return toReturn;
}
@ -83,14 +65,14 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
* first method called by the UI
*/
public LinkedHashMap<String, ArrayList<VRE>> getUserVREs() {
getASLSession();
//_log.trace("getInfrastructureVOs method called");
if (!isWithinPortal())
return getFakeVREs();
//return new ArrayList<VO>();
else
try {
String username = getASLSession().getUsername();
PortalContext context = PortalContext.getConfiguration();
String username = context.getCurrentUser(getThreadLocalRequest()).getUsername();
GroupManager gm = new LiferayGroupManager();
LinkedHashMap<String, ArrayList<VRE>> toReturn = new LinkedHashMap<String, ArrayList<VRE>>();
@ -147,7 +129,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
Collections.sort(toSort);
}
HttpServletRequest request = getThreadLocalRequest();
PortalContext context = PortalContext.getConfiguration();
String gatewayURL = context.getGatewayURL(request);
String exploreURL = gatewayURL+context.getSiteLandingPagePath(request)+GCubePortalConstants.VRES_EXPLORE_FRIENDLY_URL;
VRE addMore = new VRE("", "", "", "", exploreURL, UserBelonging.BELONGING);

View File

@ -10,18 +10,11 @@ import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
/**
* MyVREsPortlet Portlet Class
@ -38,30 +31,6 @@ public class MyVREsPortlet extends GenericPortlet {
}
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
long userid = Long.parseLong(renderRequest.getRemoteUser());
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
renderRequest.getPortletSession().setAttribute(WebKeys.THEME_DISPLAY, themeDisplay, PortletSession.APPLICATION_SCOPE);
User user = null;
try {
user = UserLocalServiceUtil.getUser(userid);
} catch (SystemException e) {
e.printStackTrace();
} catch (PortalException e) {
e.printStackTrace();
}
//get the username
String username = user.getScreenName();
//Set the username to the portlet session, so that it can be accessed through the servlet
renderRequest.getPortletSession().setAttribute("username", username, PortletSession.APPLICATION_SCOPE);
renderRequest.getPortletSession().setAttribute("user", username, PortletSession.APPLICATION_SCOPE);
include(viewJSP, renderRequest, renderResponse);
}