The Messages column family has been merged with the UserNotifications one. The unreadNotifications cf now contains every kind of unread notification (i.e., also messages notifications)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@126751 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-04-04 16:02:46 +00:00
parent e8b9c9ae5c
commit fdda510279
3 changed files with 45 additions and 71 deletions

Binary file not shown.

View File

@ -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)

View File

@ -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<String, String> cf_UserMessageNotifications = new ColumnFamily<String, String>(
USER_MESSAGES_NOTIFICATIONS, // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer
private static ColumnFamily<String, String> cf_UserMessageNotificationsUnread = new ColumnFamily<String, String>(
USER_MESSAGES_NOTIFICATIONS_UNREAD, // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer
protected static ColumnFamily<String, String> cf_UserNotificationsPreferences = new ColumnFamily<String, String>(
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<String> getUserMessagesUnreadNotificationsIds(String userid) {
OperationResult<Rows<String, String>> result = null;
try {
result = conn.getKeyspace().prepareQuery(cf_UserMessageNotificationsUnread)
.getKeySlice(userid)
.execute();
} catch (ConnectionException e) {
e.printStackTrace();
}
ArrayList<String> toReturn = new ArrayList<String>();
// Iterate rows and their columns
for (Row<String, String> row : result.getResult()) {
for (Column<String> 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<Notification> getUnreadNotificationMessagesByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException {
ArrayList<Notification> toReturn = new ArrayList<Notification>();
ArrayList<String> notificationsIDs = getUserMessagesUnreadNotificationsIds(userid);
ArrayList<String> 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<String> 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<String> 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;
}
/*
*