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
This commit is contained in:
Massimiliano Assante 2015-06-29 15:49:49 +00:00
parent d211f7f879
commit 004e2cec2b
5 changed files with 99 additions and 43 deletions

View File

@ -1,9 +1,12 @@
#Tue Dec 04 18:04:58 CET 2012
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.6 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.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1576,7 +1576,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.putColumn("SenderFullName", invite.getSenderFullName(), null); .putColumn("SenderFullName", invite.getSenderFullName(), null);
return m; return m;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1615,7 +1615,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (isExistingInvite(invite.getVreid(), invite.getInvitedEmail()) != null) if (isExistingInvite(invite.getVreid(), invite.getInvitedEmail()) != null)
return InviteOperationResult.ALREADY_INVITED; return InviteOperationResult.ALREADY_INVITED;
_log.debug("Invite not found, proceed to save it ..."); _log.debug("Invite not found, proceed to save it ...");
MutationBatch m = initSaveInvite(invite); MutationBatch m = initSaveInvite(invite);
//an entry in the VRE Invites //an entry in the VRE Invites
m.withRow(cf_VREInvites, invite.getVreid()) m.withRow(cf_VREInvites, invite.getVreid())
@ -1660,6 +1660,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
return toReturn; 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<Invite> getInvitesById(List<String> inviteIds) throws InviteIDNotFoundException, InviteStatusNotFoundException {
ArrayList<Invite> toReturn = new ArrayList<Invite>();
for (String inviteid : inviteIds)
toReturn.add(readInvite(inviteid));
return toReturn;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* @throws InviteStatusNotFoundException * @throws InviteStatusNotFoundException
@ -1689,24 +1703,39 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public List<Invite> getAllInvitedEmailsByVRE(String vreid) { public List<Invite> getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException{
// TODO Auto-generated method stub OperationResult<Rows<String, String>> result = null;
return null; try {
} result = conn.getKeyspace().prepareQuery(cf_VREInvites)
/** .getKeySlice(vreid)
* {@inheritDoc} .execute();
*/ } catch (ConnectionException e) {
@Override e.printStackTrace();
public List<Invite> getPendingInvitedEmailsByVRE(String vreid) { }
// TODO Auto-generated method stub ArrayList<String> invitesIds = new ArrayList<String>();
return null; // Iterate rows and their columns
for (Row<String, String> row : result.getResult()) {
if (status != null) {
for (Column<String> 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<String> column : row.getColumns())
invitesIds.add(column.getName());
}
}
return getInvitesById(invitesIds);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void closeConnection() { public void closeConnection() {
// TODO Auto-generated method stub
} }
/* /*
* *
@ -1782,7 +1811,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
else else
throw new FeedTypeNotFoundException("The Feed Type was not recognized should be one of " + FeedType.values() + " asked for: " + type); 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 * simply return an enum representing the invite status type
* @param type . * @param type .
@ -1790,17 +1819,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* @throws TypeNotFoundException . * @throws TypeNotFoundException .
*/ */
private InviteStatus getInviteStatusType(String type) throws InviteStatusNotFoundException { private InviteStatus getInviteStatusType(String type) throws InviteStatusNotFoundException {
if (type.compareTo("PENDING") == 0) { switch (type) {
case "PENDING":
return InviteStatus.PENDING; return InviteStatus.PENDING;
} case "ACCEPTED":
else if (type.compareTo("ACCEPTED") == 0) {
return InviteStatus.ACCEPTED; return InviteStatus.ACCEPTED;
} case "REJECTED":
else if (type.compareTo("REJECTED") == 0) {
return InviteStatus.REJECTED; return InviteStatus.REJECTED;
} case "RETRACTED":
else return InviteStatus.RETRACTED;
default:
throw new InviteStatusNotFoundException("The Invite Status was not recognized should be one of " + InviteStatus.values() + " asked for: " + type); 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; return isValid;
} }

View File

@ -58,15 +58,23 @@ public class DatabookCassandraTest {
public void testInvites() { public void testInvites() {
String controlCode = UUID.randomUUID().toString(); String controlCode = UUID.randomUUID().toString();
String vreid = "/gcube/devsec/devVRE"; String vreid = "/gcube/devsec/devVRE";
String email = "m.assante@gmail.com"; String email = "ciccio@gmail.com";
Invite invite = new Invite(UUID.randomUUID().toString(), "massimiliano.assante", vreid, email, controlCode, InviteStatus.PENDING, new Date(), "Massimiliano Assante");
InviteStatus statusToLookfor = InviteStatus.ACCEPTED;
Invite invite = new Invite(UUID.randomUUID().toString(), "andrea.rossi", vreid, email, controlCode, InviteStatus.PENDING, new Date(), "Andrea Rossi");
try { try {
InviteOperationResult result = store.saveInvite(invite); InviteOperationResult result = store.saveInvite(invite);
System.out.println(result); System.out.println(result);
String inviteid = store.isExistingInvite(vreid, email); String inviteid = store.isExistingInvite(vreid, email);
System.out.println(store.readInvite(inviteid)); // System.out.println(store.readInvite(inviteid));
store.setInviteStatus(vreid, email, InviteStatus.ACCEPTED); // store.setInviteStatus(vreid, email, InviteStatus.ACCEPTED);
System.out.println(store.readInvite(inviteid)); // 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -240,7 +240,7 @@ public interface DatabookStore {
* @return true if there are unread messages notifications (including messages), false if they are all read * @return true if there are unread messages notifications (including messages), false if they are all read
*/ */
boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException; boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException;
/** /**
* return the channels a user chose for being notified for a given notification type * return the channels a user chose for being notified for a given notification type
* @param userid user identifier * @param userid user identifier
@ -264,7 +264,7 @@ public interface DatabookStore {
* @throws NotificationChannelTypeNotFoundException self explaining * @throws NotificationChannelTypeNotFoundException self explaining
*/ */
Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException; Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException;
/** /**
* add a comment to a feed * add a comment to a feed
* @param comment the Comment instance to add * @param comment the Comment instance to add
@ -376,7 +376,7 @@ public interface DatabookStore {
/** /**
* read an invite from a given id * read an invite from a given id
* @throws InviteIDNotFoundException * @throws InviteIDNotFoundException
* @throws InviteIDNotFoundException * @throws InviteStatusNotFoundException
*/ */
Invite readInvite(String inviteid) throws InviteIDNotFoundException, 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; boolean setInviteStatus(String vreid, String email, InviteStatus status) throws InviteIDNotFoundException, InviteStatusNotFoundException;
/** /**
* return the list of invites * Use to get the list of invites per VRE
* @param vreid * @param vreid the vre id
* @return * @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<Invite> getAllInvitedEmailsByVRE(String vreid); List<Invite> getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException;
List<Invite> getPendingInvitedEmailsByVRE(String vreid);
/** /**
* close the connection to the underlying database * close the connection to the underlying database
*/ */

View File

@ -1,7 +1,20 @@
package org.gcube.portal.databook.shared; package org.gcube.portal.databook.shared;
public enum InviteStatus { public enum InviteStatus {
/**
* First status of anyh invite
*/
PENDING, PENDING,
/**
* User accepted the invite
*/
ACCEPTED, ACCEPTED,
REJECTED; /**
* User rejected the invite
*/
REJECTED,
/**
* Manager withdrawed the invite
*/
RETRACTED;
} }