added support for notifications settings and tested
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@68582 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1fa3019066
commit
23bc1541b7
2178
.gwt/.gwt-log
2178
.gwt/.gwt-log
File diff suppressed because it is too large
Load Diff
|
@ -187,6 +187,7 @@ public class CassandraClusterConnection {
|
||||||
ColumnFamilyDefinition cfDefUserLikedFeeds = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_LIKED_FEEDS);
|
ColumnFamilyDefinition cfDefUserLikedFeeds = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_LIKED_FEEDS);
|
||||||
ColumnFamilyDefinition cfDefUserNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS);
|
ColumnFamilyDefinition cfDefUserNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS);
|
||||||
ColumnFamilyDefinition cfDefUserMessagesNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_MESSAGES_NOTIFICATIONS);
|
ColumnFamilyDefinition cfDefUserMessagesNotifications = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_MESSAGES_NOTIFICATIONS);
|
||||||
|
ColumnFamilyDefinition cfDefUserNotificationsSettings = getDynamicCFDef(DBCassandraAstyanaxImpl.USER_NOTIFICATIONS_SETTINGS);
|
||||||
|
|
||||||
|
|
||||||
ksDef.setName(keyspaceName)
|
ksDef.setName(keyspaceName)
|
||||||
|
@ -203,6 +204,7 @@ public class CassandraClusterConnection {
|
||||||
.addColumnFamily(cfDefUserTimeline)
|
.addColumnFamily(cfDefUserTimeline)
|
||||||
.addColumnFamily(cfDefUserNotifications)
|
.addColumnFamily(cfDefUserNotifications)
|
||||||
.addColumnFamily(cfDefUserMessagesNotifications)
|
.addColumnFamily(cfDefUserMessagesNotifications)
|
||||||
|
.addColumnFamily(cfDefUserNotificationsSettings)
|
||||||
.addColumnFamily(cfDefUserLikedFeeds);
|
.addColumnFamily(cfDefUserLikedFeeds);
|
||||||
|
|
||||||
cluster.addKeyspace(ksDef);
|
cluster.addKeyspace(ksDef);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.gcube.portal.databook.shared.Feed;
|
||||||
import org.gcube.portal.databook.shared.FeedType;
|
import org.gcube.portal.databook.shared.FeedType;
|
||||||
import org.gcube.portal.databook.shared.Like;
|
import org.gcube.portal.databook.shared.Like;
|
||||||
import org.gcube.portal.databook.shared.Notification;
|
import org.gcube.portal.databook.shared.Notification;
|
||||||
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
||||||
import org.gcube.portal.databook.shared.NotificationType;
|
import org.gcube.portal.databook.shared.NotificationType;
|
||||||
import org.gcube.portal.databook.shared.PrivacyLevel;
|
import org.gcube.portal.databook.shared.PrivacyLevel;
|
||||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||||
|
@ -20,6 +21,7 @@ import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
|
||||||
|
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||||
|
@ -63,6 +65,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
||||||
public static final String USER_LIKED_FEEDS = "USERLikes";
|
public static final String USER_LIKED_FEEDS = "USERLikes";
|
||||||
public static final String USER_NOTIFICATIONS = "USERNotifications"; // regular user notifications timeline
|
public static final String USER_NOTIFICATIONS = "USERNotifications"; // regular user notifications timeline
|
||||||
public static final String USER_MESSAGES_NOTIFICATIONS = "USERMessagesNotifications"; // user messages notifications timeline
|
public static final String USER_MESSAGES_NOTIFICATIONS = "USERMessagesNotifications"; // user messages notifications timeline
|
||||||
|
public static final String USER_NOTIFICATIONS_SETTINGS = "USERNotificationsSettings"; // settings for notifications
|
||||||
|
|
||||||
private static ColumnFamily<String, String> cf_Connections = new ColumnFamily<String, String>(
|
private static ColumnFamily<String, String> cf_Connections = new ColumnFamily<String, String>(
|
||||||
CONNECTIONS, // Column Family Name
|
CONNECTIONS, // Column Family Name
|
||||||
|
@ -115,6 +118,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
||||||
USER_MESSAGES_NOTIFICATIONS, // Column Family Name
|
USER_MESSAGES_NOTIFICATIONS, // Column Family Name
|
||||||
StringSerializer.get(), // Key Serializer
|
StringSerializer.get(), // Key Serializer
|
||||||
StringSerializer.get()); // Column Serializer
|
StringSerializer.get()); // Column Serializer
|
||||||
|
private static ColumnFamily<String, String> cf_UserNotificationsSettings = new ColumnFamily<String, String>(
|
||||||
|
USER_NOTIFICATIONS_SETTINGS, // Column Family Name
|
||||||
|
StringSerializer.get(), // Key Serializer
|
||||||
|
StringSerializer.get()); // Column Serializer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connection instance
|
* connection instance
|
||||||
|
@ -885,8 +892,78 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
********************** NOTIFICATION SETTINGS ***********************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* @throws NotificationChannelTypeNotFoundException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<NotificationChannelType> getUserNotificationChannels(String userid) throws NotificationChannelTypeNotFoundException {
|
||||||
|
List<NotificationChannelType> toReturn = new ArrayList<NotificationChannelType>();
|
||||||
|
OperationResult<Rows<String, String>> result = null;
|
||||||
|
try {
|
||||||
|
result = conn.getKeyspace().prepareQuery(cf_UserNotificationsSettings)
|
||||||
|
.getKeySlice(userid)
|
||||||
|
.execute();
|
||||||
|
} catch (ConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//if there are no settings create them and put all of them at true
|
||||||
|
if (result.getResult().getRowByIndex(0).getColumns().size() == 0) {
|
||||||
|
for (int i = 0; i < NotificationChannelType.values().length; i++) {
|
||||||
|
_log.info("Userid " + userid + " settings not found, initiating its settings...");
|
||||||
|
setUserNotificationChannel(userid, NotificationChannelType.values()[i], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (Row<String, String> row : result.getResult())
|
||||||
|
for (Column<String> column : row.getColumns())
|
||||||
|
if (column.getBooleanValue()) toReturn.add(getChannelType(column.getName()));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean setUserNotificationChannel(String userid, NotificationChannelType channel, boolean enabled) {
|
||||||
|
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
|
||||||
|
//check if the value exists and if so update it
|
||||||
|
OperationResult<Rows<String, String>> result = null;
|
||||||
|
try {
|
||||||
|
result = conn.getKeyspace().prepareQuery(cf_UserNotificationsSettings)
|
||||||
|
.getKeySlice(userid)
|
||||||
|
.execute();
|
||||||
|
} catch (ConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean settingExists = false;
|
||||||
|
//if the setting exists and is different from enabled value update it
|
||||||
|
for (Row<String, String> row : result.getResult()) {
|
||||||
|
for (Column<String> column : row.getColumns())
|
||||||
|
if (column.getName().compareTo(channel.toString()) == 0 && (column.getBooleanValue() != enabled) ) {
|
||||||
|
m.withRow(cf_UserNotificationsSettings, userid).putColumn(channel.toString(), enabled, null);
|
||||||
|
settingExists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! settingExists)
|
||||||
|
m.withRow(cf_UserNotificationsSettings, userid).putColumn(channel.toString(), ""+enabled, null);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
boolean overAllresult = execute(m);
|
||||||
|
if (overAllresult)
|
||||||
|
_log.trace("Set Notification Channel for " + userid + " to " + enabled + " OK");
|
||||||
|
else
|
||||||
|
_log.error("Set Notification Channel for " + userid + " to " + enabled + " KO");
|
||||||
|
return overAllresult;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
********************** COMMENTS ***********************
|
********************** COMMENTS ***********************
|
||||||
|
@ -1170,6 +1247,24 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* simply return an enum representing the privacy level
|
||||||
|
* @param privacyLevel .
|
||||||
|
* @return correct enum representing the privacy level
|
||||||
|
* @throws NotificationChannelTypeNotFoundException
|
||||||
|
* @throws FeedTypeNotFoundException
|
||||||
|
*/
|
||||||
|
private NotificationChannelType getChannelType(String channelName) throws NotificationChannelTypeNotFoundException {
|
||||||
|
if (channelName.compareTo("PORTAL") == 0)
|
||||||
|
return NotificationChannelType.PORTAL;
|
||||||
|
else if (channelName.compareTo("EMAIL") == 0)
|
||||||
|
return NotificationChannelType.EMAIL;
|
||||||
|
else if (channelName.compareTo("TWITTER") == 0)
|
||||||
|
return NotificationChannelType.TWITTER;
|
||||||
|
else
|
||||||
|
throw new NotificationChannelTypeNotFoundException("The Notification Channel Type wass not recognized should be one of " + NotificationChannelType.values() + " asked for: " + channelName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* simply return an enum representing the privacy level
|
* simply return an enum representing the privacy level
|
||||||
* @param privacyLevel .
|
* @param privacyLevel .
|
||||||
|
|
|
@ -13,9 +13,11 @@ import org.gcube.portal.databook.shared.Feed;
|
||||||
import org.gcube.portal.databook.shared.FeedType;
|
import org.gcube.portal.databook.shared.FeedType;
|
||||||
import org.gcube.portal.databook.shared.Like;
|
import org.gcube.portal.databook.shared.Like;
|
||||||
import org.gcube.portal.databook.shared.Notification;
|
import org.gcube.portal.databook.shared.Notification;
|
||||||
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
||||||
import org.gcube.portal.databook.shared.NotificationType;
|
import org.gcube.portal.databook.shared.NotificationType;
|
||||||
import org.gcube.portal.databook.shared.PrivacyLevel;
|
import org.gcube.portal.databook.shared.PrivacyLevel;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||||
|
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -57,6 +59,17 @@ public class DatabookCassandraTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNotificationSettings() {
|
||||||
|
try {
|
||||||
|
for (NotificationChannelType channel : store.getUserNotificationChannels("leonardo.candela")) {
|
||||||
|
System.out.println(channel);
|
||||||
|
}
|
||||||
|
} catch (NotificationChannelTypeNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
};
|
||||||
|
store.setUserNotificationChannel("leonardo.candela", NotificationChannelType.TWITTER, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleNotification() {
|
public void testSingleNotification() {
|
||||||
|
|
|
@ -6,11 +6,13 @@ import org.gcube.portal.databook.shared.Comment;
|
||||||
import org.gcube.portal.databook.shared.Feed;
|
import org.gcube.portal.databook.shared.Feed;
|
||||||
import org.gcube.portal.databook.shared.Like;
|
import org.gcube.portal.databook.shared.Like;
|
||||||
import org.gcube.portal.databook.shared.Notification;
|
import org.gcube.portal.databook.shared.Notification;
|
||||||
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
||||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
|
||||||
|
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||||
|
@ -203,6 +205,23 @@ public interface DatabookStore {
|
||||||
* @return true if there are unread messages notifications (including messages), false if they are all read
|
* @return true if there are unread messages notifications (including messages), false if they are all read
|
||||||
*/
|
*/
|
||||||
boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException;
|
boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the channels a user chose for being notified
|
||||||
|
* @param userid user identifier
|
||||||
|
* @return a list of <class>NotificationChannelType</class> that represents the channels this user wants to be notified
|
||||||
|
*/
|
||||||
|
List<NotificationChannelType> getUserNotificationChannels(String userid) throws NotificationChannelTypeNotFoundException;
|
||||||
|
/**
|
||||||
|
* enable or disable the channels to be used for notifying the user
|
||||||
|
* @param userid user identifier
|
||||||
|
* @param channel the type of the channel
|
||||||
|
* @param enabled is you want it to be enabled or not
|
||||||
|
* @return true if everything was fine
|
||||||
|
*/
|
||||||
|
boolean setUserNotificationChannel(String userid, NotificationChannelType channel, boolean enabled);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a comment to a feed
|
* add a comment to a feed
|
||||||
* @param comment the Comment instance to add
|
* @param comment the Comment instance to add
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.gcube.portal.databook.shared;
|
||||||
|
/**
|
||||||
|
* @author Massimiliano Assante ISTI-CNR
|
||||||
|
*
|
||||||
|
* @version 1.0 January 2012
|
||||||
|
*/
|
||||||
|
public enum NotificationChannelType {
|
||||||
|
/**
|
||||||
|
* PORTAL
|
||||||
|
*/
|
||||||
|
PORTAL,
|
||||||
|
/**
|
||||||
|
* EMAIL
|
||||||
|
*/
|
||||||
|
EMAIL,
|
||||||
|
/**
|
||||||
|
* TWITTER
|
||||||
|
*/
|
||||||
|
TWITTER;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ package org.gcube.portal.databook.shared;
|
||||||
/**
|
/**
|
||||||
* @author Massimiliano Assante ISTI-CNR
|
* @author Massimiliano Assante ISTI-CNR
|
||||||
*
|
*
|
||||||
* @version 1.0 July 6th 2012
|
* @version 1.0 January 2012
|
||||||
*/
|
*/
|
||||||
public enum NotificationType {
|
public enum NotificationType {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.gcube.portal.databook.shared.ex;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class NotificationChannelTypeNotFoundException extends Exception {
|
||||||
|
public NotificationChannelTypeNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue