Changed method for edited comments
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@121770 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
484d110012
commit
6b6d41cd3e
|
@ -614,6 +614,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public List<Feed> getAllPortalPrivacyLevelFeeds() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException {
|
||||
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
||||
|
@ -1268,8 +1269,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
.putColumn("Userid", comment.getUserid(), null)
|
||||
.putColumn("Feedid",comment.getFeedid(), null)
|
||||
.putColumn("FullName",comment.getFullName(), null)
|
||||
.putColumn("ThumbnailURL", comment.getThumbnailURL(), null);
|
||||
|
||||
.putColumn("ThumbnailURL", comment.getThumbnailURL(), null)
|
||||
.putColumn("IsEdited", comment.isEdit(), null);
|
||||
|
||||
try {
|
||||
m.execute();
|
||||
|
@ -1285,7 +1286,6 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Comment> getAllCommentByFeed(String feedid) {
|
||||
List<Comment> toReturn = new ArrayList<Comment>();
|
||||
|
||||
|
@ -1315,6 +1315,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
toAdd.setThumbnailURL(col.getStringValue());
|
||||
else if (col.getName().compareTo("Feedid") == 0)
|
||||
toAdd.setFeedid(col.getStringValue());
|
||||
else if(col.getName().compareTo("IsEdited") == 0)
|
||||
toAdd.setEdit(col.getBooleanValue());
|
||||
else if(col.getName().compareTo("LastEditTime") == 0)
|
||||
toAdd.setLastEditTime(getDateFromTimeInMillis(col.getStringValue()));
|
||||
else {
|
||||
_log.error("getAllCommentByFeed(): Could not assign variable to this Comment for column name: " + col.getName());
|
||||
}
|
||||
|
@ -1327,6 +1331,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -1335,7 +1340,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
MutationBatch m = conn.getKeyspace().prepareMutationBatch();
|
||||
//an entry in the feed CF
|
||||
m.withRow(cf_Comments, comment2Edit.getKey().toString()).putColumn("Text", comment2Edit.getText(), null);
|
||||
m.withRow(cf_Comments, comment2Edit.getKey().toString()).putColumn("Timestamp", comment2Edit.getTime().getTime()+"", null);
|
||||
m.withRow(cf_Comments, comment2Edit.getKey().toString()).putColumn("IsEdited", comment2Edit.isEdit(), null);
|
||||
m.withRow(cf_Comments, comment2Edit.getKey().toString()).putColumn("LastEditTime", comment2Edit.getLastEditTime().getTime() + "", null);
|
||||
try {
|
||||
m.execute();
|
||||
} catch (ConnectionException e) {
|
||||
|
@ -1345,6 +1351,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
_log.info("Comments update OK to: " + comment2Edit.getText());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package org.gcube.portal.databook.server;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -24,12 +29,29 @@ public class DatabookCassandraTest {
|
|||
@Test
|
||||
public void testFeedNumberPerUser() {
|
||||
String userid = "massimiliano.assante";
|
||||
//String userid = "costantino.perciante";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.YEAR, -1);
|
||||
Date now = new Date();
|
||||
System.out.println(store.getRecentFeedsByUserAndDate(userid, cal.getTimeInMillis()).size());
|
||||
System.out.println(new Date().getTime() - now.getTime()+"ms");
|
||||
|
||||
List<Feed> feeds = null;
|
||||
int numComment = 0;
|
||||
long init = System.currentTimeMillis();
|
||||
try {
|
||||
feeds = store.getAllFeedsByUser(userid);
|
||||
|
||||
for (Feed feed : feeds) {
|
||||
List<Comment> comments = store.getAllCommentByFeed(feed.getKey());
|
||||
|
||||
|
||||
for (Comment comment : comments) {
|
||||
numComment ++;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PrivacyLevelTypeNotFoundException | FeedTypeNotFoundException
|
||||
| ColumnNameNotFoundException | FeedIDNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.err.println("retrieved " + feeds.size() + " and " + numComment + " in " + (end - init) + "ms");
|
||||
}
|
||||
|
||||
// @Test
|
||||
|
|
|
@ -19,6 +19,9 @@ public class Comment implements Serializable, Comparable<Comment> {
|
|||
private String text;
|
||||
private String fullName;
|
||||
private String thumbnailURL;
|
||||
private boolean isEdit; // false default
|
||||
private Date lastEditTime; // null default
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -45,7 +48,37 @@ public class Comment implements Serializable, Comparable<Comment> {
|
|||
this.text = text;
|
||||
this.fullName = fullName;
|
||||
this.thumbnailURL = thumbnailURL;
|
||||
this.isEdit = false;
|
||||
this.lastEditTime = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for edited comment
|
||||
* @param key
|
||||
* @param userid
|
||||
* @param time
|
||||
* @param feedid
|
||||
* @param text
|
||||
* @param fullName
|
||||
* @param thumbnailURL
|
||||
* @param isEdit
|
||||
* @param editDate
|
||||
*/
|
||||
public Comment(String key, String userid, Date time, String feedid,
|
||||
String text, String fullName, String thumbnailURL, boolean isEdit, Date editDate) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.userid = userid;
|
||||
this.time = time;
|
||||
this.feedid = feedid;
|
||||
this.text = text;
|
||||
this.fullName = fullName;
|
||||
this.thumbnailURL = thumbnailURL;
|
||||
this.isEdit = isEdit;
|
||||
this.lastEditTime = editDate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the text
|
||||
|
@ -112,6 +145,18 @@ public class Comment implements Serializable, Comparable<Comment> {
|
|||
this.thumbnailURL = thumbnailURL;
|
||||
}
|
||||
|
||||
public boolean isEdit() {
|
||||
return isEdit;
|
||||
}
|
||||
public void setEdit(boolean isEdit) {
|
||||
this.isEdit = isEdit;
|
||||
}
|
||||
public Date getLastEditTime() {
|
||||
return lastEditTime;
|
||||
}
|
||||
public void setLastEditTime(Date lastEditTime) {
|
||||
this.lastEditTime = lastEditTime;
|
||||
}
|
||||
public int compareTo(Comment toCompare) {
|
||||
if (this.time.after(toCompare.getTime()))
|
||||
return 1;
|
||||
|
@ -119,4 +164,12 @@ public class Comment implements Serializable, Comparable<Comment> {
|
|||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Comment [key=" + key + ", userid=" + userid + ", time=" + time
|
||||
+ ", feedid=" + feedid + ", text=" + text + ", fullName="
|
||||
+ fullName + ", thumbnailURL=" + thumbnailURL + ", isEdit="
|
||||
+ isEdit + ", lastEditTime=" + lastEditTime + "]";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue