diff --git a/.classpath b/.classpath index 51be09f..61d6ab1 100644 --- a/.classpath +++ b/.classpath @@ -20,7 +20,7 @@ - + diff --git a/META-INF/KeySpace Structure.xlsx b/META-INF/KeySpace Structure.xlsx index bf6abfd..fd70642 100644 Binary files a/META-INF/KeySpace Structure.xlsx and b/META-INF/KeySpace Structure.xlsx differ diff --git a/pom.xml b/pom.xml index d30a6d0..2e49aed 100644 --- a/pom.xml +++ b/pom.xml @@ -22,11 +22,11 @@ http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId} - 2.5.1 + 2.7.0 distro - 1.6 - 1.6 + 1.7 + 1.7 UTF-8 UTF-8 @@ -59,6 +59,11 @@ com.google gwt-jsonmaker + + com.sun.mail + javax.mail + provided + com.liferay.portal portal-service @@ -73,11 +78,10 @@ junit 4.8 - com.google.gwt gwt-user - + ${gwtVersion} provided 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 6a1e4f3..8de2a0e 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -10,10 +10,16 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; + import org.apache.commons.lang.NullArgumentException; import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Feed; import org.gcube.portal.databook.shared.FeedType; +import org.gcube.portal.databook.shared.Invite; +import org.gcube.portal.databook.shared.InviteOperationResult; +import org.gcube.portal.databook.shared.InviteStatus; import org.gcube.portal.databook.shared.Like; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; @@ -24,6 +30,8 @@ import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException; import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException; +import org.gcube.portal.databook.shared.ex.InviteIDNotFoundException; +import org.gcube.portal.databook.shared.ex.InviteStatusNotFoundException; import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException; @@ -44,8 +52,6 @@ import com.netflix.astyanax.query.PreparedIndexExpression; import com.netflix.astyanax.serializers.StringSerializer; /** * @author Massimiliano Assante ISTI-CNR - * @version 1.0 Dec 2012 - * * * This class is used for querying and adding data to Cassandra via Astyanax High Level API * @@ -65,6 +71,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public static final String FEEDS = "Feeds"; public static final String COMMENTS = "Comments"; public static final String LIKES = "Likes"; + public static final String INVITES = "Invites"; public static final String VRE_TIMELINE_FEEDS = "VRETimeline"; public static final String USER_TIMELINE_FEEDS = "USERTimeline"; public static final String APP_TIMELINE_FEEDS = "AppTimeline"; @@ -74,6 +81,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public static final String USER_NOTIFICATIONS_PREFERENCES = "USERNotificationsPreferences"; // preferences for notifications public static final String HASHTAGS_COUNTER = "HashtagsCounter"; // count the hashtags per group and type public static final String HASHTAGGED_FEEDS = "HashtaggedFeeds"; // contains hashtags per type associated with vre and feed + public static final String VRE_INVITES = "VREInvites"; //contains the emails that were invited per VRE + public static final String EMAIL_INVITES = "EMAILInvites"; //contains the list of invitation per email private static ColumnFamily cf_Connections = new ColumnFamily( @@ -111,6 +120,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { LIKES, // Column Family Name StringSerializer.get(), // Key Serializer StringSerializer.get()); // Column Serializer + private static ColumnFamily cf_Invites = new ColumnFamily( + INVITES, // Column Family Name + StringSerializer.get(), // Key Serializer + StringSerializer.get()); // Column Serializer private static ColumnFamily cf_UserLikedFeeds = new ColumnFamily( USER_LIKED_FEEDS, // Column Family Name StringSerializer.get(), // Key Serializer @@ -140,6 +153,15 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { StringSerializer.get(), // Key Serializer StringSerializer.get()); // Column Serializer + private static ColumnFamily cf_VREInvites = new ColumnFamily( + VRE_INVITES, // Column Family Name + StringSerializer.get(), // Key Serializer + StringSerializer.get()); // Column Serializer + protected static ColumnFamily cf_EmailInvites = new ColumnFamily( + EMAIL_INVITES, // Column Family Name + StringSerializer.get(), // Key Serializer + StringSerializer.get()); // Column Serializer + /** @@ -1528,6 +1550,157 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { toReturn = getFeedsByIds(feedIds); return toReturn; } + /* + * + ********************** Invites *********************** + * + */ + /** + * common part to save a feed + * @param feed + * @return the partial mutation batch instance + */ + private MutationBatch initSaveInvite(Invite invite) { + if (invite == null) + throw new NullArgumentException("Invite instance is null"); + // Inserting data + MutationBatch m = conn.getKeyspace().prepareMutationBatch(); + //an entry in the feed CF + m.withRow(cf_Invites, invite.getKey().toString()) + .putColumn("SenderUserId", invite.getSenderUserId(), null) + .putColumn("Vreid", invite.getVreid(), null) + .putColumn("InvitedEmail", invite.getInvitedEmail(), null) + .putColumn("ControlCode", invite.getControlCode(), null) + .putColumn("Status", invite.getStatus().toString(), null) + .putColumn("Time", invite.getTime().getTime()+"", null) + .putColumn("SenderFullName", invite.getSenderFullName(), null); + return m; + } + + /** + * {@inheritDoc} + */ + @Override + public String isExistingInvite(String vreid, String email) { + OperationResult> result = null; + try { + result = conn.getKeyspace().prepareQuery(cf_EmailInvites) + .getKeySlice(email) + .execute(); + } catch (ConnectionException e) { + e.printStackTrace(); + } + // Iterate rows and their columns + for (Row row : result.getResult()) { + for (Column column : row.getColumns()) { + if (column.getName().compareTo(vreid)==0) + return column.getStringValue(); + } + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public InviteOperationResult saveInvite(Invite invite) throws AddressException, NullArgumentException { + if (invite == null) + throw new NullArgumentException("Invite instance is null"); + String email = invite.getInvitedEmail(); + if (! verifyEmail(email)) + throw new AddressException("Email is not valid ->" + email); + if (invite.getVreid() == null || invite.getVreid().equals("")) + throw new NullArgumentException("VREId is null or empty"); + _log.debug("isExistingInvite? " + invite.getInvitedEmail() + " in " + invite.getVreid()); + 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()) + .putColumn(invite.getKey().toString(), InviteStatus.PENDING.toString(), null); + + //an entry in the EMAIL Invites + m.withRow(cf_EmailInvites, email) + .putColumn(invite.getVreid(), invite.getKey().toString(), null); + boolean result = execute(m); + return result ? InviteOperationResult.SUCCESS : InviteOperationResult.FAILED; + } + /** + * {@inheritDoc} + */ + @Override + public Invite readInvite(String inviteid) throws InviteIDNotFoundException, InviteStatusNotFoundException { + Invite toReturn = new Invite(); + OperationResult> result; + try { + result = conn.getKeyspace().prepareQuery(cf_Invites) + .getKey(inviteid) + .execute(); + + ColumnList columns = result.getResult(); + if (columns.size() == 0) { + throw new InviteStatusNotFoundException("The requested inviteid: " + inviteid + " is not existing"); + } + + toReturn.setKey(inviteid); + toReturn.setSenderUserId(columns.getColumnByName("SenderUserId").getStringValue()); + toReturn.setVreid(columns.getColumnByName("Vreid").getStringValue()); + toReturn.setInvitedEmail(columns.getColumnByName("InvitedEmail").getStringValue()); + toReturn.setControlCode(columns.getColumnByName("ControlCode").getStringValue()); + InviteStatus status = getInviteStatusType(columns.getColumnByName("Status").getStringValue()); + toReturn.setStatus(status); + toReturn.setTime(getDateFromTimeInMillis(columns.getColumnByName("Time").getStringValue())); + toReturn.setSenderFullName(columns.getColumnByName("SenderFullName").getStringValue()); + + } catch (ConnectionException e) { + e.printStackTrace(); + return null; + } + return toReturn; + } + /** + * {@inheritDoc} + * @throws InviteStatusNotFoundException + */ + @Override + public boolean setInviteStatus(String vreid, String email, InviteStatus status) throws InviteIDNotFoundException, InviteStatusNotFoundException { + String inviteid = isExistingInvite(vreid, email); + Invite toSet = readInvite(inviteid); + if (toSet == null) + throw new InviteIDNotFoundException("The specified invite to set with id: " + inviteid + " does not exist"); + + MutationBatch m = conn.getKeyspace().prepareMutationBatch(); + //update in the Invites Static CF + m.withRow(cf_Invites, inviteid).putColumn("Status", status.toString(), null); + //updated in the VREInvites Dynamic CF + m.withRow(cf_VREInvites, toSet.getVreid()).putColumn(inviteid, status.toString(), null); + try { + m.execute(); + } catch (ConnectionException e) { + _log.error("ERROR while setting Invite " + inviteid + " to " + status.toString()); + return false; + } + _log.trace("Invite Status Set to " + status.toString() + " OK"); + return true; + } + /** + * {@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; + } /** * {@inheritDoc} */ @@ -1609,6 +1782,26 @@ 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 . + * @return correct enum representing the feed type + * @throws TypeNotFoundException . + */ + private InviteStatus getInviteStatusType(String type) throws InviteStatusNotFoundException { + if (type.compareTo("PENDING") == 0) { + return InviteStatus.PENDING; + } + else if (type.compareTo("ACCEPTED") == 0) { + return InviteStatus.ACCEPTED; + } + else if (type.compareTo("REJECTED") == 0) { + return InviteStatus.REJECTED; + } + else + throw new InviteStatusNotFoundException("The Invite Status was not recognized should be one of " + InviteStatus.values() + " asked for: " + type); + } /** * simply return an enum representing the feed type @@ -1835,7 +2028,24 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { _log.debug("Hashtag Count update OK to: " + newCount); return true; } - + /** + * verify an email address + * @param email + * @return true or false + */ + private boolean verifyEmail(String email) { + boolean isValid = false; + try { + InternetAddress internetAddress = new InternetAddress(email); + internetAddress.validate(); + isValid = true; + } catch (AddressException e) { + _log.error("Validation Exception Occurred for email: " + email); + } + 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 21bd051..b1a0f00 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java @@ -10,8 +10,13 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import javax.mail.internet.AddressException; + import org.gcube.portal.databook.shared.Feed; import org.gcube.portal.databook.shared.FeedType; +import org.gcube.portal.databook.shared.Invite; +import org.gcube.portal.databook.shared.InviteOperationResult; +import org.gcube.portal.databook.shared.InviteStatus; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.PrivacyLevel; @@ -23,13 +28,16 @@ import org.junit.BeforeClass; import org.junit.Test; import com.google.common.collect.ImmutableMap; +import com.google.gwt.thirdparty.javascript.jscomp.Result; import com.netflix.astyanax.connectionpool.OperationResult; import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; +import com.netflix.astyanax.ddl.ColumnDefinition; import com.netflix.astyanax.ddl.ColumnFamilyDefinition; import com.netflix.astyanax.model.ColumnFamily; import com.netflix.astyanax.model.Row; import com.netflix.astyanax.model.Rows; import com.netflix.astyanax.serializers.StringSerializer; +import com.netflix.astyanax.thrift.ddl.ThriftColumnDefinitionImpl; import com.netflix.astyanax.thrift.ddl.ThriftColumnFamilyDefinitionImpl; public class DatabookCassandraTest { @@ -45,74 +53,117 @@ public class DatabookCassandraTest { store.closeConnection(); System.out.println("End"); } - - + @Test - public void testHashTag() { - try { - final String VREID = "/gcube/devsec/devVRE"; - final String HASHTAG1 = "#testHashTag"; - final String HASHTAG2 = "#testHashTag3"; - List hashtags = new LinkedList(); - hashtags.add(HASHTAG1); - hashtags.add(HASHTAG2); - -// Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, "massimiliano.assante", new Date(), VREID, -// "www.d4science.org/monitor", "thumbUri", "This is a feed with " + HASHTAG1 + " and " + HASHTAG2, PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host"); -// assertTrue(store.saveUserFeed(feed)); -// assertTrue(store.saveHashTags(feed.getKey(), VREID, hashtags)); -// assertTrue(store.deleteHashTags("d0c64e42-9616-4e24-a65a-7a63a280d676", VREID, hashtags)); -// System.out.println(feed); -// - System.out.println("\ngetting getVREHashtagsWithOccurrence for " + VREID); - Map hashtagsWithOcc = store.getVREHashtagsWithOccurrence(VREID); - for (String hashtag : hashtagsWithOcc.keySet()) { - System.out.println(hashtag + ":" + hashtagsWithOcc.get(hashtag)); - } - - System.out.println("\ngetting getVREFeedsByHashtag for " + VREID + " and " + HASHTAG1); - for (Feed theFeed : store.getVREFeedsByHashtag(VREID, HASHTAG1)) { - System.out.println(theFeed); - } - + 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"); + 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)); } catch (Exception e) { e.printStackTrace(); } - - + } -// /** -// * use exclusively to add a new (Dynamic) CF to a keyspace -// */ -// @Test -// public void addHashtagsColumnFamilies() { -// ColumnFamily cf_HashtagsCounter = new ColumnFamily( -// DBCassandraAstyanaxImpl.HASHTAGS_COUNTER, // Column Family Name -// StringSerializer.get(), // Key Serializer -// StringSerializer.get()); // Column Serializer -// ColumnFamily cf_HashtagTimeline = new ColumnFamily( -// DBCassandraAstyanaxImpl.HASHTAGGED_FEEDS, // Column Family Name -// StringSerializer.get(), // Key Serializer -// StringSerializer.get()); // Column Serializer -// -// try { -// new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_HashtagsCounter, ImmutableMap.builder() -// .put("default_validation_class", "UTF8Type") -// .put("key_validation_class", "UTF8Type") -// .put("comparator_type", "UTF8Type") -// .build()); -// -// new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_HashtagTimeline, ImmutableMap.builder() -// .put("default_validation_class", "UTF8Type") -// .put("key_validation_class", "UTF8Type") -// .put("comparator_type", "UTF8Type") -// .build()); -// -// } catch (ConnectionException e) { -// e.printStackTrace(); -// } -// } - + + // @Test + // public void testHashTag() { + // try { + // final String VREID = "/gcube/devsec/devVRE"; + // final String HASHTAG1 = "#testHashTag"; + // final String HASHTAG2 = "#testHashTag3"; + // List hashtags = new LinkedList(); + // hashtags.add(HASHTAG1); + // hashtags.add(HASHTAG2); + // + //// Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, "massimiliano.assante", new Date(), VREID, + //// "www.d4science.org/monitor", "thumbUri", "This is a feed with " + HASHTAG1 + " and " + HASHTAG2, PrivacyLevel.VRES, "Massimiliano Assante", "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host"); + //// assertTrue(store.saveUserFeed(feed)); + //// assertTrue(store.saveHashTags(feed.getKey(), VREID, hashtags)); + //// assertTrue(store.deleteHashTags("d0c64e42-9616-4e24-a65a-7a63a280d676", VREID, hashtags)); + //// System.out.println(feed); + //// + // System.out.println("\ngetting getVREHashtagsWithOccurrence for " + VREID); + // Map hashtagsWithOcc = store.getVREHashtagsWithOccurrence(VREID); + // for (String hashtag : hashtagsWithOcc.keySet()) { + // System.out.println(hashtag + ":" + hashtagsWithOcc.get(hashtag)); + // } + // + // System.out.println("\ngetting getVREFeedsByHashtag for " + VREID + " and " + HASHTAG1); + // for (Feed theFeed : store.getVREFeedsByHashtag(VREID, HASHTAG1)) { + // System.out.println(theFeed); + // } + // + // } catch (Exception e) { + // e.printStackTrace(); + // } + // + // + // } + + + // /** + // * use exclusively to add a new (Static) CF to a keyspace + // */ + // @Test + // public void addInvitesStaticColumnFamilies() { + // ColumnFamily CF_INVITES = ColumnFamily.newColumnFamily(DBCassandraAstyanaxImpl.INVITES, StringSerializer.get(), StringSerializer.get()); + // + // try { + // new CassandraClusterConnection(false).getKeyspace().createColumnFamily(CF_INVITES, ImmutableMap.builder() + // .put("default_validation_class", "UTF8Type") + // .put("key_validation_class", "UTF8Type") + // .put("comparator_type", "UTF8Type") + // .build()); + // + // } catch (ConnectionException e) { + // e.printStackTrace(); + // } + // System.out.println("addInvitesStaticColumnFamily END"); + // } + + + // /** + // * use exclusively to add a new (Dynamic) CF to a keyspace + // */ + // @Test + // public void addInvitesDynamicColumnFamilies() { + // System.out.println("addInvitesColumnFamilies"); + // ColumnFamily cf_HashtagsCounter = new ColumnFamily( + // DBCassandraAstyanaxImpl.VRE_INVITES, // Column Family Name + // StringSerializer.get(), // Key Serializer + // StringSerializer.get()); // Column Serializer + // ColumnFamily cf_HashtagTimeline = new ColumnFamily( + // DBCassandraAstyanaxImpl.EMAIL_INVITES, // Column Family Name + // StringSerializer.get(), // Key Serializer + // StringSerializer.get()); // Column Serializer + // + // try { + // new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_HashtagsCounter, ImmutableMap.builder() + // .put("default_validation_class", "UTF8Type") + // .put("key_validation_class", "UTF8Type") + // .put("comparator_type", "UTF8Type") + // .build()); + // + // new CassandraClusterConnection(false).getKeyspace().createColumnFamily(cf_HashtagTimeline, ImmutableMap.builder() + // .put("default_validation_class", "UTF8Type") + // .put("key_validation_class", "UTF8Type") + // .put("comparator_type", "UTF8Type") + // .build()); + // + // } catch (ConnectionException e) { + // e.printStackTrace(); + // } + // System.out.println("addInvitesColumnFamilies END"); + // } + // private List getKeys() { // List toReturn = new ArrayList(); 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 71c3762..e7c5175 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookStore.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookStore.java @@ -3,8 +3,14 @@ package org.gcube.portal.databook.server; import java.util.List; import java.util.Map; +import javax.mail.internet.AddressException; + +import org.apache.commons.lang.NullArgumentException; import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Feed; +import org.gcube.portal.databook.shared.Invite; +import org.gcube.portal.databook.shared.InviteOperationResult; +import org.gcube.portal.databook.shared.InviteStatus; import org.gcube.portal.databook.shared.Like; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; @@ -14,6 +20,8 @@ import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException; import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException; +import org.gcube.portal.databook.shared.ex.InviteIDNotFoundException; +import org.gcube.portal.databook.shared.ex.InviteStatusNotFoundException; import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException; @@ -352,6 +360,38 @@ public interface DatabookStore { * @return all the feeds having the hashtag passed as parameter */ List getVREFeedsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException; + /** + * Save the invite for a given email into a given vre + * @param invite the invite object instanc to save + * @return {@link InviteOperationResult} SUCCESS, FAILED or ALREADY_INVITED (if an invite is sent to en existing email in the same environment more than once) + */ + InviteOperationResult saveInvite(Invite invite) throws AddressException, NullArgumentException; + /** + * + * @param vreid the environment where you want to check the invite + * @param email the email of the invite to check in the environmnet + * @return the InviteId if present, null otherwise + */ + String isExistingInvite(String vreid, String email); + /** + * read an invite from a given id + * @throws InviteIDNotFoundException + * @throws InviteIDNotFoundException + */ + Invite readInvite(String inviteid) throws InviteIDNotFoundException, InviteStatusNotFoundException; + /** + * set the status of an invite, see {@link InviteStatus} + * @throws InviteIDNotFoundException + */ + boolean setInviteStatus(String vreid, String email, InviteStatus status) throws InviteIDNotFoundException, InviteStatusNotFoundException; + /** + * return the list of invites + * @param vreid + * @return + */ + List getAllInvitedEmailsByVRE(String vreid); + + List getPendingInvitedEmailsByVRE(String vreid); /** * close the connection to the underlying database */ diff --git a/src/main/java/org/gcube/portal/databook/shared/Feed.java b/src/main/java/org/gcube/portal/databook/shared/Feed.java index cd13adb..52aaefb 100644 --- a/src/main/java/org/gcube/portal/databook/shared/Feed.java +++ b/src/main/java/org/gcube/portal/databook/shared/Feed.java @@ -6,7 +6,6 @@ import java.util.Date; /** * * @author Massimiliano Assante, ISTI-CNR - * @version 0.1 July 2012 * */ @SuppressWarnings("serial") diff --git a/src/main/java/org/gcube/portal/databook/shared/Invite.java b/src/main/java/org/gcube/portal/databook/shared/Invite.java new file mode 100644 index 0000000..be1548d --- /dev/null +++ b/src/main/java/org/gcube/portal/databook/shared/Invite.java @@ -0,0 +1,144 @@ +package org.gcube.portal.databook.shared; + +import java.io.Serializable; +import java.util.Date; +/** + * + * @author Massimiliano Assante, ISTI-CNR + * + */ +@SuppressWarnings("serial") +public class Invite implements Serializable { + + private String key; + private String senderUserId; + private String vreid; + private String invitedEmail; + private String controlCode; + private InviteStatus status; + private Date time; + private String senderFullName; + + + public Invite() { + super(); + } + + + + + public Invite(String key, String senderUserId, String vreid, + String invitedEmail, String controlCode, InviteStatus status, + Date time, String senderFullName) { + super(); + this.key = key; + this.senderUserId = senderUserId; + this.vreid = vreid; + this.invitedEmail = invitedEmail; + this.controlCode = controlCode; + this.status = status; + this.time = time; + this.senderFullName = senderFullName; + } + + + + + public String getKey() { + return key; + } + + + + + public void setKey(String key) { + this.key = key; + } + + + + + public String getSenderUserId() { + return senderUserId; + } + + + public void setSenderUserId(String senderUserId) { + this.senderUserId = senderUserId; + } + + + public String getVreid() { + return vreid; + } + + + public void setVreid(String vreid) { + this.vreid = vreid; + } + + + public String getInvitedEmail() { + return invitedEmail; + } + + + public void setInvitedEmail(String invitedEmail) { + this.invitedEmail = invitedEmail; + } + + + public String getControlCode() { + return controlCode; + } + + + public void setControlCode(String controlCode) { + this.controlCode = controlCode; + } + + + public InviteStatus getStatus() { + return status; + } + + + public void setStatus(InviteStatus status) { + this.status = status; + } + + + public Date getTime() { + return time; + } + + + public void setTime(Date time) { + this.time = time; + } + + + public String getSenderFullName() { + return senderFullName; + } + + + public void setSenderFullName(String senderFullName) { + this.senderFullName = senderFullName; + } + + + + + @Override + public String toString() { + return "Invite [key=" + key + ", senderUserId=" + senderUserId + + ", vreid=" + vreid + ", invitedEmail=" + invitedEmail + + ", controlCode=" + controlCode + ", status=" + status + + ", time=" + time + ", senderFullName=" + senderFullName + "]"; + } + + + + +} diff --git a/src/main/java/org/gcube/portal/databook/shared/InviteOperationResult.java b/src/main/java/org/gcube/portal/databook/shared/InviteOperationResult.java new file mode 100644 index 0000000..da0327f --- /dev/null +++ b/src/main/java/org/gcube/portal/databook/shared/InviteOperationResult.java @@ -0,0 +1,8 @@ +package org.gcube.portal.databook.shared; + +public enum InviteOperationResult { + SUCCESS, + FAILED, + //If I send an invite the same email in the same environment more than once + ALREADY_INVITED; +} diff --git a/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java b/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java new file mode 100644 index 0000000..b3b5b90 --- /dev/null +++ b/src/main/java/org/gcube/portal/databook/shared/InviteStatus.java @@ -0,0 +1,7 @@ +package org.gcube.portal.databook.shared; + +public enum InviteStatus { + PENDING, + ACCEPTED, + REJECTED; +} diff --git a/src/main/java/org/gcube/portal/databook/shared/ex/InviteIDNotFoundException.java b/src/main/java/org/gcube/portal/databook/shared/ex/InviteIDNotFoundException.java new file mode 100644 index 0000000..a7d5cb0 --- /dev/null +++ b/src/main/java/org/gcube/portal/databook/shared/ex/InviteIDNotFoundException.java @@ -0,0 +1,8 @@ +package org.gcube.portal.databook.shared.ex; + +@SuppressWarnings("serial") +public class InviteIDNotFoundException extends Exception { + public InviteIDNotFoundException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portal/databook/shared/ex/InviteStatusNotFoundException.java b/src/main/java/org/gcube/portal/databook/shared/ex/InviteStatusNotFoundException.java new file mode 100644 index 0000000..5f4f9c2 --- /dev/null +++ b/src/main/java/org/gcube/portal/databook/shared/ex/InviteStatusNotFoundException.java @@ -0,0 +1,8 @@ +package org.gcube.portal.databook.shared.ex; + +@SuppressWarnings("serial") +public class InviteStatusNotFoundException extends Exception { + public InviteStatusNotFoundException(String message) { + super(message); + } +}