diff --git a/META-INF/KeySpace Structure.xlsx b/META-INF/KeySpace Structure.xlsx index 649ddf1..d3405b9 100644 Binary files a/META-INF/KeySpace Structure.xlsx and b/META-INF/KeySpace Structure.xlsx differ diff --git a/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java b/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java index 31d1654..4cdbf48 100644 --- a/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java +++ b/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java @@ -240,8 +240,6 @@ public class CassandraClusterConnection { ColumnFamilyDefinition cfDefUserLikedFeeds = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_LIKED_FEEDS); ColumnFamilyDefinition cfDefUserNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS); ColumnFamilyDefinition cfDefUserNotificationsUnread = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS_UNREAD); - ColumnFamilyDefinition cfDefUserMessagesNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_MESSAGES_NOTIFICATIONS); - ColumnFamilyDefinition cfDefUserMessagesNotificationsUnread = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_MESSAGES_NOTIFICATIONS_UNREAD); ColumnFamilyDefinition cfDefUserNotificationsPreferences = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS_PREFERENCES); ColumnFamilyDefinition cfDefHashtagsCounter = getDynamicCFDef(DBCassandraAstyanaxImpl.HASHTAGS_COUNTER); ColumnFamilyDefinition cfDefHashtagTimeline = getDynamicCFDef(DBCassandraAstyanaxImpl.HASHTAGGED_FEEDS); @@ -263,8 +261,6 @@ public class CassandraClusterConnection { .addColumnFamily(cfDefUserTimeline) .addColumnFamily(cfDefUserNotifications) .addColumnFamily(cfDefUserNotificationsUnread) - .addColumnFamily(cfDefUserMessagesNotifications) - .addColumnFamily(cfDefUserMessagesNotificationsUnread) .addColumnFamily(cfDefUserNotificationsPreferences) .addColumnFamily(cfDefUserLikedFeeds) .addColumnFamily(cfDefHashtagsCounter) diff --git a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java index c78d451..a8cbb16 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -78,10 +78,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public static final String USER_TIMELINE_FEEDS = "USERTimeline"; public static final String APP_TIMELINE_FEEDS = "AppTimeline"; public static final String USER_LIKED_FEEDS = "USERLikes"; - public static final String USER_NOTIFICATIONS = "USERNotifications"; // regular user notifications timeline (both read and unread) - public static final String USER_NOTIFICATIONS_UNREAD = "USERNotificationsUnread"; // only unread user notifications - public static final String USER_MESSAGES_NOTIFICATIONS = "USERMessagesNotifications"; // user messages notifications timeline - public static final String USER_MESSAGES_NOTIFICATIONS_UNREAD = "USERMessagesNotificationsUnread"; // only unread user notification messages + public static final String USER_NOTIFICATIONS = "USERNotifications"; // regular user notifications timeline (both read and unread, messages are included) + public static final String USER_NOTIFICATIONS_UNREAD = "USERNotificationsUnread"; // only unread user notifications/ notifications messages public static final String USER_NOTIFICATIONS_PREFERENCES = "USERNotificationsPreferences"; // preferences for notifications public static final String HASHTAGS_COUNTER = "HashtagsCounter"; // count the hashtags per group and type public static final String HASHTAGGED_FEEDS = "HashtaggedFeeds"; // contains hashtags per type associated with vre and feed @@ -146,14 +144,6 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { USER_NOTIFICATIONS_UNREAD, // Column Family Name StringSerializer.get(), // Key Serializer StringSerializer.get()); // Column Serializer - private static ColumnFamily cf_UserMessageNotifications = new ColumnFamily( - USER_MESSAGES_NOTIFICATIONS, // Column Family Name - StringSerializer.get(), // Key Serializer - StringSerializer.get()); // Column Serializer - private static ColumnFamily cf_UserMessageNotificationsUnread = new ColumnFamily( - USER_MESSAGES_NOTIFICATIONS_UNREAD, // Column Family Name - StringSerializer.get(), // Key Serializer - StringSerializer.get()); // Column Serializer protected static ColumnFamily cf_UserNotificationsPreferences = new ColumnFamily( USER_NOTIFICATIONS_PREFERENCES, // Column Family Name StringSerializer.get(), // Key Serializer @@ -901,20 +891,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { .putColumn("SenderFullName", n.getSenderFullName(), null) .putColumn("SenderThumbnail", n.getSenderThumbnail(), null); - if (n.getType() != NotificationType.MESSAGE){ - //an entry in the user Notifications Timeline - m.withRow(cf_UserNotifications, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); + //an entry in the user Notifications Timeline + m.withRow(cf_UserNotifications, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); - // another entry in the Unread Notifications Timeline - m.withRow(cf_UserNotificationsUnread, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); - } - else{ - //an entry in the user Messages Notifications Timeline - m.withRow(cf_UserMessageNotifications, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); - - //an entry in the user Unread Messages Notifications Timeline - m.withRow(cf_UserMessageNotificationsUnread, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); - } + // save key in the unread notifications column family too + m.withRow(cf_UserNotificationsUnread, n.getUserid()).putColumn(n.getTime().getTime()+"", n.getKey().toString(), null); return execute(m); } @@ -965,16 +946,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { throw new NotificationIDNotFoundException("The specified notification to set Read with id: " + notificationidToSet + " does not exist"); MutationBatch m = conn.getKeyspace().prepareMutationBatch(); - //an entry in the feed CF + + //set as read m.withRow(cf_Notifications, notificationidToSet).putColumn("Read", true, null); - // delete the notification's key from the unread notifications or unread notification messages column family, according to the type - if(toSet.getType().equals(NotificationType.MESSAGE)){ - m.withRow(cf_UserMessageNotificationsUnread, toSet.getUserid()).deleteColumn(toSet.getTime().getTime()+""); - } - else{ - m.withRow(cf_UserNotificationsUnread, toSet.getUserid()).deleteColumn(toSet.getTime().getTime()+""); - } + // delete the notification's key from the unread notifications column family + m.withRow(cf_UserNotificationsUnread, toSet.getUserid()).deleteColumn(toSet.getTime().getTime()+""); // execute the operations try { @@ -1012,7 +989,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { return toReturn; } /** - * Return a list of not read notifications by user userid + * Return a list of not read notifications by user userid (messages as well as other notifications) * @param userid user identifier * @return simply return a list of not read user notifications UUID in chronological order from the oldest to the more recent */ @@ -1036,31 +1013,6 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } return toReturn; } - /** - * Returns UUIDS of not read user notification messages - * @param userid user identifier - * @return simply return a list of yet to read user messages notifications UUID in chronological order from the oldest to the more recent - */ - private ArrayList getUserMessagesUnreadNotificationsIds(String userid) { - OperationResult> result = null; - try { - result = conn.getKeyspace().prepareQuery(cf_UserMessageNotificationsUnread) - .getKeySlice(userid) - .execute(); - } catch (ConnectionException e) { - e.printStackTrace(); - } - - ArrayList toReturn = new ArrayList(); - - // Iterate rows and their columns - for (Row row : result.getResult()) { - for (Column column : row.getColumns()) { - toReturn.add(column.getStringValue()); - } - } - return toReturn; - } /** * {@inheritDoc} */ @@ -1145,10 +1097,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { for (int i = notificationsIDs.size()-1; i >= 0; i--) { try{ - + // set to read (and automatically remove from the unread column family) setNotificationRead(notificationsIDs.get(i)); - + } catch (NotificationIDNotFoundException e) { _log.error("Could not set read notification with id =" + notificationsIDs.get(i)); } @@ -1161,12 +1113,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getUnreadNotificationMessagesByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException { ArrayList toReturn = new ArrayList(); - ArrayList notificationsIDs = getUserMessagesUnreadNotificationsIds(userid); + ArrayList notificationsIDs = getUnreadUserNotificationsIds(userid); //need them in reverse order for (int i = notificationsIDs.size()-1; i >= 0; i--) { try{ - toReturn.add(readNotification(notificationsIDs.get(i))); + Notification not = readNotification(notificationsIDs.get(i)); + if(not.getType().equals(NotificationType.MESSAGE)) + toReturn.add(not); }catch(Exception e){ _log.error("Unable to read notification message with key " + notificationsIDs.get(i)); } @@ -1180,8 +1134,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public boolean checkUnreadNotifications(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException { - // are there notifications to read? - return getUnreadUserNotificationsIds(userid).size() > 0; + ArrayList unreadNotifications = getUnreadUserNotificationsIds(userid); + + for (int i = unreadNotifications.size() - 1; i >= 0; i--) { + Notification toAdd; + try { + toAdd = readNotification(unreadNotifications.get(i)); + if (toAdd.getType() != NotificationType.MESSAGE) + return true; + } catch (NotificationIDNotFoundException e) { + _log.error("Notification not found with id = " + unreadNotifications.get(i)); + } + } + + return false; } /** * {@inheritDoc} @@ -1189,8 +1155,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException { - // are there messages to read? - return getUserMessagesUnreadNotificationsIds(userid).size() > 0; + ArrayList unreadNotifications = getUnreadUserNotificationsIds(userid); + + for (int i = unreadNotifications.size() - 1; i >= 0; i--) { + Notification toAdd; + try { + toAdd = readNotification(unreadNotifications.get(i)); + if (toAdd.getType() == NotificationType.MESSAGE) + return true; + } catch (NotificationIDNotFoundException e) { + _log.error("Notification not found with id = " + unreadNotifications.get(i)); + } + } + + return false; } /* *