From 004e2cec2b4461a4b27fcbcef488aa3fdb426a2d Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 29 Jun 2015 15:49:49 +0000 Subject: [PATCH] support for invites invites management alpha version is complete git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@115627 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.jdt.core.prefs | 11 ++- .../server/DBCassandraAstyanaxImpl.java | 79 +++++++++++++------ .../server/DatabookCassandraTest.java | 18 +++-- .../portal/databook/server/DatabookStore.java | 19 ++--- .../portal/databook/shared/InviteStatus.java | 15 +++- 5 files changed, 99 insertions(+), 43 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 06ad0dc..6249222 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,12 @@ -#Tue Dec 04 18:04:58 CET 2012 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 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 8de2a0e..634ed8a 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -1576,7 +1576,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { .putColumn("SenderFullName", invite.getSenderFullName(), null); return m; } - + /** * {@inheritDoc} */ @@ -1615,7 +1615,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { if (isExistingInvite(invite.getVreid(), invite.getInvitedEmail()) != null) return InviteOperationResult.ALREADY_INVITED; _log.debug("Invite not found, proceed to save it ..."); - + MutationBatch m = initSaveInvite(invite); //an entry in the VRE Invites m.withRow(cf_VREInvites, invite.getVreid()) @@ -1660,6 +1660,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } return toReturn; } + /** + * helper method that retrieve all the Invites belonging to a list of Ids + * @param inviteIds the lisf of invites UUID + * @return all the invites belonging to a list of Ids + * @throws InviteIDNotFoundException + * @throws InviteStatusNotFoundException + */ + private List getInvitesById(List inviteIds) throws InviteIDNotFoundException, InviteStatusNotFoundException { + ArrayList toReturn = new ArrayList(); + for (String inviteid : inviteIds) + toReturn.add(readInvite(inviteid)); + + return toReturn; + } /** * {@inheritDoc} * @throws InviteStatusNotFoundException @@ -1689,24 +1703,39 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { * {@inheritDoc} */ @Override - public List getAllInvitedEmailsByVRE(String vreid) { - // TODO Auto-generated method stub - return null; - } - /** - * {@inheritDoc} - */ - @Override - public List getPendingInvitedEmailsByVRE(String vreid) { - // TODO Auto-generated method stub - return null; + public List getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException{ + OperationResult> result = null; + try { + result = conn.getKeyspace().prepareQuery(cf_VREInvites) + .getKeySlice(vreid) + .execute(); + } catch (ConnectionException e) { + e.printStackTrace(); + } + ArrayList invitesIds = new ArrayList(); + // Iterate rows and their columns + for (Row row : result.getResult()) { + if (status != null) { + for (Column column : row.getColumns()) { + for (int i = 0; i < status.length; i++) { + if (column.getStringValue().compareTo(status[i].toString())==0) + invitesIds.add(column.getName()); + } + + } + } + else { + for (Column column : row.getColumns()) + invitesIds.add(column.getName()); + } + } + return getInvitesById(invitesIds); } /** * {@inheritDoc} */ @Override public void closeConnection() { - // TODO Auto-generated method stub } /* * @@ -1782,7 +1811,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { else throw new FeedTypeNotFoundException("The Feed Type was not recognized should be one of " + FeedType.values() + " asked for: " + type); } - + /** * simply return an enum representing the invite status type * @param type . @@ -1790,17 +1819,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { * @throws TypeNotFoundException . */ private InviteStatus getInviteStatusType(String type) throws InviteStatusNotFoundException { - if (type.compareTo("PENDING") == 0) { + switch (type) { + case "PENDING": return InviteStatus.PENDING; - } - else if (type.compareTo("ACCEPTED") == 0) { + case "ACCEPTED": return InviteStatus.ACCEPTED; - } - else if (type.compareTo("REJECTED") == 0) { + case "REJECTED": return InviteStatus.REJECTED; - } - else + case "RETRACTED": + return InviteStatus.RETRACTED; + default: throw new InviteStatusNotFoundException("The Invite Status was not recognized should be one of " + InviteStatus.values() + " asked for: " + type); + } + } /** @@ -2044,8 +2075,8 @@ 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 b1a0f00..4dffd1c 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java @@ -58,15 +58,23 @@ public class DatabookCassandraTest { public void testInvites() { String controlCode = UUID.randomUUID().toString(); String vreid = "/gcube/devsec/devVRE"; - String email = "m.assante@gmail.com"; - Invite invite = new Invite(UUID.randomUUID().toString(), "massimiliano.assante", vreid, email, controlCode, InviteStatus.PENDING, new Date(), "Massimiliano Assante"); + 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(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(); } 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 e7c5175..2100a07 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookStore.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookStore.java @@ -240,7 +240,7 @@ public interface DatabookStore { * @return true if there are unread messages notifications (including messages), false if they are all read */ boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException; - + /** * return the channels a user chose for being notified for a given notification type * @param userid user identifier @@ -264,7 +264,7 @@ public interface DatabookStore { * @throws NotificationChannelTypeNotFoundException self explaining */ Map getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException; - + /** * add a comment to a feed * @param comment the Comment instance to add @@ -376,7 +376,7 @@ public interface DatabookStore { /** * read an invite from a given id * @throws InviteIDNotFoundException - * @throws InviteIDNotFoundException + * @throws InviteStatusNotFoundException */ Invite readInvite(String inviteid) throws InviteIDNotFoundException, InviteStatusNotFoundException; /** @@ -385,13 +385,14 @@ public interface DatabookStore { */ boolean setInviteStatus(String vreid, String email, InviteStatus status) throws InviteIDNotFoundException, InviteStatusNotFoundException; /** - * return the list of invites - * @param vreid - * @return + * Use to get the list of invites per VRE + * @param vreid the vre id + * @param status optional, if you want to restict on the status, e.g. all pending invites + * @return return the list of invites + * @throws InviteIDNotFoundException + * @throws InviteStatusNotFoundException */ - List getAllInvitedEmailsByVRE(String vreid); - - List getPendingInvitedEmailsByVRE(String vreid); + List getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException; /** * close the connection to the underlying database */ diff --git a/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java b/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java index b3b5b90..62df7ea 100644 --- a/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java +++ b/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java @@ -1,7 +1,20 @@ package org.gcube.portal.databook.shared; public enum InviteStatus { + /** + * First status of anyh invite + */ PENDING, + /** + * User accepted the invite + */ ACCEPTED, - REJECTED; + /** + * User rejected the invite + */ + REJECTED, + /** + * Manager withdrawed the invite + */ + RETRACTED; }