added My Favorites Filter support methods

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@68733 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-02-02 17:21:56 +00:00
parent 75dd508ba0
commit c331f8f397
4 changed files with 1152 additions and 12 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1195,6 +1195,33 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
return toReturn; return toReturn;
} }
/**
* {@inheritDoc}
*/
@Override
public List<Feed> getAllLikedFeedsByUser(String userid, int limit) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
ArrayList<Feed> toReturn = new ArrayList<Feed>();
List<String> likedFeedIDs = getAllLikedFeedIdsByUser(userid);
//check if quantity is greater than user feeds
limit = (limit > likedFeedIDs.size()) ? likedFeedIDs.size() : limit;
//need them in reverse order
for (int i = likedFeedIDs.size()-1; i >= (likedFeedIDs.size()-limit); i--) {
Feed toAdd = readFeed(likedFeedIDs.get(i));
if (toAdd.getType() == FeedType.TWEET || toAdd.getType() == FeedType.SHARE || toAdd.getType() == FeedType.PUBLISH) {
toReturn.add(toAdd);
_log.trace("Read recent feed: " + likedFeedIDs.get(i));
} else {
_log.trace("Read and skipped feed: " + likedFeedIDs.get(i) + " (Removed Feed)");
limit += 1; //increase the quantity in case of removed feed
//check if quantity is greater than user feeds
limit = (limit > likedFeedIDs.size()) ? likedFeedIDs.size() : limit;
}
}
return toReturn;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1266,7 +1293,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
else else
throw new NotificationChannelTypeNotFoundException("The Notification Channel Type was not recognized should be one of " + NotificationChannelType.values() + " asked for: " + channelName); throw new NotificationChannelTypeNotFoundException("The Notification Channel Type was 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 .

View File

@ -16,8 +16,11 @@ import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.NotificationChannelType; 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.FeedIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -27,7 +30,7 @@ public class DatabookCassandraTest {
@BeforeClass @BeforeClass
public static void setup() throws Exception { public static void setup() throws Exception {
store = new DBCassandraAstyanaxImpl(true); //set to true if you want to drop the KeySpace and recreate it store = new DBCassandraAstyanaxImpl(false); //set to true if you want to drop the KeySpace and recreate it
} }
@AfterClass @AfterClass
@ -58,16 +61,26 @@ public class DatabookCassandraTest {
} }
} }
@Test
public void testLikedFeedsRetrieval() {
try {
for (Feed feed : store.getAllLikedFeedsByUser("luca.frosini", 10)) {
System.out.println(feed);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Test @Test
public void testNotificationSettings() { public void testNotificationSettings() {
// try { try {
// for (NotificationChannelType channel : store.getUserNotificationChannels("luca.frosini")) { for (NotificationChannelType channel : store.getUserNotificationChannels("luca.frosini")) {
// System.out.println(channel); System.out.println(channel);
// } }
// } catch (NotificationChannelTypeNotFoundException e) { } catch (NotificationChannelTypeNotFoundException e) {
// e.printStackTrace(); e.printStackTrace();
// }; };
// store.setUserNotificationChannel("luca.frosini", NotificationChannelType.EMAIL, true); // store.setUserNotificationChannel("luca.frosini", NotificationChannelType.EMAIL, true);
} }

View File

@ -20,7 +20,7 @@ import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
/** /**
* @author Massimiliano Assante ISTI-CNR * @author Massimiliano Assante ISTI-CNR
* *
* @version 0.5 Oct 5th 2012 * @version 1.0 Feb 2013
* <class>DatabookStore</class> is the high level interface for querying and adding data to DatabookStore * <class>DatabookStore</class> is the high level interface for querying and adding data to DatabookStore
*/ */
public interface DatabookStore { public interface DatabookStore {
@ -154,7 +154,7 @@ public interface DatabookStore {
/** /**
* @param userid user identifier * @param userid user identifier
* @param limit set 0 to get everything, an int to get the most -limit- notifications * @param limit set 0 to get everything, an int to get the most recent -limit- notifications
* return all the notifications belonging to the userid up to limit, set 0 to get everything * return all the notifications belonging to the userid up to limit, set 0 to get everything
* @throws NotificationTypeNotFoundException * @throws NotificationTypeNotFoundException
* @throws ColumnNameNotFoundException * @throws ColumnNameNotFoundException
@ -255,7 +255,7 @@ public interface DatabookStore {
/** /**
* unlike a feed * unlike a feed
* @param likeid the like identifier to delete * @param likeid the like identifier to delete
* @parma feedid the feedid to shich the comment is associated * @param feedid the feedid to shich the comment is associated
* @return true if success, false otherwise * @return true if success, false otherwise
*/ */
boolean unlike(String likeid, String feedid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, LikeIDNotFoundException, FeedIDNotFoundException; boolean unlike(String likeid, String feedid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, LikeIDNotFoundException, FeedIDNotFoundException;
@ -264,6 +264,17 @@ public interface DatabookStore {
* return all the feedids a user has liked * return all the feedids a user has liked
*/ */
List<String> getAllLikedFeedIdsByUser(String userid); List<String> getAllLikedFeedIdsByUser(String userid);
/**
* @param userid user identifier
* @param limit set 0 to get everything, an int to get the most recent -limit- liked feeds
* @throws ColumnNameNotFoundException .
* @throws FeedIDNotFoundException .
* @throws FeedTypeNotFoundException .
* @throws PrivacyLevelTypeNotFoundException
* @throws FeedIDNotFoundException .
* return all the feeds a user has liked
*/
List<Feed> getAllLikedFeedsByUser(String userid, int limit) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException;
/** /**
* @param feedid feed identifier * @param feedid feed identifier
* return all the likes belonging to the feedid * return all the likes belonging to the feedid