removed ASL Session

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@134940 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/23194
Massimiliano Assante 8 years ago
parent 199a691e14
commit b83e890141

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/notifications-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/notifications-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/notifications-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/notifications-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/notifications-2.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/notifications-2.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -4,8 +4,7 @@
<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"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/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"/>

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>notifications</artifactId>
<packaging>war</packaging>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<name>gCube Notifications Portlet</name>
<properties>
@ -74,16 +74,6 @@
<artifactId>social-networking-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
@ -96,16 +86,20 @@
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>

@ -15,9 +15,7 @@ import java.util.TreeMap;
import javax.servlet.ServletContext;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Notification;
@ -27,7 +25,6 @@ import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.notifications.client.NotificationsService;
import org.gcube.portlets.user.notifications.shared.NotificationConstants;
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,6 +42,8 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
private final static String TYPE_CATEGORIES_FILENAME = "categorybytype.properties";
private final static String TYPE_LABELS_FILENAME = "labelbytype.properties";
private final static String TYPE_DESCRIPTIONS_FILENAME = "descbytype.properties";
private PortalContext context = PortalContext.getConfiguration();
/**
* The store interface
*/
@ -59,63 +58,16 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
public void destroy() {
store.closeConnection();
}
/**
* the current ASLSession
* @return the session
*/
private ASLSession getASLSession() {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
user = getDevelopmentUser();
_log.warn("USER IS NULL setting "+user+" and Running OUTSIDE PORTAL");
}
_log.debug("SessionID = " + sessionID);
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
*
* @return true if you're running into the portal, false if in development
*/
private boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
} catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
_log.trace("Development Mode ON");
return false;
}
}
/**
* set the user in development mode
* @return
*/
public String getDevelopmentUser() {
String user = "test.user";
// user = "andrea.rossi";
return user;
}
public UserInfo getUserInfo() {
try {
String username = getASLSession().getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png";
if (isWithinPortal()) {
GCubeUser user = new LiferayUserManager().getUserByUsername(username);
thumbnailURL = user.getUserAvatarURL();
fullName = user.getFullname();
email = user.getEmail();
UserInfo toReturn = new UserInfo(username, fullName, thumbnailURL, email, null, true, false, null);
return toReturn;
}
else {
_log.info("Returning test USER");
return new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
}
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
String username = currUser.getUsername();
String email = currUser.getEmail();
String fullName = currUser.getFullname();
String thumbnailURL = currUser.getUserAvatarURL();
UserInfo toReturn = new UserInfo(username, fullName, thumbnailURL, email, null, true, false, null);
return toReturn;
} catch (Exception e) {
e.printStackTrace();
@ -129,7 +81,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
public HashMap<Date, ArrayList<Notification>> getUserNotifications() {
HashMap<Date, ArrayList<Notification>> toReturn = new HashMap<Date, ArrayList<Notification>>();
try {
for (Notification notification : store.getAllNotificationByUser(getASLSession().getUsername(), NotificationConstants.NOTIFICATION_NUMBER_PRE)) {
for (Notification notification : store.getAllNotificationByUser(context.getCurrentUser(getThreadLocalRequest()).getUsername(), NotificationConstants.NOTIFICATION_NUMBER_PRE)) {
Date dateWithoutTime = removeTimePart(notification.getTime());
notification.setDescription(replaceAmpersand(notification.getDescription()));
if (! toReturn.containsKey(dateWithoutTime)) {
@ -154,7 +106,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
public HashMap<Date, ArrayList<Notification>> getUserNotificationsByRange(int from, int quantity) {
HashMap<Date, ArrayList<Notification>> toReturn = new HashMap<Date, ArrayList<Notification>>();
try {
for (Notification notification : store.getRangeNotificationsByUser(getASLSession().getUsername(), from, quantity)) {
for (Notification notification : store.getRangeNotificationsByUser(context.getCurrentUser(getThreadLocalRequest()).getUsername(), from, quantity)) {
Date dateWithoutTime = removeTimePart(notification.getTime());
if (! toReturn.containsKey(dateWithoutTime)) {
ArrayList<Notification> nots = new ArrayList<Notification>();
@ -194,7 +146,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
*/
public boolean setAllUserNotificationsRead() {
try {
store.setAllNotificationReadByUser(getASLSession().getUsername());
store.setAllNotificationReadByUser(context.getCurrentUser(getThreadLocalRequest()).getUsername());
} catch (Exception e) {
_log.error("While trying to set User notifications Read");
e.printStackTrace();
@ -204,7 +156,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
@Override
public LinkedHashMap<String, ArrayList<NotificationPreference>> getUserNotificationPreferences() {
String userid = getASLSession().getUsername();
String userid = context.getCurrentUser(getThreadLocalRequest()).getUsername();
//load the 3 prop files
Properties categories = getCategoriesByType();
Properties labels = getLabelsByType();
@ -253,7 +205,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
@Override
public boolean setUserNotificationPreferences(Map<NotificationType, NotificationChannelType[]> enabledChannels) {
return store.setUserNotificationPreferences(getASLSession().getUsername(), enabledChannels);
return store.setUserNotificationPreferences(context.getCurrentUser(getThreadLocalRequest()).getUsername(), enabledChannels);
}
/**
*

@ -13,8 +13,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
/**
* NotificationsPortlet Portlet Class
* @author Massimiliano Assante - ISTI CNR
@ -27,8 +25,7 @@ public class NotificationsPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Notifications_view.jsp");
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Notifications_view.jsp");
dispatcher.include(request, response);
}

@ -13,7 +13,7 @@
<inherits name='org.gcube.portlets.widgets.switchbutton.SwitchButton' />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- Specify the app entry point class. -->
<set-property name="bootstrap.responsiveDesign" value="true"/>
<set-property name="bootstrap.responsiveDesign" value="true" />
<entry-point
class='org.gcube.portlets.user.notifications.client.Notifications' />

@ -1,19 +1,6 @@
package org.gcube.portlets.user.notifications.test;
import static org.junit.Assert.assertTrue;
import org.gcube.portlets.user.notifications.server.NotificationsServiceImpl;
import org.junit.Test;
public class TestForDeploy {
@Test
public void testUserIsTestUser() {
NotificationsServiceImpl serviceImpl = new NotificationsServiceImpl();
String username = serviceImpl.getDevelopmentUser();
System.out.println("username for deploy is: " + username);
assertTrue(username.compareTo("test.user") == 0);
System.out.println("Test OK!");
}
}

Loading…
Cancel
Save