From 4991c1fe995991388091f35f6eb1cbc58c782350 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 1 Oct 2014 15:27:03 +0000 Subject: [PATCH] added hashtag support, ready for test git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@100333 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/DBCassandraAstyanaxImpl.java | 25 ++++++++++++++++++- .../server/DatabookCassandraTest.java | 3 ++- .../portal/databook/server/DatabookStore.java | 9 +++++++ 3 files changed, 35 insertions(+), 2 deletions(-) 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 7a0266a..b1b9325 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -1424,6 +1424,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } return toReturn; } + /* + * + ********************** HASHTAGS *********************** + * + */ /** * {@inheritDoc} */ @@ -1436,7 +1441,25 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { boolean firstInsert = execute(m); boolean secondInsert = updateVREHashtagCount(vreid, hashtag, true); if (! (firstInsert && secondInsert)) { - _log.error("saveHashTag: Could not save the hashtag(s)"); + _log.error("saveHashTags: Could not save the hashtag(s)"); + return false; + } + } + return true; + } + /** + * {@inheritDoc} + */ + @Override + public boolean deleteHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException { + // Inserting data + MutationBatch m = conn.getKeyspace().prepareMutationBatch(); + for (String hashtag : hashtags) { + m.withRow(cf_HashtagTimeline, hashtag).deleteColumn(feedid); + boolean firstDelete = execute(m); + boolean secondInsert = updateVREHashtagCount(vreid, hashtag, false); + if (! (firstDelete && secondInsert)) { + _log.error("deleteHashTags: Could not delete the hashtag(s)"); return false; } } 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 096b076..af3e6a0 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java @@ -55,12 +55,13 @@ public class DatabookCassandraTest { final String HASHTAG2 = "#yetAnotherHashTag"; List hashtags = new LinkedList(); hashtags.add(HASHTAG1); - hashtags.add(HASHTAG2); + //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); 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 14b9ff3..cde7051 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookStore.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookStore.java @@ -325,6 +325,15 @@ public interface DatabookStore { * @throws FeedIDNotFoundException */ boolean saveHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException; + /** + * + * @param hashtags the hashtag including the '#' + * @param feedid the feedid to which the hashtag is associated + * @param vreid VRE identifier + * @return true if success, false otherwise + * @throws FeedIDNotFoundException + */ + boolean deleteHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException; /** * get a map of vre hashtags where the key is the hashtag and the value is the occurrence of the hashtag in the VRE * @param vreid vre identifier (scope)