added new method for reading comments by Id

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@122716 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-02-02 10:57:17 +00:00
parent cbdaf753d4
commit c0030bd737
4 changed files with 113 additions and 68 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>
<version>1.10.0-SNAPSHOT</version> <version>1.10.1-SNAPSHOT</version>
<name>gCube Social Networking Library</name> <name>gCube Social Networking Library</name>
<description> <description>
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities. The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import javax.mail.internet.AddressException; import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
@ -1335,6 +1334,39 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean updateCommentNoResult = updateFeedCommentsCount(toComment, true); boolean updateCommentNoResult = updateFeedCommentsCount(toComment, true);
return updateCommentNoResult; return updateCommentNoResult;
} }
/**
* {@inheritDoc}
*/
public Comment readCommentById(String commentId) throws CommentIDNotFoundException {
Comment toReturn = new Comment();
OperationResult<ColumnList<String>> result;
try {
result = conn.getKeyspace().prepareQuery(cf_Comments)
.getKey(commentId)
.execute();
ColumnList<String> columns = result.getResult();
if (columns.size() == 0) {
throw new CommentIDNotFoundException("The requested commentId: " + commentId + " is not existing");
}
toReturn.setKey(commentId);
toReturn.setText(columns.getColumnByName("Text").getStringValue());
toReturn.setFullName(columns.getColumnByName("FullName").getStringValue());
toReturn.setEdit(columns.getColumnByName("IsEdited").getBooleanValue());
toReturn.setFeedid(columns.getColumnByName("Feedid").getStringValue());
toReturn.setUserid(columns.getColumnByName("Userid").getStringValue());
toReturn.setTime(getDateFromTimeInMillis(columns.getColumnByName("Timestamp").getStringValue()));
toReturn.setThumbnailURL(columns.getColumnByName("ThumbnailURL").getStringValue());
if (columns.getColumnByName("LastEditTime") != null)
toReturn.setLastEditTime(getDateFromTimeInMillis(columns.getColumnByName("LastEditTime").getStringValue()));
} catch (ConnectionException e) {
e.printStackTrace();
return null;
}
return toReturn;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -8,9 +8,11 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.gcube.portal.databook.shared.Attachment; import org.gcube.portal.databook.shared.Attachment;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.Feed; import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.PrivacyLevel; import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -58,41 +60,41 @@ public class DatabookCassandraTest {
// System.err.println("retrieved " + feeds.size() + " and " + numComment + " in " + (end - init) + "ms"); // System.err.println("retrieved " + feeds.size() + " and " + numComment + " in " + (end - init) + "ms");
// } // }
@Test // @Test
public void testAttachments() { // public void testAttachments() {
Attachment a1 = new Attachment(UUID.randomUUID().toString(), "www1", "gattino1", "description1", "http://cdn.tuttozampe.com/wp-content/uploads/2010/09/ipoglicemia-gatto.jpg", "image/jpg"); // Attachment a1 = new Attachment(UUID.randomUUID().toString(), "www1", "gattino1", "description1", "http://cdn.tuttozampe.com/wp-content/uploads/2010/09/ipoglicemia-gatto.jpg", "image/jpg");
Attachment a2 = new Attachment(UUID.randomUUID().toString(), "www2", "name2", "description2", "http://www.gcomegatto.it/wp-content/uploads/2015/01/09gatto.jpg","image/jpg"); // Attachment a2 = new Attachment(UUID.randomUUID().toString(), "www2", "name2", "description2", "http://www.gcomegatto.it/wp-content/uploads/2015/01/09gatto.jpg","image/jpg");
Attachment a3 = new Attachment(UUID.randomUUID().toString(), "www3", "name3", "description3", "http://cdn.tuttozampe.com/wp-content/uploads/2010/09/ipoglicemia-gatto.jpg","image/jpg"); // Attachment a3 = new Attachment(UUID.randomUUID().toString(), "www3", "name3", "description3", "http://cdn.tuttozampe.com/wp-content/uploads/2010/09/ipoglicemia-gatto.jpg","image/jpg");
List<Attachment> toPass = new ArrayList<Attachment>(); // List<Attachment> toPass = new ArrayList<Attachment>();
toPass.add(a1); // toPass.add(a1);
toPass.add(a2); // toPass.add(a2);
toPass.add(a3); // toPass.add(a3);
//
String feedId = UUID.randomUUID().toString(); // String feedId = UUID.randomUUID().toString();
Feed feed = new Feed(feedId, FeedType.TWEET, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // Feed feed = new Feed(feedId, FeedType.TWEET, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
"http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg", // "http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg",
"http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg", // "http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg",
"This post has attachments (gattini) ", PrivacyLevel.SINGLE_VRE, // "This post has attachments (gattini) ", PrivacyLevel.SINGLE_VRE,
"Massimiliano Assante", // "Massimiliano Assante",
"massimiliano.assante@isti.cnr.it", // "massimiliano.assante@isti.cnr.it",
"http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg", // "http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg",
"Gattino", // "Gattino",
"linkDesc", // "linkDesc",
"image/jpeg", false); // "image/jpeg", false);
feed.setMultiFileUpload(true); // feed.setMultiFileUpload(true);
assertTrue(store.saveUserFeed(feed, toPass)); // assertTrue(store.saveUserFeed(feed, toPass));
System.out.println("Wrote post? "); // System.out.println("Wrote post? ");
System.out.println("Feed has the following attachments: "); // System.out.println("Feed has the following attachments: ");
try { // try {
for (Attachment at : store.getAttachmentsByFeedId(feedId)) { // for (Attachment at : store.getAttachmentsByFeedId(feedId)) {
System.out.println(at); // System.out.println(at);
} // }
} catch (FeedIDNotFoundException e) { // } catch (FeedIDNotFoundException e) {
// TODO Auto-generated catch block // // TODO Auto-generated catch block
e.printStackTrace(); // e.printStackTrace();
} // }
//
} // }
// @Test // @Test
// public void testHashTag() { // public void testHashTag() {
@ -494,36 +496,41 @@ public class DatabookCassandraTest {
// //
// //
// //
// @Test // @Test
// public void testComments() { // public void testComments() {
// int count = 10; // int count = 10;
// Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE", // Feed feed = new Feed(UUID.randomUUID().toString(), FeedType.SHARE, "massimiliano.assante", new Date(), "/gcube/devsec/devVRE",
// "http://www.d4science.org/monitor", "thumbUri", "This is feed that is going to be commented ", PrivacyLevel.PUBLIC, "Massimiliano Assante", // "http://www.d4science.org/monitor", "thumbUri", "This is feed that is going to be commented ", PrivacyLevel.PUBLIC, "Massimiliano Assante",
// "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false); // "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
// assertTrue(store.saveUserFeed(feed)); // assertTrue(store.saveUserFeed(feed));
// //
// Comment toDelete = null; // Comment toDelete = null;
// for (int i = 0; i < count; i++) { // for (int i = 0; i < count; i++) {
// try { // try {
// toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela", // toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela",
// new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl"); // new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl");
// assertTrue(store.addComment(toDelete)); // assertTrue(store.addComment(toDelete));
// //
// } catch (FeedIDNotFoundException e) { // } catch (FeedIDNotFoundException e) {
// System.out.println("Exception feed id not found"); // System.out.println("Exception feed id not found");
// } // }
// } // }
// System.out.println("GetAllCOmmentsByFeed "); // System.out.println("GetAllCOmmentsByFeed ");
// for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) { // for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) {
// System.out.println(cm.getText()); // try {
// }; // System.out.println(store.readCommentById(cm.getKey()));
// // } catch (CommentIDNotFoundException e) {
// try { // // TODO Auto-generated catch block
// assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid())); // e.printStackTrace();
// } catch (Exception e) { // }
// System.out.println("Exception feed id not found"); // };
// } //
// } // try {
// assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid()));
// } catch (Exception e) {
// System.out.println("Exception feed id not found");
// }
// }
} }

View File

@ -286,7 +286,13 @@ public interface DatabookStore {
* @throws NotificationChannelTypeNotFoundException self explaining * @throws NotificationChannelTypeNotFoundException self explaining
*/ */
Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException; Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException;
/**
* @param commentId comment unique identifier
* @return the comment belonging to the commentId
* @throws CommentIDNotFoundException
*/
Comment readCommentById(String commentId) throws CommentIDNotFoundException;
/** /**
* add a comment to a feed * add a comment to a feed
* @param comment the Comment instance to add * @param comment the Comment instance to add