diff --git a/.classpath b/.classpath index b710ac4..ee1b4ce 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -38,5 +38,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index c95bedc..28b72ad 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,8 +4,7 @@ - - + uses diff --git a/pom.xml b/pom.xml index d14246d..316d9b5 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user notifications war - 2.1.0-SNAPSHOT + 2.2.0-SNAPSHOT gCube Notifications Portlet @@ -74,16 +74,6 @@ social-networking-library provided - - org.gcube.portal - custom-portal-handler - provided - - - org.gcube.applicationsupportlayer - aslcore - provided - org.gcube.common.portal portal-manager @@ -96,16 +86,20 @@ org.gcube.core common-scope-maps - compile - - - org.gcube.applicationsupportlayer - accesslogger + provided org.gcube.dvos usermanagement-core + + org.slf4j + slf4j-log4j12 + + + org.slf4j + slf4j-api + com.liferay.portal portal-service diff --git a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java index 8cb8f77..12b36a8 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java @@ -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> getUserNotifications() { HashMap> toReturn = new HashMap>(); 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> getUserNotificationsByRange(int from, int quantity) { HashMap> toReturn = new HashMap>(); 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 nots = new ArrayList(); @@ -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> 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 enabledChannels) { - return store.setUserNotificationPreferences(getASLSession().getUsername(), enabledChannels); + return store.setUserNotificationPreferences(context.getCurrentUser(getThreadLocalRequest()).getUsername(), enabledChannels); } /** * diff --git a/src/main/java/org/gcube/portlets/user/notifications/server/portlet/NotificationsPortlet.java b/src/main/java/org/gcube/portlets/user/notifications/server/portlet/NotificationsPortlet.java index c48e076..fa49c12 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/server/portlet/NotificationsPortlet.java +++ b/src/main/java/org/gcube/portlets/user/notifications/server/portlet/NotificationsPortlet.java @@ -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); } diff --git a/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml b/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml index 4cd2133..0d12253 100644 --- a/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml @@ -13,7 +13,7 @@ - + diff --git a/src/test/java/org/gcube/portlets/user/notifications/test/TestForDeploy.java b/src/test/java/org/gcube/portlets/user/notifications/test/TestForDeploy.java index b0b01fb..f5917c5 100644 --- a/src/test/java/org/gcube/portlets/user/notifications/test/TestForDeploy.java +++ b/src/test/java/org/gcube/portlets/user/notifications/test/TestForDeploy.java @@ -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!"); - } }