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
This commit is contained in:
Massimiliano Assante 2015-12-02 15:50:26 +00:00
parent 1f4f753fa8
commit 10518c9d51
4 changed files with 83 additions and 30 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<version>1.8.1-SNAPSHOT</version>
<version>1.8.2-SNAPSHOT</version>
<name>gCube Social Networking Library</name>
<description>
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.

View File

@ -449,6 +449,44 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc}
*/
@Override
public List<Feed> 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<Rows<String, String>> result = null;
try {
result = conn.getKeyspace().prepareQuery(cf_UserTline)
.getKeySlice(userid)
.execute();
} catch (ConnectionException e) {
e.printStackTrace();
}
List<Feed> toReturn = new ArrayList<Feed>();
// Iterate rows and their columns
for (Row<String, String> row : result.getResult()) {
for (Column<String> 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;
}

View File

@ -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<Invite> 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<Invite> invites = store.getInvitedEmailsByVRE(vreid, statusToLookfor, InviteStatus.PENDING);
// for (Invite invite2 : invites) {
// System.out.println(invite2);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
// @Test
// public void testHashTag() {

View File

@ -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<Feed> getRecentFeedsByUserAndDate(String userid, long timeInMillis) throws IllegalArgumentException;
/**
* save a Notification instance in the store
* @return true if everything went fine