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:
parent
cbdaf753d4
commit
c0030bd737
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
<version>1.10.0-SNAPSHOT</version>
|
||||
<version>1.10.1-SNAPSHOT</version>
|
||||
<name>gCube Social Networking Library</name>
|
||||
<description>
|
||||
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
@ -1335,6 +1334,39 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
boolean updateCommentNoResult = updateFeedCommentsCount(toComment, true);
|
||||
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}
|
||||
*/
|
||||
|
|
|
@ -8,9 +8,11 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
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.FeedType;
|
||||
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.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -58,41 +60,41 @@ public class DatabookCassandraTest {
|
|||
// System.err.println("retrieved " + feeds.size() + " and " + numComment + " in " + (end - init) + "ms");
|
||||
// }
|
||||
|
||||
@Test
|
||||
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 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");
|
||||
List<Attachment> toPass = new ArrayList<Attachment>();
|
||||
toPass.add(a1);
|
||||
toPass.add(a2);
|
||||
toPass.add(a3);
|
||||
|
||||
String feedId = UUID.randomUUID().toString();
|
||||
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",
|
||||
"This post has attachments (gattini) ", PrivacyLevel.SINGLE_VRE,
|
||||
"Massimiliano Assante",
|
||||
"massimiliano.assante@isti.cnr.it",
|
||||
"http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg",
|
||||
"Gattino",
|
||||
"linkDesc",
|
||||
"image/jpeg", false);
|
||||
feed.setMultiFileUpload(true);
|
||||
assertTrue(store.saveUserFeed(feed, toPass));
|
||||
System.out.println("Wrote post? ");
|
||||
System.out.println("Feed has the following attachments: ");
|
||||
try {
|
||||
for (Attachment at : store.getAttachmentsByFeedId(feedId)) {
|
||||
System.out.println(at);
|
||||
}
|
||||
} catch (FeedIDNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
// @Test
|
||||
// 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 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");
|
||||
// List<Attachment> toPass = new ArrayList<Attachment>();
|
||||
// toPass.add(a1);
|
||||
// toPass.add(a2);
|
||||
// toPass.add(a3);
|
||||
//
|
||||
// String feedId = UUID.randomUUID().toString();
|
||||
// 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",
|
||||
// "This post has attachments (gattini) ", PrivacyLevel.SINGLE_VRE,
|
||||
// "Massimiliano Assante",
|
||||
// "massimiliano.assante@isti.cnr.it",
|
||||
// "http://www.dailybest.it/wp-content/uploads/2015/10/gattini-nele-ciotole-e1344352237289.jpg",
|
||||
// "Gattino",
|
||||
// "linkDesc",
|
||||
// "image/jpeg", false);
|
||||
// feed.setMultiFileUpload(true);
|
||||
// assertTrue(store.saveUserFeed(feed, toPass));
|
||||
// System.out.println("Wrote post? ");
|
||||
// System.out.println("Feed has the following attachments: ");
|
||||
// try {
|
||||
// for (Attachment at : store.getAttachmentsByFeedId(feedId)) {
|
||||
// System.out.println(at);
|
||||
// }
|
||||
// } catch (FeedIDNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void testHashTag() {
|
||||
|
@ -494,36 +496,41 @@ public class DatabookCassandraTest {
|
|||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void testComments() {
|
||||
// int count = 10;
|
||||
// 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",
|
||||
// "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
|
||||
// assertTrue(store.saveUserFeed(feed));
|
||||
//
|
||||
// Comment toDelete = null;
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// try {
|
||||
// toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela",
|
||||
// new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl");
|
||||
// assertTrue(store.addComment(toDelete));
|
||||
//
|
||||
// } catch (FeedIDNotFoundException e) {
|
||||
// System.out.println("Exception feed id not found");
|
||||
// }
|
||||
// }
|
||||
// System.out.println("GetAllCOmmentsByFeed ");
|
||||
// for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) {
|
||||
// System.out.println(cm.getText());
|
||||
// };
|
||||
//
|
||||
// try {
|
||||
// assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid()));
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Exception feed id not found");
|
||||
// }
|
||||
// }
|
||||
// @Test
|
||||
// public void testComments() {
|
||||
// int count = 10;
|
||||
// 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",
|
||||
// "massimiliano.assante@isti.cnr.it", "thumburl", "linkTitle", "linkDesc", "host", false);
|
||||
// assertTrue(store.saveUserFeed(feed));
|
||||
//
|
||||
// Comment toDelete = null;
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// try {
|
||||
// toDelete = new Comment(UUID.randomUUID().toString(),"leonardo.candela",
|
||||
// new Date(), feed.getKey().toString(), "This comment #"+i, "Leonardo Candela", "thumbUrl");
|
||||
// assertTrue(store.addComment(toDelete));
|
||||
//
|
||||
// } catch (FeedIDNotFoundException e) {
|
||||
// System.out.println("Exception feed id not found");
|
||||
// }
|
||||
// }
|
||||
// System.out.println("GetAllCOmmentsByFeed ");
|
||||
// for (Comment cm : store.getAllCommentByFeed(feed.getKey().toString())) {
|
||||
// try {
|
||||
// System.out.println(store.readCommentById(cm.getKey()));
|
||||
// } catch (CommentIDNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// try {
|
||||
// assertTrue(store.deleteComment(toDelete.getKey(), toDelete.getFeedid()));
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Exception feed id not found");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -286,7 +286,13 @@ public interface DatabookStore {
|
|||
* @throws NotificationChannelTypeNotFoundException self explaining
|
||||
*/
|
||||
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
|
||||
* @param comment the Comment instance to add
|
||||
|
|
Loading…
Reference in New Issue