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:
parent
d921f5b282
commit
d8948a8580
|
@ -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,25 +1337,31 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
// Inserting data
|
||||
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
|
||||
//an entry in the feed CF
|
||||
m.withRow(cf_Likes, like.getKey().toString())
|
||||
.putColumn("Timestamp", like.getTime().getTime()+"", null)
|
||||
.putColumn("Userid", like.getUserid(), null)
|
||||
.putColumn("Feedid",like.getFeedid(), null)
|
||||
.putColumn("FullName",like.getFullName(), null)
|
||||
.putColumn("ThumbnailURL", like.getThumbnailURL(), null);
|
||||
//and an entry in the UserLikesCF
|
||||
m.withRow(cf_UserLikedFeeds, like.getUserid()).putColumn(like.getKey(), like.getFeedid(), null);
|
||||
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
|
||||
m.withRow(cf_Likes, like.getKey().toString())
|
||||
.putColumn("Timestamp", like.getTime().getTime()+"", null)
|
||||
.putColumn("Userid", like.getUserid(), null)
|
||||
.putColumn("Feedid",like.getFeedid(), null)
|
||||
.putColumn("FullName",like.getFullName(), null)
|
||||
.putColumn("ThumbnailURL", like.getThumbnailURL(), null);
|
||||
//and an entry in the UserLikesCF
|
||||
m.withRow(cf_UserLikedFeeds, like.getUserid()).putColumn(like.getKey(), like.getFeedid(), null);
|
||||
|
||||
try {
|
||||
m.execute();
|
||||
} catch (ConnectionException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updateFeedLikesCount(toLike, true);
|
||||
try {
|
||||
m.execute();
|
||||
} catch (ConnectionException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updateFeedLikesCount(toLike, true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -1721,7 +1755,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
if (column.getStringValue().compareTo(status[i].toString())==0)
|
||||
invitesIds.add(column.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue