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
This commit is contained in:
Costantino Perciante 2017-05-16 14:07:37 +00:00
parent ca2814c7d3
commit 00622a0dc8
7 changed files with 116 additions and 14 deletions

0
.gwt/.gwt-log Normal file
View File

Binary file not shown.

View File

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

View File

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

View File

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

View File

@ -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 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 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_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 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 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 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 HASHTAGS_COUNTER, // Column Family Name
StringSerializer.get(), // Key Serializer StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column 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 HASHTAGGED_FEEDS, // Column Family Name
StringSerializer.get(), // Key Serializer StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column 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>( private static ColumnFamily<String, String> cf_VREInvites = new ColumnFamily<String, String>(
VRE_INVITES, // Column Family Name VRE_INVITES, // Column Family Name
StringSerializer.get(), // Key Serializer StringSerializer.get(), // Key Serializer
@ -1833,7 +1837,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
MutationBatch m = conn.getKeyspace().prepareMutationBatch(); MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) { for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase(); 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 firstInsert = execute(m);
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true); boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
if (! (firstInsert && secondInsert)) { if (! (firstInsert && secondInsert)) {
@ -1856,7 +1860,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
MutationBatch m = conn.getKeyspace().prepareMutationBatch(); MutationBatch m = conn.getKeyspace().prepareMutationBatch();
for (String hashtag : noduplicatesHashtags) { for (String hashtag : noduplicatesHashtags) {
String lowerCaseHashtag = hashtag.toLowerCase(); String lowerCaseHashtag = hashtag.toLowerCase();
m.withRow(cf_HashtagTimeline, lowerCaseHashtag).deleteColumn(feedid); m.withRow(cf_HashtagTimelineFeed, lowerCaseHashtag).deleteColumn(feedid);
boolean firstDelete = execute(m); boolean firstDelete = execute(m);
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false); boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
if (! (firstDelete && secondInsert)) { if (! (firstDelete && secondInsert)) {
@ -1870,6 +1874,59 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @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) { public Map<String, Integer> getVREHashtagsWithOccurrence(String vreid) {
OperationResult<Rows<String, String>> result = null; OperationResult<Rows<String, String>> result = null;
try { try {
@ -1951,23 +2008,44 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override @Override
public List<Feed> getVREFeedsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException { public List<Feed> getVREFeedsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
List<Feed> toReturn = new ArrayList<Feed>(); 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 { try {
result = conn.getKeyspace().prepareQuery(cf_HashtagTimeline) resultFeed = conn.getKeyspace().prepareQuery(cf_HashtagTimelineFeed)
.getKeySlice(hashtag) .getKeySlice(hashtag)
.execute(); .execute();
} catch (ConnectionException e) { } catch (ConnectionException e) {
e.printStackTrace(); e.printStackTrace();
} }
ArrayList<String> feedIds = new ArrayList<String>(); try {
// Iterate rows and their columns resultComment = conn.getKeyspace().prepareQuery(cf_HashtagTimelineComment)
for (Row<String, String> row : result.getResult()) { .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()) { for (Column<String> column : row.getColumns()) {
if (column.getStringValue().compareTo(vreid)==0) if (column.getStringValue().compareTo(vreid)==0)
feedIds.add(column.getName()); 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; return toReturn;
} }
/* /*

View File

@ -372,6 +372,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 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 '#' * @param hashtags the hashtag including the '#'
@ -381,6 +390,15 @@ public interface DatabookStore {
* @throws FeedIDNotFoundException * @throws FeedIDNotFoundException
*/ */
boolean deleteHashTags(String feedid, String vreid, List<String> hashtags) 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 * 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)