From 4ec40fb58cd9cd7839ba4cfe2caa67219cbfbe84 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Tue, 28 Nov 2023 19:37:40 +0100 Subject: [PATCH] New social client --- .../server/DBCassandraAstyanaxImpl.java | 139 +++++++----------- 1 file changed, 57 insertions(+), 82 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 20724f1..ccdb58b 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -20,12 +20,7 @@ import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundExcept import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException; import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException; import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException; -import org.gcube.social_networking.social_networking_client_library.CommentClient; -import org.gcube.social_networking.social_networking_client_library.HashTagClient; -import org.gcube.social_networking.social_networking_client_library.InviteClient; -import org.gcube.social_networking.social_networking_client_library.LikeClient; -import org.gcube.social_networking.social_networking_client_library.NotificationClient; -import org.gcube.social_networking.social_networking_client_library.PostClient; +import org.gcube.social_networking.social_networking_client_library.LibClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,12 +35,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { * logger */ private static final Logger _log = LoggerFactory.getLogger(DBCassandraAstyanaxImpl.class); - private static PostClient postClient; - private static NotificationClient notificationClient; - private static HashTagClient hashTagClient; - private static InviteClient inviteClient; - private static CommentClient commentClient; - private static LikeClient likeClient; + private static LibClient libClient; /** @@ -54,12 +44,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ protected DBCassandraAstyanaxImpl(boolean dropSchema) { try { - postClient = new PostClient(); - notificationClient = new NotificationClient(); - hashTagClient = new HashTagClient(); - commentClient = new CommentClient(); - inviteClient = new InviteClient(); - likeClient = new LikeClient(); + libClient = new LibClient(); } catch (Exception e) { throw new RuntimeException(e); } @@ -70,12 +55,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ public DBCassandraAstyanaxImpl() { try { - postClient = new PostClient(); - notificationClient = new NotificationClient(); - hashTagClient = new HashTagClient(); - commentClient = new CommentClient(); - inviteClient = new InviteClient(); - likeClient = new LikeClient(); + libClient = new LibClient(); } catch (Exception e) { throw new RuntimeException(e); } @@ -87,12 +67,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ public DBCassandraAstyanaxImpl(String infrastructureName) { try { - postClient = new PostClient(); - notificationClient = new NotificationClient(); - hashTagClient = new HashTagClient(); - commentClient = new CommentClient(); - inviteClient = new InviteClient(); - likeClient = new LikeClient(); + libClient = new LibClient(); } catch (Exception e) { throw new RuntimeException(e); } @@ -174,7 +149,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveUserPost(Post post) { - return postClient.saveUserPostLib(post); + return libClient.saveUserPostLib(post); } /** * {@inheritDoc} @@ -189,7 +164,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveUserPost(Post post, List attachments) { - return postClient.saveUserPostLib(post, attachments); + return libClient.saveUserPostLib(post, attachments); } /** @@ -205,7 +180,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveAppPost(Post post) { - return postClient.saveAppPostLib(post); + return libClient.saveAppPostLib(post); } /** * {@inheritDoc} @@ -220,7 +195,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveAppPost(Post post, List attachments) { - return postClient.saveAppPostLib(post, attachments); + return libClient.saveAppPostLib(post, attachments); } /** * {@inheritDoc} @@ -235,7 +210,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean savePostToVRETimeline(String postKey, String vreid) throws FeedIDNotFoundException { - return postClient.savePostToVRETimelineLib(postKey, vreid); + return libClient.savePostToVRETimelineLib(postKey, vreid); } /** * {@inheritDoc} @@ -255,7 +230,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public Post readPost(String postid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException { - return postClient.readPostLib(postid); + return libClient.readPostLib(postid); } /** * {@inheritDoc} @@ -282,7 +257,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { if (timeInMillis > now.getTime()) throw new IllegalArgumentException("the timeInMillis must be before today"); - return postClient.getRecentPostsByUserAndDateLib(userid, timeInMillis); + return libClient.getRecentPostsByUserAndDateLib(userid, timeInMillis); } /** * {@inheritDoc} @@ -297,7 +272,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean deletePost(String postid) throws FeedIDNotFoundException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException { - return postClient.deletePostLib(postid); + return libClient.deletePostLib(postid); } /** * {@inheritDoc} @@ -317,7 +292,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllPostsByUser(String userid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return postClient.getAllPostsByUserLib(userid); + return libClient.getAllPostsByUserLib(userid); } /** * {@inheritDoc} @@ -336,7 +311,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllPostsByApp(String appid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return postClient.getAllPostsByAppLib(appid); + return libClient.getAllPostsByAppLib(appid); } /** * {@inheritDoc} @@ -360,7 +335,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getRecentCommentedPostsByUserAndDate(String userid, long timeInMillis) throws Exception { - return postClient.getRecentCommentedPostsByUserAndDateLib(userid, timeInMillis); + return libClient.getRecentCommentedPostsByUserAndDateLib(userid, timeInMillis); } /** * {@inheritDoc} @@ -377,7 +352,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } @Override public List getAllPortalPrivacyLevelPosts() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException { - return postClient.getAllPortalPrivacyLevelPostsLib(); + return libClient.getAllPortalPrivacyLevelPostsLib(); } /** * {@inheritDoc} @@ -394,7 +369,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { } @Override public List getRecentPostsByUser(String userid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return postClient.getRecentPostsByUserLib(userid, quantity); + return libClient.getRecentPostsByUserLib(userid, quantity); } /** * {@inheritDoc} @@ -414,7 +389,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllPostsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return postClient.getAllPostsByVRELib(vreid); + return libClient.getAllPostsByVRELib(vreid); } /** * {@inheritDoc} @@ -435,7 +410,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getRecentPostsByVRE(String vreid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { _log.info("\n\n in getRecentPostsByVRE"); - return postClient.getRecentPostsByVRELib(vreid, quantity); + return libClient.getRecentPostsByVRELib(vreid, quantity); } /** * {@inheritDoc} @@ -456,7 +431,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public RangePosts getRecentPostsByVREAndRange(String vreid, int from, int quantity) throws IllegalArgumentException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException { - return postClient.getRecentPostsByVREAndRangeLib(vreid, from, quantity); + return libClient.getRecentPostsByVREAndRangeLib(vreid, from, quantity); } /* @@ -469,7 +444,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveNotification(Notification n) { - return notificationClient.saveNotificationLib(n); + return libClient.saveNotificationLib(n); } /** @@ -477,14 +452,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public Notification readNotification(String notificationid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.readNotificationLib(notificationid); + return libClient.readNotificationLib(notificationid); } /** * {@inheritDoc} */ @Override public boolean setNotificationRead(String notificationidToSet) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.setNotificationReadLib(notificationidToSet); + return libClient.setNotificationReadLib(notificationidToSet); } /** @@ -492,28 +467,28 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.getAllNotificationByUserLib(userid, limit); + return libClient.getAllNotificationByUserLib(userid, limit); } /** * {@inheritDoc} */ @Override public List getUnreadNotificationsByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException { - return notificationClient.getUnreadNotificationsByUserLib(userid); + return libClient.getUnreadNotificationsByUserLib(userid); } /** * {@inheritDoc} */ @Override public List getRangeNotificationsByUser(String userid,int from, int quantity) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException { - return notificationClient.getRangeNotificationsByUserLib(userid, from, quantity); + return libClient.getRangeNotificationsByUserLib(userid, from, quantity); } /** * {@inheritDoc} */ @Override public boolean setAllNotificationReadByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.setAllNotificationReadByUserLib(userid); + return libClient.setAllNotificationReadByUserLib(userid); } /** @@ -521,14 +496,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean checkUnreadNotifications(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.checkUnreadNotificationsLib(userid); + return libClient.checkUnreadNotificationsLib(userid); } /** * {@inheritDoc} */ @Override public boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException { - return notificationClient.checkUnreadMessagesNotificationsLib(userid); + return libClient.checkUnreadMessagesNotificationsLib(userid); } /* * @@ -540,7 +515,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getUserNotificationChannels(String userid, NotificationType notificationType) throws NotificationChannelTypeNotFoundException, NotificationTypeNotFoundException { - return notificationClient.getUserNotificationChannelsLib(userid, notificationType); + return libClient.getUserNotificationChannelsLib(userid, notificationType); } /** @@ -548,7 +523,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean setUserNotificationPreferences(String userid, Map enabledChannels) { - return notificationClient.setUserNotificationPreferencesLib(userid, enabledChannels); + return libClient.setUserNotificationPreferencesLib(userid, enabledChannels); } /** * {@inheritDoc} @@ -557,7 +532,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public Map getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException { - return notificationClient.getUserNotificationPreferencesLib(userid); + return libClient.getUserNotificationPreferencesLib(userid); } /* * @@ -569,13 +544,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean addComment(Comment comment) throws FeedIDNotFoundException { - return commentClient.addCommentLib(comment)!=null; + return libClient.addCommentLib(comment)!=null; } /** * {@inheritDoc} */ public Comment readCommentById(String commentId) throws CommentIDNotFoundException { - return commentClient.readCommentByIdLib(commentId); + return libClient.readCommentByIdLib(commentId); } /** * {@inheritDoc} @@ -590,7 +565,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllCommentByPost(String postid) { - return commentClient.getAllCommentsByPostIdLib(postid); + return libClient.getAllCommentsByPostIdLib(postid); } /** @@ -601,7 +576,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public List getRecentCommentsByUserAndDate(final String userid, final long timeInMillis) throws Exception { - return commentClient.getRecentCommentsByUserAndDateLib(userid, timeInMillis); + return libClient.getRecentCommentsByUserAndDateLib(userid, timeInMillis); } @@ -610,7 +585,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean editComment(Comment comment2Edit) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, CommentIDNotFoundException, FeedIDNotFoundException { - return commentClient.editCommentLib(comment2Edit)!=null; + return libClient.editCommentLib(comment2Edit)!=null; } /** @@ -618,21 +593,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean deleteComment(String commentid, String feedid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, CommentIDNotFoundException, FeedIDNotFoundException { - return commentClient.deleteCommentLib(commentid, feedid); + return libClient.deleteCommentLib(commentid, feedid); } /** * {@inheritDoc} */ @Override public boolean like(Like like) throws FeedIDNotFoundException { - return likeClient.likeLib(like); + return libClient.likeLib(like); } /** * {@inheritDoc} */ @Override public boolean unlike(String userid, String likeid, String feedid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, LikeIDNotFoundException, FeedIDNotFoundException { - return likeClient.unlikeLib(userid, likeid, feedid); + return libClient.unlikeLib(userid, likeid, feedid); } /** * {@inheritDoc} @@ -647,7 +622,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getAllLikedPostIdsByUser(String userid) { - return likeClient.getAllLikedPostIdsByUserLib(userid); + return libClient.getAllLikedPostIdsByUserLib(userid); } /** * {@inheritDoc} @@ -816,7 +791,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getAllLikesByPost(String postid) { //possible error index - return likeClient.getAllLikesByPostLib(postid); + return libClient.getAllLikesByPostLib(postid); } /* * @@ -828,42 +803,42 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean saveHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException { - return hashTagClient.saveHashTagsLib(feedid, vreid, hashtags); + return libClient.saveHashTagsLib(feedid, vreid, hashtags); } /** * {@inheritDoc} */ @Override public boolean deleteHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException { - return hashTagClient.deleteHashTagsLib(feedid, vreid, hashtags); + return libClient.deleteHashTagsLib(feedid, vreid, hashtags); } /** * {@inheritDoc} */ @Override public boolean saveHashTagsComment(String commentId, String vreid, List hashtags) throws CommentIDNotFoundException { - return hashTagClient.saveHashTagsCommentLib(commentId, vreid, hashtags); + return libClient.saveHashTagsCommentLib(commentId, vreid, hashtags); } /** * {@inheritDoc} */ @Override public boolean deleteHashTagsComment(String commentId, String vreid, List hashtags) throws CommentIDNotFoundException { - return hashTagClient.deleteHashTagsCommentLib(commentId, vreid, hashtags); + return libClient.deleteHashTagsCommentLib(commentId, vreid, hashtags); } /** * {@inheritDoc} */ @Override public Map getVREHashtagsWithOccurrence(String vreid) { - return hashTagClient.getVREHashtagsWithOccurrenceLib(vreid); + return libClient.getVREHashtagsWithOccurrenceLib(vreid); } /** * {@inheritDoc} */ @Override public Map getVREHashtagsWithOccurrenceFilteredByTime(String vreid, long timestamp){ - return hashTagClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(vreid, timestamp); + return libClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(vreid, timestamp); } /** @@ -878,7 +853,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public List getVREPostsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException { - return hashTagClient.getVREPostsByHashtagLib(vreid, hashtag); + return libClient.getVREPostsByHashtagLib(vreid, hashtag); } /* * @@ -892,21 +867,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public String isExistingInvite(String vreid, String email) { - return inviteClient.isExistingInviteLib(vreid, email); + return libClient.isExistingInviteLib(vreid, email); } /** * {@inheritDoc} */ @Override public InviteOperationResult saveInvite(Invite invite) throws AddressException { - return inviteClient.saveInviteLib(invite); + return libClient.saveInviteLib(invite); } /** * {@inheritDoc} */ @Override public Invite readInvite(String inviteid) throws InviteIDNotFoundException, InviteStatusNotFoundException { - return inviteClient.readInviteLib(inviteid); + return libClient.readInviteLib(inviteid); } /** @@ -915,21 +890,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { */ @Override public boolean setInviteStatus(String vreid, String email, InviteStatus status) throws InviteIDNotFoundException, InviteStatusNotFoundException { - return inviteClient.setInviteStatusLib(vreid, email, status); + return libClient.setInviteStatusLib(vreid, email, status); } /** * {@inheritDoc} */ @Override public List getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException{ - return inviteClient.getInvitedEmailsByVRELib(vreid, status); + return libClient.getInvitedEmailsByVRELib(vreid, status); } /** * {@inheritDoc} */ @Override public List getAttachmentsByFeedId(String feedId) throws FeedIDNotFoundException { - return postClient.getAttachmentsByFeedIdLib(feedId); + return libClient.getAttachmentsByFeedIdLib(feedId); } /** * {@inheritDoc} @@ -940,6 +915,6 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { @Override public List getAllVREIds(){ - return postClient.getAllVREIdsLib(); + return libClient.getAllVREIdsLib(); } }