|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|