|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|