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
This commit is contained in:
Massimiliano Assante 2014-10-01 15:27:03 +00:00
parent fdcd091f84
commit 4991c1fe99
3 changed files with 35 additions and 2 deletions

View File

@ -1424,6 +1424,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
return toReturn; return toReturn;
} }
/*
*
********************** HASHTAGS ***********************
*
*/
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1436,7 +1441,25 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean firstInsert = execute(m); boolean firstInsert = execute(m);
boolean secondInsert = updateVREHashtagCount(vreid, hashtag, true); boolean secondInsert = updateVREHashtagCount(vreid, hashtag, true);
if (! (firstInsert && secondInsert)) { 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<String> 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; return false;
} }
} }

View File

@ -55,12 +55,13 @@ public class DatabookCassandraTest {
final String HASHTAG2 = "#yetAnotherHashTag"; final String HASHTAG2 = "#yetAnotherHashTag";
List<String> hashtags = new LinkedList<String>(); List<String> hashtags = new LinkedList<String>();
hashtags.add(HASHTAG1); hashtags.add(HASHTAG1);
hashtags.add(HASHTAG2); //hashtags.add(HASHTAG2);
Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, "massimiliano.assante", new Date(), VREID, 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"); "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.saveUserFeed(feed));
assertTrue(store.saveHashTags(feed.getKey(), VREID, hashtags)); assertTrue(store.saveHashTags(feed.getKey(), VREID, hashtags));
//assertTrue(store.deleteHashTags("d0c64e42-9616-4e24-a65a-7a63a280d676", VREID, hashtags));
System.out.println(feed); System.out.println(feed);
System.out.println("\ngetting getVREHashtagsWithOccurrence for " + VREID); System.out.println("\ngetting getVREHashtagsWithOccurrence for " + VREID);

View File

@ -325,6 +325,15 @@ public interface DatabookStore {
* @throws FeedIDNotFoundException * @throws FeedIDNotFoundException
*/ */
boolean saveHashTags(String feedid, String vreid, List<String> hashtags) throws FeedIDNotFoundException; boolean saveHashTags(String feedid, String vreid, List<String> 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<String> 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 * 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) * @param vreid vre identifier (scope)