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;
}
/**
* {@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}
*/
@ -1266,7 +1293,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
else
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
* @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.NotificationType;
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.FeedTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -27,7 +30,7 @@ public class DatabookCassandraTest {
@BeforeClass
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
@ -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
public void testNotificationSettings() {
// try {
// for (NotificationChannelType channel : store.getUserNotificationChannels("luca.frosini")) {
// System.out.println(channel);
// }
// } catch (NotificationChannelTypeNotFoundException e) {
// e.printStackTrace();
// };
try {
for (NotificationChannelType channel : store.getUserNotificationChannels("luca.frosini")) {
System.out.println(channel);
}
} catch (NotificationChannelTypeNotFoundException e) {
e.printStackTrace();
};
// 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
*
* @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
*/
public interface DatabookStore {
@ -154,7 +154,7 @@ public interface DatabookStore {
/**
* @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
* @throws NotificationTypeNotFoundException
* @throws ColumnNameNotFoundException
@ -255,7 +255,7 @@ public interface DatabookStore {
/**
* unlike a feed
* @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
*/
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
*/
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
* return all the likes belonging to the feedid