added code for support of hashtags in comments

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@148718 82a268e6-3cf1-43bd-a215-b396298e98cf
feature/23194
Costantino Perciante 7 years ago
parent ca2814c7d3
commit 00622a0dc8

Binary file not shown.

@ -1,8 +1,12 @@
<ReleaseNotes>
<Changeset component="org.gcube.portal.social-networking-library.1-16-0"
date="2017-05-25">
<Change>Added support for hashtags in comments</Change>
</Changeset>
<Changeset component="org.gcube.portal.social-networking-library.1-15-0"
date="2017-01-25">
<Change>Added support for job completion notifications</Change>
<Change>Improved exceptions handling</Change>
<Change>Improved exceptions handling</Change>
</Changeset>
<Changeset component="org.gcube.portal.social-networking-library.1-14-0"
date="2016-09-29">

@ -10,7 +10,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<version>1.15.0-SNAPSHOT</version>
<version>1.16.0-SNAPSHOT</version>
<name>gCube Social Networking Library</name>
<description>
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.

@ -271,6 +271,7 @@ public class CassandraClusterConnection {
ColumnFamilyDefinition cfDefVREInvitesTimeline = getDynamicCFDef(DBCassandraAstyanaxImpl.VRE_INVITES);
ColumnFamilyDefinition cfDefHashtagsCounter = getDynamicCFDef(DBCassandraAstyanaxImpl.HASHTAGS_COUNTER);
ColumnFamilyDefinition cfDefHashtagTimeline = getDynamicCFDef(DBCassandraAstyanaxImpl.HASHTAGGED_FEEDS);
ColumnFamilyDefinition cfDefHashtagCommentsTimeline = getDynamicCFDef(DBCassandraAstyanaxImpl.HASHTAGGED_COMMENTS);
ksDef.setName(keyspaceName)
@ -294,7 +295,8 @@ public class CassandraClusterConnection {
.addColumnFamily(cfDefEmailInvitesTimeline)
.addColumnFamily(cfDefVREInvitesTimeline)
.addColumnFamily(cfDefHashtagsCounter)
.addColumnFamily(cfDefHashtagTimeline);
.addColumnFamily(cfDefHashtagTimeline)
.addColumnFamily(cfDefHashtagCommentsTimeline);
cluster.addKeyspace(ksDef);
}

@ -85,6 +85,7 @@ 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 HASHTAGGED_COMMENTS = "HashtaggedComments"; // contains hashtags per type associated with vre and comment
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
public static final String ATTACHMENTS = "Attachments"; //contains the list of all the attachments in a feed
@ -154,11 +155,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
HASHTAGS_COUNTER, // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer
protected static ColumnFamily<String, String> cf_HashtagTimeline = new ColumnFamily<String, String>(
protected static ColumnFamily<String, String> cf_HashtagTimelineFeed = new ColumnFamily<String, String>(
HASHTAGGED_FEEDS, // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer
protected static ColumnFamily<String, String> cf_HashtagTimelineComment = new ColumnFamily<String, String>(
HASHTAGGED_COMMENTS, // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer
private static ColumnFamily<String, String> cf_VREInvites = new ColumnFamily<String, String>(
VRE_INVITES, // Column Family Name
StringSerializer.get(), // Key Serializer
@ -1833,7 +1837,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase();
m.withRow(cf_HashtagTimeline, lowerCaseHashtag).putColumn(feedid, vreid, null);
m.withRow(cf_HashtagTimelineFeed, lowerCaseHashtag).putColumn(feedid, vreid, null);
boolean firstInsert = execute(m);
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
if (! (firstInsert && secondInsert)) {
@ -1856,7 +1860,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase();
m.withRow(cf_HashtagTimeline, lowerCaseHashtag).deleteColumn(feedid);
m.withRow(cf_HashtagTimelineFeed, lowerCaseHashtag).deleteColumn(feedid);
boolean firstDelete = execute(m);
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
if (! (firstDelete && secondInsert)) {
@ -1870,6 +1874,59 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc}
*/
@Override
public boolean saveHashTagsComment(String commentId, String vreid, List<String> hashtags) throws CommentIDNotFoundException {
Set<String> noduplicatesHashtags = null;
if (hashtags != null && !hashtags.isEmpty()) {
noduplicatesHashtags = new HashSet<String>(hashtags);
}
// Inserting datacommentIdcommentId
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase();
m.withRow(cf_HashtagTimelineComment, lowerCaseHashtag).putColumn(commentId, vreid, null);
boolean firstInsert = execute(m);
boolean secondInsert = false;
if(firstInsert)
secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
if (! (firstInsert && secondInsert)) {
_log.error("saveHashTags: Could not save the hashtag(s)");
return false;
}
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteHashTagsComment(String commentId, String vreid, List<String> hashtags) throws CommentIDNotFoundException {
Set<String> noduplicatesHashtags = null;
if (hashtags != null && !hashtags.isEmpty()) {
noduplicatesHashtags = new HashSet<String>(hashtags);
}
// Inserting data
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase();
m.withRow(cf_HashtagTimelineComment, lowerCaseHashtag).deleteColumn(commentId);
boolean firstDelete = execute(m);
if(firstDelete){
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
if (!(firstDelete && secondInsert)) {
_log.error("deleteHashTags: Could not delete the hashtag(s)");
return false;
}
}else{
_log.error("deleteHashTags: Could not delete the hashtag(s)");
return false;
}
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, Integer> getVREHashtagsWithOccurrence(String vreid) {
OperationResult<Rows<String, String>> result = null;
try {
@ -1951,23 +2008,44 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
public List<Feed> getVREFeedsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
List<Feed> toReturn = new ArrayList<Feed>();
OperationResult<Rows<String, String>> result = null;
OperationResult<Rows<String, String>> resultFeed = null;
OperationResult<Rows<String, String>> resultComment = null;
try {
result = conn.getKeyspace().prepareQuery(cf_HashtagTimeline)
resultFeed = conn.getKeyspace().prepareQuery(cf_HashtagTimelineFeed)
.getKeySlice(hashtag)
.execute();
} catch (ConnectionException e) {
e.printStackTrace();
}
ArrayList<String> feedIds = new ArrayList<String>();
// Iterate rows and their columns
for (Row<String, String> row : result.getResult()) {
}
try {
resultComment = conn.getKeyspace().prepareQuery(cf_HashtagTimelineComment)
.getKeySlice(hashtag)
.execute();
} catch (ConnectionException e) {
e.printStackTrace();
}
Set<String> feedIds = new HashSet<String>();
// Iterate rows and their columns (feed)
for (Row<String, String> row : resultFeed.getResult()) {
for (Column<String> column : row.getColumns()) {
if (column.getStringValue().compareTo(vreid)==0)
feedIds.add(column.getName());
}
}
toReturn = getFeedsByIds(feedIds);
// Iterate rows and their columns (comments)
for (Row<String, String> row : resultComment.getResult()) {
for (Column<String> column : row.getColumns()) {
if (column.getStringValue().compareTo(vreid)==0){
try {
Comment c = readCommentById(column.getName());
feedIds.add(c.getFeedid());
} catch (CommentIDNotFoundException e) {
_log.warn("Failed to fetch comment with id " + column.getName(), e);
}
}
}
}
toReturn = getFeedsByIds(new ArrayList<String>(feedIds));
return toReturn;
}
/*

@ -372,6 +372,15 @@ public interface DatabookStore {
* @throws FeedIDNotFoundException
*/
boolean saveHashTags(String feedid, String vreid, List<String> hashtags) throws FeedIDNotFoundException;
/**
*
* @param hashtags the hashtag including the '#'
* @param commentId the commentId to which the hashtag is associated
* @param vreid VRE identifier
* @return true if success, false otherwise
* @throws CommentIDNotFoundException
*/
boolean saveHashTagsComment(String commentId, String vreid, List<String> hashtags) throws CommentIDNotFoundException;
/**
*
* @param hashtags the hashtag including the '#'
@ -381,6 +390,15 @@ public interface DatabookStore {
* @throws FeedIDNotFoundException
*/
boolean deleteHashTags(String feedid, String vreid, List<String> hashtags) throws FeedIDNotFoundException;
/**
*
* @param hashtags the hashtag including the '#'
* @param commentId the commentId to which the hashtag is associated
* @param vreid VRE identifier
* @return true if success, false otherwise
* @throws CommentIDNotFoundException
*/
boolean deleteHashTagsComment(String commentId, String vreid, List<String> hashtags) throws CommentIDNotFoundException;
/**
* 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)

Loading…
Cancel
Save