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 c670bea..b4f65ff 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -8,21 +8,7 @@ import java.util.Map; import javax.mail.internet.AddressException; -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.Invite; -import org.gcube.portal.databook.shared.InviteOperationResult; -import org.gcube.portal.databook.shared.InviteStatus; -import org.gcube.portal.databook.shared.Like; -import org.gcube.portal.databook.shared.Notification; -import org.gcube.portal.databook.shared.NotificationChannelType; -import org.gcube.portal.databook.shared.NotificationType; -import org.gcube.portal.databook.shared.Post; -import org.gcube.portal.databook.shared.PostType; -import org.gcube.portal.databook.shared.RangeFeeds; -import org.gcube.portal.databook.shared.RangePosts; +import org.gcube.portal.databook.shared.*; import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException; import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException; import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException; @@ -160,13 +146,28 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { * */ + private static Post feed2post(Feed feed){ + Post post = new Post(feed.getKey(), PostType.valueOf(feed.getType().toString()), feed.getEntityId(), feed.getTime(), + feed.getVreid(), feed.getUri(), feed.getUriThumbnail(), feed.getDescription(), feed.getPrivacy(), + feed.getFullName(), feed.getEmail(), feed.getThumbnailURL(), feed.getCommentsNo(), + feed.getLikesNo(), feed.getLinkTitle(), feed.getLinkDescription(), feed.getLinkHost(), feed.isApplicationFeed(), feed.isMultiFileUpload()); + return post; + } + + private static Feed post2feed(Post post){ + Feed feed = new Feed(post.getKey(), FeedType.valueOf(post.getType().toString()), post.getEntityId(), post.getTime(), + post.getVreid(), post.getUri(), post.getUriThumbnail(), post.getDescription(), post.getPrivacy(), + post.getFullName(), post.getEmail(), post.getThumbnailURL(), post.getCommentsNo(), + post.getLikesNo(), post.getLinkTitle(), post.getLinkDescription(), post.getLinkHost(), post.isApplicationFeed(), post.isMultiFileUpload()); + return feed; + } /** * {@inheritDoc} */ @Deprecated @Override public boolean saveUserFeed(Feed post) { - return true; + return saveUserPost(feed2post(post)); } /** * {@inheritDoc} @@ -181,7 +182,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public boolean saveUserFeed(Feed feed, List attachments) { - return true; + return saveUserPost(feed2post(feed), attachments); } /** * {@inheritDoc} @@ -197,7 +198,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override @Deprecated public boolean saveAppFeed(Feed post) { - return true; + return saveAppPost(feed2post(post)); } /** * {@inheritDoc} @@ -212,7 +213,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public boolean saveAppFeed(Feed feed, List attachments) { - return true; + return saveAppPost(feed2post(feed), attachments); } /** * {@inheritDoc} @@ -227,7 +228,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public boolean saveFeedToVRETimeline(String feedKey, String vreid) throws FeedIDNotFoundException { - return true; + return savePostToVRETimeline(feedKey, vreid); } /** * {@inheritDoc} @@ -245,7 +246,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException { - return null; + return post2feed(readPost(feedid)); } /** * {@inheritDoc} @@ -265,8 +266,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { Date now = new Date(); if (timeInMillis > now.getTime()) throw new IllegalArgumentException("the timeInMillis must be before today"); - - return null; + List posts = getRecentPostsByUserAndDate(userid, timeInMillis); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } /** * {@inheritDoc} @@ -285,7 +290,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public boolean deleteFeed(String feedId) throws FeedIDNotFoundException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException { - return true; + return deletePost(feedId); } /** * {@inheritDoc} @@ -300,7 +305,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public List getAllFeedsByUser(String userid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + List posts = getAllPostsByUser(userid); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } /** * {@inheritDoc} @@ -314,7 +324,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllFeedsByApp(String appid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + List posts = getAllPostsByApp(appid); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } /** * {@inheritDoc} @@ -331,7 +346,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getRecentCommentedFeedsByUserAndDate(String userid, long timeInMillis) throws Exception { - return null; + List posts = getRecentCommentedPostsByUserAndDate(userid, timeInMillis); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } /** * {@inheritDoc} @@ -348,7 +368,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public List getAllPortalPrivacyLevelFeeds() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException { - return null; + List posts = getAllPortalPrivacyLevelPosts(); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } @Override public List getAllPortalPrivacyLevelPosts() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException { @@ -360,7 +385,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override @Deprecated public List getRecentFeedsByUser(String userid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + List posts = getRecentPostsByUser(userid, quantity); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } @Override public List getRecentPostsByUser(String userid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { @@ -372,7 +402,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override @Deprecated public List getAllFeedsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + List posts = getAllPostsByVRE(vreid); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } /** * {@inheritDoc} @@ -387,7 +422,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Deprecated @Override public List getRecentFeedsByVRE(String vreid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + List posts = getRecentPostsByVRE(vreid, quantity); + List feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + return feeds; } @Override public List getRecentPostsByVRE(String vreid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { @@ -398,7 +438,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public RangeFeeds getRecentFeedsByVREAndRange(String vreid, int from, int quantity) throws IllegalArgumentException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return null; + RangePosts rangePosts = getRecentPostsByVREAndRange(vreid, from, quantity); + List posts = rangePosts.getPosts(); + ArrayList feeds = new ArrayList<>(); + for(Post post: posts){ + feeds.add(post2feed(post)); + } + RangeFeeds rangeFeeds = new RangeFeeds(rangePosts.getLastReturnedPostTimelineIndex(), feeds); + return rangeFeeds; } /** * {@inheritDoc}