From 6b6d41cd3e754ca0ec1a774707227bedbcee9350 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 10 Dec 2015 17:38:08 +0000 Subject: [PATCH] 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 --- .../server/DBCassandraAstyanaxImpl.java | 15 ++++-- .../server/DatabookCassandraTest.java | 38 ++++++++++--- .../gcube/portal/databook/shared/Comment.java | 53 +++++++++++++++++++ 3 files changed, 94 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java index 6991ec0..d77aacd 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -614,6 +614,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { /** * {@inheritDoc} */ + @SuppressWarnings("deprecation") @Override public List getAllPortalPrivacyLevelFeeds() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException { ArrayList toReturn = new ArrayList(); @@ -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 getAllCommentByFeed(String feedid) { List toReturn = new ArrayList(); @@ -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} */ diff --git a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java index 33833bc..438b1cc 100644 --- a/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java +++ b/src/main/java/org/gcube/portal/databook/server/DatabookCassandraTest.java @@ -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 feeds = null; + int numComment = 0; + long init = System.currentTimeMillis(); + try { + feeds = store.getAllFeedsByUser(userid); + + for (Feed feed : feeds) { + List 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 diff --git a/src/main/java/org/gcube/portal/databook/shared/Comment.java b/src/main/java/org/gcube/portal/databook/shared/Comment.java index 6cf964e..83bc5ed 100644 --- a/src/main/java/org/gcube/portal/databook/shared/Comment.java +++ b/src/main/java/org/gcube/portal/databook/shared/Comment.java @@ -19,6 +19,9 @@ public class Comment implements Serializable, Comparable { 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 { 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 { 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 { 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 + "]"; + } }