implemented get notifications by range

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@94115 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-04-02 16:03:42 +00:00
parent d216551fcd
commit f89400c81a
3 changed files with 389 additions and 336 deletions

View File

@ -879,6 +879,38 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public List<Notification> getRangeNotificationsByUser(String userid,int from, int quantity) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException {
if (from < 1) {
throw new IllegalArgumentException("From must be greather than 0");
}
ArrayList<Notification> toReturn = new ArrayList<Notification>();
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
//if from is greater than feeds size return empty
if (from >= notificationsIDs.size()) {
_log.warn("The starting point of the range is greather than the total number of feeds for this timeline: " + from + " >= " + notificationsIDs.size());
return new ArrayList<Notification>();
}
int rangeStart = notificationsIDs.size()-from;
int rangeEnd = rangeStart-quantity;
//check that you reached the end
if (rangeEnd<1)
rangeEnd = 0;
_log.debug("BEFORE starting Point=" + rangeStart + " rangeEnd= " + rangeEnd);
//need them in reverse order
for (int i = rangeStart; i > rangeEnd; i--) {
Notification toAdd = readNotification(notificationsIDs.get(i));
toReturn.add(toAdd);
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@Override
public boolean setAllNotificationReadByUser(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException { public boolean setAllNotificationReadByUser(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException {
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid); ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
@ -1625,4 +1657,5 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }

View File

@ -39,352 +39,362 @@ public class DatabookCassandraTest {
System.out.println("End"); System.out.println("End");
} }
// //
// /** // /**
// * use exclusively to add a new CF to a keyspace // * use exclusively to add a new CF to a keyspace
// */ // */
// @Test // @Test
// public void addNotifPreferencesColumnFamily() { // public void addNotifPreferencesColumnFamily() {
// // ColumnFamily<String, String> cf_UserNotificationsPreferences = new ColumnFamily<String, String>( // // ColumnFamily<String, String> cf_UserNotificationsPreferences = new ColumnFamily<String, String>(
// // DBCassandraAstyanaxImpl.USER_NOTIFICATIONS_PREFERENCES, // Column Family Name // // DBCassandraAstyanaxImpl.USER_NOTIFICATIONS_PREFERENCES, // Column Family Name
// // StringSerializer.get(), // Key Serializer // // StringSerializer.get(), // Key Serializer
// // StringSerializer.get()); // Column Serializer // // StringSerializer.get()); // Column Serializer
// // // //
// // try { // // try {
// // new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_UserNotificationsPreferences, ImmutableMap.<String, Object>builder() // // new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_UserNotificationsPreferences, ImmutableMap.<String, Object>builder()
// // .put("default_validation_class", "UTF8Type") // // .put("default_validation_class", "UTF8Type")
// // .put("key_validation_class", "UTF8Type") // // .put("key_validation_class", "UTF8Type")
// // .put("comparator_type", "UTF8Type") // // .put("comparator_type", "UTF8Type")
// // .build()); // // .build());
// // } catch (ConnectionException e) { // // } catch (ConnectionException e) {
// // e.printStackTrace(); // // e.printStackTrace();
// // } // // }
// } // }
// //
// @Test // @Test
// public void testFriendships() { // public void testFriendships() {
// assertTrue(store.requestFriendship("massimiliano.assante", "leonardo.candela")); // assertTrue(store.requestFriendship("massimiliano.assante", "leonardo.candela"));
// assertTrue(store.requestFriendship("massimiliano.assante", "ermit")); // assertTrue(store.requestFriendship("massimiliano.assante", "ermit"));
// assertTrue(store.requestFriendship("massimiliano.assante", "giorgino")); // assertTrue(store.requestFriendship("massimiliano.assante", "giorgino"));
// assertTrue(store.requestFriendship("barabba", "massimiliano.assante")); // assertTrue(store.requestFriendship("barabba", "massimiliano.assante"));
// //
// assertTrue(store.approveFriendship("leonardo.candela", "massimiliano.assante")); // assertTrue(store.approveFriendship("leonardo.candela", "massimiliano.assante"));
// assertTrue(store.approveFriendship("ermit", "massimiliano.assante")); // assertTrue(store.approveFriendship("ermit", "massimiliano.assante"));
// //
// assertTrue(store.denyFriendship("giorgino", "massimiliano.assante")); // assertTrue(store.denyFriendship("giorgino", "massimiliano.assante"));
// System.out.println("Pending Connections for massimiliano.assante:"); // System.out.println("Pending Connections for massimiliano.assante:");
// for (String userid: store.getPendingFriendRequests("massimiliano.assante")) { // for (String userid: store.getPendingFriendRequests("massimiliano.assante")) {
// System.out.println(userid); // System.out.println(userid);
// } // }
// //
// System.out.println("Connections for massimiliano.assante:"); // System.out.println("Connections for massimiliano.assante:");
// for (String userid: store.getFriends("massimiliano.assante")) { // for (String userid: store.getFriends("massimiliano.assante")) {
// System.out.println(userid); // System.out.println(userid);
// } // }
// //
// } // }
// @Test // @Test
// public void testLikedFeedsRetrieval() { // public void testLikedFeedsRetrieval() {
// try { // try {
// for (Feed feed : store.getAllLikedFeedsByUser("luca.frosini", 10)) { // for (Feed feed : store.getAllLikedFeedsByUser("luca.frosini", 10)) {
// System.out.println(feed); // System.out.println(feed);
// } // }
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// //
// @Test // @Test
// public void testSingleNotificationPreference() { // public void testSingleNotificationPreference() {
// try { // try {
// for (NotificationChannelType channel : store.getUserNotificationChannels("massimiliano.assante", NotificationType.COMMENT)) { // for (NotificationChannelType channel : store.getUserNotificationChannels("massimiliano.assante", NotificationType.COMMENT)) {
// System.out.println(channel); // System.out.println(channel);
// } // }
// } catch (NotificationChannelTypeNotFoundException e) { // } catch (NotificationChannelTypeNotFoundException e) {
// e.printStackTrace(); // e.printStackTrace();
// } catch (NotificationTypeNotFoundException e) { // } catch (NotificationTypeNotFoundException e) {
// e.printStackTrace(); // e.printStackTrace();
// }; // };
// HashMap<NotificationType, NotificationChannelType[]> toCreate = new HashMap<NotificationType, NotificationChannelType[]>(); // HashMap<NotificationType, NotificationChannelType[]> toCreate = new HashMap<NotificationType, NotificationChannelType[]>();
// for (int i = 0; i < NotificationType.values().length; i++) { // for (int i = 0; i < NotificationType.values().length; i++) {
// if (i == 0) // if (i == 0)
// toCreate.put(NotificationType.values()[i], null); // toCreate.put(NotificationType.values()[i], null);
// else if (i ==3) { // else if (i ==3) {
// NotificationChannelType[] nots = {NotificationChannelType.PORTAL}; // NotificationChannelType[] nots = {NotificationChannelType.PORTAL};
// toCreate.put(NotificationType.values()[i], nots); // toCreate.put(NotificationType.values()[i], nots);
// } // }
// else // else
// toCreate.put(NotificationType.values()[i], NotificationChannelType.values()); // toCreate.put(NotificationType.values()[i], NotificationChannelType.values());
// } // }
// store.setUserNotificationPreferences("antonio.gioia", toCreate); // store.setUserNotificationPreferences("antonio.gioia", toCreate);
// //
// //
// try { // try {
// for (NotificationChannelType channel : store.getUserNotificationChannels("antonio.gioia", NotificationType.WP_FOLDER_RENAMED)) { //i == 3 // for (NotificationChannelType channel : store.getUserNotificationChannels("antonio.gioia", NotificationType.WP_FOLDER_RENAMED)) { //i == 3
// System.out.println(channel); // System.out.println(channel);
// } // }
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// @Test // @Test
// public void testSingleNotification() { // public void testSingleNotification() {
// Notification not = new Notification( // Notification not = new Notification(
// UUID.randomUUID().toString(), // UUID.randomUUID().toString(),
// NotificationType.LIKE, // NotificationType.LIKE,
// "leonardo.candela", // "leonardo.candela",
// "MESSAGEID", // "MESSAGEID",
// new Date(), // new Date(),
// "uri", // "uri",
// "This is notification about a like", // "This is notification about a like",
// false, // false,
// "leonardo.candela", "Leonardo Candela", // "leonardo.candela", "Leonardo Candela",
// "thumburl"); // "thumburl");
// assertTrue(store.saveNotification(not)); // assertTrue(store.saveNotification(not));
// //
// not = new Notification( // not = new Notification(
// UUID.randomUUID().toString(), // UUID.randomUUID().toString(),
// NotificationType.MESSAGE, // NotificationType.MESSAGE,
// "massimiliano.assante", // "massimiliano.assante",
// "MESSAGEID", // "MESSAGEID",
// new Date(), // new Date(),
// "uri", // "uri",
// "This is notification about a like", // "This is notification about a like",
// false, // false,
// "antonio.gioia", "Antonio Gioia", // "antonio.gioia", "Antonio Gioia",
// "thumburl"); // "thumburl");
// assertTrue(store.saveNotification(not)); // assertTrue(store.saveNotification(not));
// System.out.println("Writing one Notification " + not); // System.out.println("Writing one Notification " + not);
// } // }
// //
// @Test // @Test
// public void testNotifications() { // public void testNotifications() {
// Notification not = null; // Notification not = null;
// System.out.println("Writing 18 Notifications"); // System.out.println("Writing 18 Notifications");
// int count = 18; // int count = 18;
// for (int i = 0; i < count; i++) { // for (int i = 0; i < count; i++) {
// if (i % 2 != 0) { // if (i % 2 != 0) {
// not = new Notification(UUID.randomUUID().toString(), NotificationType.JOB_COMPLETED_OK, // not = new Notification(UUID.randomUUID().toString(), NotificationType.JOB_COMPLETED_OK,
// "leonardo.candela", "TWEETID", new Date(), "uri", "This is notification about job completed OK #"+i, false, "pasquale.pagano", "Pasquale Pagano", "thumburl"); // "leonardo.candela", "TWEETID", new Date(), "uri", "This is notification about job completed OK #"+i, false, "pasquale.pagano", "Pasquale Pagano", "thumburl");
// } else { // } else {
// not = new Notification(UUID.randomUUID().toString(), NotificationType.JOB_COMPLETED_NOK, // not = new Notification(UUID.randomUUID().toString(), NotificationType.JOB_COMPLETED_NOK,
// "massimiliano.assante", "MESSAGEID", new Date(), "uri", "This is notification about completed NOK #"+i, false, "leonardo.candela", "Leonardo Candela", "thumburl"); // "massimiliano.assante", "MESSAGEID", new Date(), "uri", "This is notification about completed NOK #"+i, false, "leonardo.candela", "Leonardo Candela", "thumburl");
// } // }
// assertTrue(store.saveNotification(not)); // assertTrue(store.saveNotification(not));
// try { // try {
// Thread.sleep(150); // Thread.sleep(150);
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// // TODO Auto-generated catch block // // TODO Auto-generated catch block
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// Notification rNot= null; // Notification rNot= null;
// try { // try {
// //
// //read // //read
// rNot = store.readNotification(not.getKey().toString()); // rNot = store.readNotification(not.getKey().toString());
// assertNotNull(rNot); // assertNotNull(rNot);
// System.out.println("Reading one Notification " + rNot.getKey() + ": " + rNot.getDescription() + " Type: " + rNot.getType()); // System.out.println("Reading one Notification " + rNot.getKey() + ": " + rNot.getDescription() + " Type: " + rNot.getType());
// //
// //set Read // //set Read
// assertTrue(store.setNotificationRead(rNot.getKey().toString())); // assertTrue(store.setNotificationRead(rNot.getKey().toString()));
// //
// System.out.println("Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " was set to READ"); // System.out.println("Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " was set to READ");
// //
// not = new Notification(UUID.randomUUID().toString(), NotificationType.LIKE, // not = new Notification(UUID.randomUUID().toString(), NotificationType.LIKE,
// "leonardo.candela", "FEEDID", new Date(), "uri", "This is notification of a Liked Leo feed by Massi", false, "massimiliano.assante", "Massimiliano Assante", "thumburl"); // "leonardo.candela", "FEEDID", new Date(), "uri", "This is notification of a Liked Leo feed by Massi", false, "massimiliano.assante", "Massimiliano Assante", "thumburl");
// assertTrue(store.saveNotification(not)); // assertTrue(store.saveNotification(not));
// try { // try {
// Thread.sleep(150); // Thread.sleep(150);
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// // TODO Auto-generated catch block // // TODO Auto-generated catch block
// e.printStackTrace(); // e.printStackTrace();
// } // }
// rNot = store.readNotification(not.getKey().toString()); // rNot = store.readNotification(not.getKey().toString());
// System.out.println("Reading another Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " Read:? " + rNot.isRead()); // System.out.println("Reading another Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " Read:? " + rNot.isRead());
// // //set Read // // //set Read
// // assertTrue(store.setNotificationRead(rNot.getKey().toString())); // // assertTrue(store.setNotificationRead(rNot.getKey().toString()));
// // System.out.println("Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " was set to READ subject was this: " + rNot.getSubjectid()); // // System.out.println("Notification " + rNot.getKey() + " of Type: " + rNot.getType() + " was set to READ subject was this: " + rNot.getSubjectid());
// // // //
// Random randomGenerator = new Random(); // Random randomGenerator = new Random();
// //
// System.out.println("leonardo.candela Notifications: "); // System.out.println("leonardo.candela Notifications: ");
// List<Notification> recentNots = store.getAllNotificationByUser("leonardo.candela", randomGenerator.nextInt(50)); // List<Notification> recentNots = store.getAllNotificationByUser("leonardo.candela", randomGenerator.nextInt(50));
// assertNotNull(recentNots); // assertNotNull(recentNots);
// for (Notification notif :recentNots) // for (Notification notif :recentNots)
// System.out.println(notif); // System.out.println(notif);
// //
// //
// System.out.println("massimiliano.assante Notifications: "); // System.out.println("massimiliano.assante Notifications: ");
// recentNots = store.getUnreadNotificationsByUser("massimiliano.assante"); // recentNots = store.getUnreadNotificationsByUser("massimiliano.assante");
// assertNotNull(recentNots); // assertNotNull(recentNots);
// for (Notification notif :recentNots) // for (Notification notif :recentNots)
// System.out.println(notif); // System.out.println(notif);
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// //
@Test @Test
public void testFeeds() { public void testFeeds() {
// int count = 18; // int count = 18;
// Feed feed = null; // Feed feed = null;
// for (int i = 0; i < count; i++) { // for (int i = 0; i < count; i++) {
// if (i % 2 != 0) { // if (i % 2 != 0) {
// feed = new Feed(UUID.randomUUID().toString(), FeedType.JOIN, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // feed = new Feed(UUID.randomUUID().toString(), FeedType.JOIN, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
// "www.d4science.org/monitor", "thumbUri", "This is feed# "+ i, PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host"); // "www.d4science.org/monitor", "thumbUri", "This is feed# "+ i, PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host");
// } else { // } else {
// feed = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, "leonardo.candela", new Date(), "", // feed = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, "leonardo.candela", new Date(), "",
// "www.d4science.org/web/guest", "thumbUri", "This is feed# "+ i, PrivacyLevel.PORTAL, "Leonardo Candela", "leonardo.candela@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host"); // "www.d4science.org/web/guest", "thumbUri", "This is feed# "+ i, PrivacyLevel.PORTAL, "Leonardo Candela", "leonardo.candela@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host");
// } // }
// assertTrue(store.saveUserFeed(feed)); // assertTrue(store.saveUserFeed(feed));
// try { // try {
// Thread.sleep(150); // Thread.sleep(150);
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// // TODO Auto-generated catch block // // TODO Auto-generated catch block
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// Feed rFeed = null; // Feed rFeed = null;
// try { // try {
// rFeed = store.readFeed(feed.getKey().toString()); // rFeed = store.readFeed(feed.getKey().toString());
// rFeed = store.readFeed(feed.getKey().toString()); // rFeed = store.readFeed(feed.getKey().toString());
// rFeed = store.readFeed(feed.getKey().toString()); // rFeed = store.readFeed(feed.getKey().toString());
// rFeed = store.readFeed(feed.getKey().toString()); // rFeed = store.readFeed(feed.getKey().toString());
// assertNotNull(rFeed); // assertNotNull(rFeed);
// //
// String feedIdToDelete = UUID.randomUUID().toString(); // String feedIdToDelete = UUID.randomUUID().toString();
// feed = new Feed(feedIdToDelete, FeedType.PUBLISH, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // feed = new Feed(feedIdToDelete, FeedType.PUBLISH, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
// "www.d4science.org/monitor", "thumbUri", "This is feed to be deleted", PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false); // "www.d4science.org/monitor", "thumbUri", "This is feed to be deleted", PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
// assertTrue(store.saveUserFeed(feed)); // assertTrue(store.saveUserFeed(feed));
// try { // try {
// Thread.sleep(250); // Thread.sleep(250);
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// // TODO Auto-generated catch block // // TODO Auto-generated catch block
// e.printStackTrace(); // e.printStackTrace();
// } // }
// System.out.println("Test Delete Feed "); // System.out.println("Test Delete Feed ");
// assertTrue(store.deleteFeed(feedIdToDelete)); // assertTrue(store.deleteFeed(feedIdToDelete));
// //
// System.out.println("massimiliano.assante ALL FEEDS: "); // System.out.println("massimiliano.assante ALL FEEDS: ");
// for (Feed recFeed : store.getAllFeedsByUser("massimiliano.assante")) // for (Feed recFeed : store.getAllFeedsByUser("massimiliano.assante"))
// System.out.println(recFeed); // System.out.println(recFeed);
// //
// Random randomGenerator = new Random(); // Random randomGenerator = new Random();
// //
// System.out.println("leonardo.candela TIMELINE: "); // System.out.println("leonardo.candela TIMELINE: ");
// List<Feed> recentFeeds = store.getRecentFeedsByUser("leonardo.candela", randomGenerator.nextInt(50)); // List<Feed> recentFeeds = store.getRecentFeedsByUser("leonardo.candela", randomGenerator.nextInt(50));
// assertNotNull(recentFeeds); // assertNotNull(recentFeeds);
// for (Feed recFeed :recentFeeds) // for (Feed recFeed :recentFeeds)
// System.out.println(recFeed); // System.out.println(recFeed);
try { try {
//store.enableDeletedPosts(); //store.enableDeletedPosts();
System.out.println("/gcube/devsec/devVRE TIMELINE: "); System.out.println("Notifications TIMELINE: ");
int from = 1;
int from = 0;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
System.out.println("\nFROM="+from); System.out.println("\nFROM="+from);
RangeFeeds range = store.getRecentFeedsByVREAndRange("/gcube/devsec/TestVREFolder2", from, 5); List<Notification> range = store.getRangeNotificationsByUser("massimiliano.assante", from, 50);
List<Feed> recentFeeds = range.getFeeds(); for (Notification notification : range) {
assertNotNull(recentFeeds); System.out.println(notification.getDescription());
for (Feed recFeed :recentFeeds) from = 1+i * 50;
System.out.println("->"+recFeed.getDescription()); }
from = range.getLastReturnedFeedTimelineIndex()-1;
} }
// int from = 1;
// for (int i = 0; i < 5; i++) {
// System.out.println("\nFROM="+from);
// RangeFeeds range = store.getRecentFeedsByVREAndRange("/gcube/devsec/TestVREFolder2", from, 5);
// List<Feed> recentFeeds = range.getFeeds();
// assertNotNull(recentFeeds);
// for (Feed recFeed :recentFeeds)
// System.out.println("->"+recFeed.getDescription());
// from = range.getLastReturnedFeedTimelineIndex()-1;
// }
// System.out.println("PORTAL TIMELINE: ");
// recentFeeds = store.getAllPortalPrivacyLevelFeeds(); // System.out.println("PORTAL TIMELINE: ");
// assertNotNull(recentFeeds); // recentFeeds = store.getAllPortalPrivacyLevelFeeds();
// for (Feed recFeed :recentFeeds) // assertNotNull(recentFeeds);
// System.out.println(recFeed); // for (Feed recFeed :recentFeeds)
// System.out.println(recFeed);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
// //
// // @Test // // @Test
// // public void testNotifications() { // // public void testNotifications() {
// // int count = 10; // // int count = 10;
// // Notification notf = null; // // Notification notf = null;
// // for (int i = 0; i < count; i++) { // // for (int i = 0; i < count; i++) {
// // notf = new Notification(UUID.randomUUID().toString(), NotificationType.MESSAGE, "massimiliano.assante", new Date(), "http://urir.com", "Desc #"+i, "Gino Camillo", false); // // notf = new Notification(UUID.randomUUID().toString(), NotificationType.MESSAGE, "massimiliano.assante", new Date(), "http://urir.com", "Desc #"+i, "Gino Camillo", false);
// // assertTrue(store.saveNotification(notf)); // // assertTrue(store.saveNotification(notf));
// // } // // }
// // try { // // try {
// // assertNotNull(store.getAllNotificationByUser("massimiliano.assante")); // // assertNotNull(store.getAllNotificationByUser("massimiliano.assante"));
// // } catch (Exception e) { // // } catch (Exception e) {
// // e.printStackTrace(); // // e.printStackTrace();
// // } // // }
// // } // // }
// //
// @Test // @Test
// public void testComments() { // public void testComments() {
// int count = 10; // int count = 10;
// Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
// "http://www.d4science.org/monitor", "thumbUri", "This is feed that is going to be commented ", PrivacyLevel.PUBLIC, "Massimiliano Assante", // "http://www.d4science.org/monitor", "thumbUri", "This is feed that is going to be commented ", PrivacyLevel.PUBLIC, "Massimiliano Assante",
// "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false); // "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
// assertTrue(store.saveUserFeed(feed)); // assertTrue(store.saveUserFeed(feed));
// //
// Comment toDelete = null; // Comment toDelete = null;
// for (int i = 0; i < count; i++) { // for (int i = 0; i < count; i++) {
// try { // try {
// toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela", // toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela",
// new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl"); // new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl");
// assertTrue(store.addComment(toDelete)); // assertTrue(store.addComment(toDelete));
// //
// } catch (FeedIDNotFoundException e) { // } catch (FeedIDNotFoundException e) {
// System.out.println("Exception feed id not found"); // System.out.println("Exception feed id not found");
// } // }
// } // }
// System.out.println("GetAllCOmmentsByFeed "); // System.out.println("GetAllCOmmentsByFeed ");
// for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) { // for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) {
// System.out.println(cm.getText()); // System.out.println(cm.getText());
// }; // };
// //
// try { // try {
// assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid())); // assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid()));
// } catch (Exception e) { // } catch (Exception e) {
// System.out.println("Exception feed id not found"); // System.out.println("Exception feed id not found");
// } // }
// } // }
// //
// @Test // @Test
// public void testLikes() { // public void testLikes() {
// int count = 10; // int count = 10;
// Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
// "http://www.d4science.org/monitor", "thumbUri", "This feed is Liked ", PrivacyLevel.PUBLIC, // "http://www.d4science.org/monitor", "thumbUri", "This feed is Liked ", PrivacyLevel.PUBLIC,
// "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false); // "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
// assertTrue(store.saveUserFeed(feed)); // assertTrue(store.saveUserFeed(feed));
// Like toUnlike = new Like(UUID.randomUUID().toString(),"massimiliano.assante", // Like toUnlike = new Like(UUID.randomUUID().toString(),"massimiliano.assante",
// new Date(), feed.getKey().toString(), "Massi Pallino", "thumbUrl"); // new Date(), feed.getKey().toString(), "Massi Pallino", "thumbUrl");
// //
// try { // try {
// assertTrue(store.like(toUnlike)); // assertTrue(store.like(toUnlike));
// for (int i = 0; i < count; i++) // for (int i = 0; i < count; i++)
// assertTrue(store.like(new Like(UUID.randomUUID().toString(),"massimiliano.assante", // assertTrue(store.like(new Like(UUID.randomUUID().toString(),"massimiliano.assante",
// new Date(), feed.getKey().toString(), "Rino Pallino", "thumbUrl"))); // new Date(), feed.getKey().toString(), "Rino Pallino", "thumbUrl")));
// //
// System.out.println("massimiliano.assante liked the following feeds: "); // System.out.println("massimiliano.assante liked the following feeds: ");
// for (String feedid : store.getAllLikedFeedIdsByUser("massimiliano.assante")) { // for (String feedid : store.getAllLikedFeedIdsByUser("massimiliano.assante")) {
// System.out.println(feedid); // System.out.println(feedid);
// } // }
// //
// for (Like like : store.getAllLikesByFeed(feed.getKey().toString())) { // for (Like like : store.getAllLikesByFeed(feed.getKey().toString())) {
// System.out.println(like); // System.out.println(like);
// } // }
// //
// System.out.println("trying unlike"); // System.out.println("trying unlike");
// assertTrue(store.unlike(toUnlike.getKey(), toUnlike.getFeedid())); // assertTrue(store.unlike(toUnlike.getKey(), toUnlike.getFeedid()));
// //
// } catch (Exception e) { // } catch (Exception e) {
// System.out.println("Exception feed id not found"); // System.out.println("Exception feed id not found");
// } // }
// } // }
} }

View File

@ -177,7 +177,17 @@ public interface DatabookStore {
* @throws ColumnNameNotFoundException * @throws ColumnNameNotFoundException
*/ */
List<Notification> getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException; List<Notification> getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException;
/**
*
* @param userid user identifier
* @param from the range start has to be greater than 0
* @param quantity the number of most recent notifications for this user starting from "from" param
* @return all the notifications for the userid in the range requested
* @throws NotificationTypeNotFoundException
* @throws ColumnNameNotFoundException
* @throws NotificationIDNotFoundException
*/
List<Notification> getRangeNotificationsByUser(String userid, int from, int quantity) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException;
/** /**
* This is a fast way to set all notification to read quickly * This is a fast way to set all notification to read quickly
* @param userid * @param userid