From 10518c9d512bc04cb4468fe2475535e637da7770 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 2 Dec 2015 15:50:26 +0000 Subject: [PATCH] added new method for users statistics git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@120563 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 2 +- .../server/DBCassandraAstyanaxImpl.java | 39 +++++++++++ .../server/DatabookCassandraTest.java | 65 ++++++++++--------- .../portal/databook/server/DatabookStore.java | 7 ++ 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 5edaee7..4d085db 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.portal social-networking-library - 1.8.1-SNAPSHOT + 1.8.2-SNAPSHOT gCube Social Networking Library The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities. diff --git a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java index 10e2fa9..6991ec0 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -449,6 +449,44 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { * {@inheritDoc} */ @Override + public List getRecentFeedsByUserAndDate(String userid, long timeInMillis) throws IllegalArgumentException { + Date now = new Date(); + if (timeInMillis > now.getTime()) + throw new IllegalArgumentException("the timeInMillis must be before today"); + + OperationResult> result = null; + try { + result = conn.getKeyspace().prepareQuery(cf_UserTline) + .getKeySlice(userid) + .execute(); + } catch (ConnectionException e) { + e.printStackTrace(); + } + List toReturn = new ArrayList(); + // Iterate rows and their columns + for (Row row : result.getResult()) { + for (Column column : row.getColumns()) { + long feedTime = Long.parseLong(column.getName()); + if (feedTime > timeInMillis) { + try { + Feed toCheck = readFeed(column.getStringValue()); + if (toCheck.getType() != FeedType.DISABLED) + toReturn.add(toCheck); + } catch (PrivacyLevelTypeNotFoundException + | FeedTypeNotFoundException + | FeedIDNotFoundException + | ColumnNameNotFoundException e) { + e.printStackTrace(); + } + } + } + } + return toReturn; + } + /** + * {@inheritDoc} + */ + @Override public boolean deleteFeed(String feedId) throws FeedIDNotFoundException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException { Feed toDelete = readFeed(feedId); MutationBatch m = conn.getKeyspace().prepareMutationBatch(); @@ -2125,6 +2163,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } return isValid; } + diff --git a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java index 7d4968b..33833bc 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java @@ -1,12 +1,8 @@ package org.gcube.portal.databook.server; +import java.util.Calendar; import java.util.Date; -import java.util.List; -import java.util.UUID; -import org.gcube.portal.databook.shared.Invite; -import org.gcube.portal.databook.shared.InviteOperationResult; -import org.gcube.portal.databook.shared.InviteStatus; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -26,31 +22,42 @@ public class DatabookCassandraTest { } @Test - public void testInvites() { - String controlCode = UUID.randomUUID().toString(); - String vreid = "/gcube/devsec/devVRE"; - String email = "ciccio@gmail.com"; - - InviteStatus statusToLookfor = InviteStatus.ACCEPTED; - - Invite invite = new Invite(UUID.randomUUID().toString(), "andrea.rossi", vreid, email, controlCode, InviteStatus.PENDING, new Date(), "Andrea Rossi"); - try { - InviteOperationResult result = store.saveInvite(invite); - System.out.println(result); - String inviteid = store.isExistingInvite(vreid, email); -// System.out.println(store.readInvite(inviteid)); -// store.setInviteStatus(vreid, email, InviteStatus.ACCEPTED); -// System.out.println(store.readInvite(inviteid)); - System.out.println("Looking for all invites in " + vreid + " with status " + statusToLookfor); - List invites = store.getInvitedEmailsByVRE(vreid, statusToLookfor, InviteStatus.PENDING); - for (Invite invite2 : invites) { - System.out.println(invite2); - } - } catch (Exception e) { - e.printStackTrace(); - } - + public void testFeedNumberPerUser() { + String userid = "massimiliano.assante"; + //String userid = "costantino.perciante"; + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.YEAR, -1); + Date now = new Date(); + System.out.println(store.getRecentFeedsByUserAndDate(userid, cal.getTimeInMillis()).size()); + System.out.println(new Date().getTime() - now.getTime()+"ms"); } + +// @Test +// public void testInvites() { +// String controlCode = UUID.randomUUID().toString(); +// String vreid = "/gcube/devsec/devVRE"; +// String email = "ciccio@gmail.com"; +// +// InviteStatus statusToLookfor = InviteStatus.ACCEPTED; +// +// Invite invite = new Invite(UUID.randomUUID().toString(), "andrea.rossi", vreid, email, controlCode, InviteStatus.PENDING, new Date(), "Andrea Rossi"); +// try { +// InviteOperationResult result = store.saveInvite(invite); +// System.out.println(result); +// String inviteid = store.isExistingInvite(vreid, email); +//// System.out.println(store.readInvite(inviteid)); +//// store.setInviteStatus(vreid, email, InviteStatus.ACCEPTED); +//// System.out.println(store.readInvite(inviteid)); +// System.out.println("Looking for all invites in " + vreid + " with status " + statusToLookfor); +// List invites = store.getInvitedEmailsByVRE(vreid, statusToLookfor, InviteStatus.PENDING); +// for (Invite invite2 : invites) { +// System.out.println(invite2); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// } // @Test // public void testHashTag() { diff --git a/src/main/java/org/gcube/portal/databook/server/DatabookStore.java b/src/main/java/org/gcube/portal/databook/server/DatabookStore.java index 0ed3dae..7814421 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookStore.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookStore.java @@ -1,5 +1,6 @@ package org.gcube.portal.databook.server; +import java.util.Calendar; import java.util.List; import java.util.Map; @@ -158,6 +159,12 @@ public interface DatabookStore { * @throws ColumnNameNotFoundException */ RangeFeeds getRecentFeedsByVREAndRange(String vreid, int from, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException; + /** + * @param userid user identifier + * @param timeInMillis time in milliseconds from which you want to start retrieve the feeds + * @return the number of feeds in the range from: today to: timeInMillis + */ + List getRecentFeedsByUserAndDate(String userid, long timeInMillis) throws IllegalArgumentException; /** * save a Notification instance in the store * @return true if everything went fine