added the ability to check if a like is alredy present

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@117281 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2015-07-16 14:27:33 +00:00
parent d921f5b282
commit d8948a8580
1 changed files with 53 additions and 19 deletions

View File

@ -520,6 +520,34 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
return toReturn;
}
/**
* helper method that return whether the user
* @param userid user identifier
* @param feedid the feed identifier
* @return true if the feed id liked already
*/
private boolean isFeedLiked(String userid, String feedid) {
OperationResult<Rows<String, String>> result = null;
try {
result = conn.getKeyspace().prepareQuery(cf_UserLikedFeeds)
.getKeySlice(userid)
.execute();
} catch (ConnectionException e) {
e.printStackTrace();
}
// Iterate rows and their columns looking for the feeid id
for (Row<String, String> row : result.getResult()) {
for (Column<String> column : row.getColumns()) {
if (column.getStringValue().compareTo(feedid)==0)
return true;
}
}
return false;
}
/**
* helper method that retrieve all the feed Ids belonging to an application
* @param appid application identifier
@ -1309,6 +1337,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
return false;
}
if (isFeedLiked(like.getUserid(), feedId)) {
_log.info("User " + like.getUserid() + " already liked Feed " + feedId);
return true;
}
else {
// Inserting data
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
//an entry in the feed CF
@ -1329,6 +1362,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
return updateFeedLikesCount(toLike, true);
}
}
/**
* {@inheritDoc}
*/