diff --git a/pom.xml b/pom.xml index af8e667..76deeb1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.social-networking social-service-client - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT social-networking-service-client jar The social networking web service client library diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/CommentClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/CommentClient.java deleted file mode 100644 index fbc85d7..0000000 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/CommentClient.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.gcube.social_networking.social_networking_client_library; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.core.GenericType; - -import org.apache.commons.lang.Validate; -import org.gcube.portal.databook.shared.Comment; -import org.gcube.social_networking.social_networking_client_library.utils.HttpClient; -import org.gcube.social_networking.socialnetworking.model.output.ResponseBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Posts client. - * @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it) - */ -public class CommentClient extends BaseClient{ - - private static final String SUB_SERVICE_PATH = "2/comments/"; - private static Logger logger = LoggerFactory.getLogger(CommentClient.class); - - - public CommentClient() throws Exception { - super(SUB_SERVICE_PATH); - } - - public Boolean addCommentLib(Comment comment){ - Validate.isTrue(comment != null, "Comment to write cannot be null"); - - logger.debug("Request for writing comment"); - String thisMethodSignature = "add-comment-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, comment); - } - public Comment readCommentByIdLib(String commentid){ - Validate.isTrue(commentid != null, "Commentid to read cannot be null"); - - logger.debug("Request for reading commentid"); - String thisMethodSignature = "read-comment-by-id-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentid; - return HttpClient.get(new GenericType>(){}, request); - } - public List getAllCommentsByPostIdLib(String postid){ - Validate.isTrue(postid != null, "Postid to read cannot be null"); - - logger.debug("Request for reading comments of post"); - String thisMethodSignature = "get-comments-by-post-id-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; - return HttpClient.get(new GenericType>>(){}, request); - } - public List getRecentCommentsByUserAndDateLib(final String userid, - final long timeInMillis){ - - Validate.isTrue(userid != null, "username to read cannot be null"); - - logger.debug("Request for reading recent comments of user"); - String thisMethodSignature = "get-recent-comments-by-user-and-date-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?time=" + timeInMillis + "&username=" + userid; - return HttpClient.get(new GenericType>>(){}, request); - } - - public Boolean editCommentLib(Comment comment){ - Validate.isTrue(comment != null, "Comment to write cannot be null"); - - logger.debug("Request for writing comment"); - String thisMethodSignature = "edit-comment-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, comment); - } - - public boolean deleteCommentLib(String commentid, String postid){ - Validate.isTrue(commentid != null, "Comment to write cannot be null"); - - logger.debug("Request for del comment"); - String thisMethodSignature = "delete-comment-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentid + "&postid=" + postid; - return HttpClient.post(new GenericType>(){}, request, postid); - } -} diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/HashTagClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/HashTagClient.java index c836744..dd633e0 100644 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/HashTagClient.java +++ b/src/main/java/org/gcube/social_networking/social_networking_client_library/HashTagClient.java @@ -41,69 +41,4 @@ public class HashTagClient extends BaseClient{ String request = getServiceEndpoint() + thisMethodSignature; return HttpClient.get(new GenericType>>(){}, request); } - - - - - - //library api calls - public boolean saveHashTagsLib(String feedid, String vreid, List hashtags) { - Validate.isTrue(hashtags != null, "hashtags to write cannot be null"); - - logger.debug("Request for saving hashtags"); - String thisMethodSignature = "save-hashtag-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?feedid=" + feedid + "&vreid=" + vreid; - return HttpClient.post(new GenericType>(){}, request, hashtags); - } - - public boolean deleteHashTagsLib(String feedid, String vreid, List hashtags) { - Validate.isTrue(hashtags != null, "hashtags to delete cannot be null"); - - logger.debug("Request for deleting hashtags"); - String thisMethodSignature = "delete-hashtag-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?feedid=" + feedid + "&vreid=" + vreid; - return HttpClient.post(new GenericType>(){}, request, hashtags); - } - - public boolean saveHashTagsCommentLib(String commentId, String vreid, List hashtags){ - Validate.isTrue(hashtags != null, "hashtags to comment cannot be null"); - - logger.debug("Request for saving hashtags comment"); - String thisMethodSignature = "save-hashtag-comment-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentId + "&vreid=" + vreid; - return HttpClient.post(new GenericType>(){}, request, hashtags); - } - - public boolean deleteHashTagsCommentLib(String commentId, String vreid, List hashtags) { - Validate.isTrue(hashtags != null, "hashtags to comment delete cannot be null"); - - logger.debug("Request for deleting hashtags comment"); - String thisMethodSignature = "delete-hashtag-comment-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentId + "&vreid=" + vreid; - return HttpClient.post(new GenericType>(){}, request, hashtags); - } - - public Map getVREHashtagsWithOccurrenceLib(String vreid) { - logger.debug("Request for vre hashtags occurrences"); - String thisMethodSignature = "get-vre-hashtags-occurrences-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid; - return HttpClient.get(new GenericType>>(){}, request); - } - - public Map getVREHashtagsWithOccurrenceFilteredByTimeLib(String vreid, long timestamp){ - logger.debug("Request for vre hashtags occurrences with time"); - String thisMethodSignature = "get-vre-hashtags-occurrences-time-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&time=" + timestamp; - return HttpClient.get(new GenericType>>(){}, request); - } - - - public List getVREPostsByHashtagLib(String vreid, String hashtag){ - hashtag = hashtag.substring(1); - logger.debug("Request for vre of hashtags"); - String thisMethodSignature = "get-vre-post-by-hashtag-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&hashtag=" + hashtag; - return HttpClient.get(new GenericType>>(){}, request); - } - } diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/InviteClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/InviteClient.java deleted file mode 100644 index 804344f..0000000 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/InviteClient.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.gcube.social_networking.social_networking_client_library; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.core.GenericType; - -import org.apache.commons.lang.Validate; -import org.gcube.portal.databook.shared.Invite; -import org.gcube.portal.databook.shared.InviteOperationResult; -import org.gcube.portal.databook.shared.InviteStatus; -import org.gcube.social_networking.social_networking_client_library.utils.HttpClient; -import org.gcube.social_networking.socialnetworking.model.output.ResponseBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Posts client. - * @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it) - */ -public class InviteClient extends BaseClient{ - - private static final String SUB_SERVICE_PATH = "2/invites/"; - private static Logger logger = LoggerFactory.getLogger(InviteClient.class); - - - public InviteClient() throws Exception { - super(SUB_SERVICE_PATH); - } - - public String isExistingInviteLib(String vreid, String email){ - Validate.isTrue(email != null, "email to invite cannot be null"); - - logger.debug("Request for inviting to vre"); - String thisMethodSignature = "is-existing-invite-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&email=" + email; - return HttpClient.get(new GenericType>(){}, request); - } - public InviteOperationResult saveInviteLib(Invite invite){ - Validate.isTrue(invite != null, "likeid to unlike cannot be null"); - - logger.debug("Request for saving invite"); - String thisMethodSignature = "save-invite-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, invite); - } - public Invite readInviteLib(String inviteid){ - Validate.isTrue(inviteid != null, "inviteid to read likes cannot be null"); - - logger.debug("Request for reading invite"); - String thisMethodSignature = "read-invite-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?inviteid=" + inviteid; - return HttpClient.get(new GenericType>(){}, request); - } - public boolean setInviteStatusLib(String vreid, String email, InviteStatus status){ - Validate.isTrue(status != null, "status to set cannot be null"); - - logger.debug("Request for setting invite status"); - String thisMethodSignature = "set-invite-status-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&email=" + email; - return HttpClient.post(new GenericType>(){}, request, status); - } - - public List getInvitedEmailsByVRELib(String vreid, InviteStatus... status){ - Validate.isTrue(status != null, "status to get cannot be null"); - - logger.debug("Request for getting email invites"); - String thisMethodSignature = "get-invited-email-by-vre-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid; - return HttpClient.post(new GenericType>>(){}, request, status); - } - -} diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/LibClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/LibClient.java new file mode 100644 index 0000000..3bbe747 --- /dev/null +++ b/src/main/java/org/gcube/social_networking/social_networking_client_library/LibClient.java @@ -0,0 +1,481 @@ +package org.gcube.social_networking.social_networking_client_library; + +import org.apache.commons.lang.Validate; +import org.gcube.portal.databook.shared.*; +import org.gcube.social_networking.social_networking_client_library.utils.HttpClient; +import org.gcube.social_networking.socialnetworking.model.output.ResponseBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.core.GenericType; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LibClient extends BaseClient{ + + private static final String SUB_SERVICE_PATH = "lib/"; + private static Logger logger = LoggerFactory.getLogger(LibClient.class); + + + public LibClient() throws Exception { + super(SUB_SERVICE_PATH); + } + + //Comments + public Boolean addCommentLib(Comment comment){ + Validate.isTrue(comment != null, "Comment to write cannot be null"); + + logger.debug("Request for writing comment"); + String thisMethodSignature = "add-comment-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, comment); + } + public Comment readCommentByIdLib(String commentid){ + Validate.isTrue(commentid != null, "Commentid to read cannot be null"); + + logger.debug("Request for reading commentid"); + String thisMethodSignature = "read-comment-by-id-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentid; + return HttpClient.get(new GenericType>(){}, request); + } + public List getAllCommentsByPostIdLib(String postid){ + Validate.isTrue(postid != null, "Postid to read cannot be null"); + + logger.debug("Request for reading comments of post"); + String thisMethodSignature = "get-comments-by-post-id-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; + return HttpClient.get(new GenericType>>(){}, request); + } + public List getRecentCommentsByUserAndDateLib(final String userid, + final long timeInMillis){ + + Validate.isTrue(userid != null, "username to read cannot be null"); + + logger.debug("Request for reading recent comments of user"); + String thisMethodSignature = "get-recent-comments-by-user-and-date-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?time=" + timeInMillis + "&username=" + userid; + return HttpClient.get(new GenericType>>(){}, request); + } + + public Boolean editCommentLib(Comment comment){ + Validate.isTrue(comment != null, "Comment to write cannot be null"); + + logger.debug("Request for writing comment"); + String thisMethodSignature = "edit-comment-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, comment); + } + + public boolean deleteCommentLib(String commentid, String postid){ + Validate.isTrue(commentid != null, "Comment to write cannot be null"); + + logger.debug("Request for del comment"); + String thisMethodSignature = "delete-comment-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentid + "&postid=" + postid; + return HttpClient.post(new GenericType>(){}, request, postid); + } + + //Hashtags + public boolean saveHashTagsLib(String feedid, String vreid, List hashtags) { + Validate.isTrue(hashtags != null, "hashtags to write cannot be null"); + + logger.debug("Request for saving hashtags"); + String thisMethodSignature = "save-hashtag-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?feedid=" + feedid + "&vreid=" + vreid; + return HttpClient.post(new GenericType>(){}, request, hashtags); + } + + public boolean deleteHashTagsLib(String feedid, String vreid, List hashtags) { + Validate.isTrue(hashtags != null, "hashtags to delete cannot be null"); + + logger.debug("Request for deleting hashtags"); + String thisMethodSignature = "delete-hashtag-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?feedid=" + feedid + "&vreid=" + vreid; + return HttpClient.post(new GenericType>(){}, request, hashtags); + } + + public boolean saveHashTagsCommentLib(String commentId, String vreid, List hashtags){ + Validate.isTrue(hashtags != null, "hashtags to comment cannot be null"); + + logger.debug("Request for saving hashtags comment"); + String thisMethodSignature = "save-hashtag-comment-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentId + "&vreid=" + vreid; + return HttpClient.post(new GenericType>(){}, request, hashtags); + } + + public boolean deleteHashTagsCommentLib(String commentId, String vreid, List hashtags) { + Validate.isTrue(hashtags != null, "hashtags to comment delete cannot be null"); + + logger.debug("Request for deleting hashtags comment"); + String thisMethodSignature = "delete-hashtag-comment-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?commentid=" + commentId + "&vreid=" + vreid; + return HttpClient.post(new GenericType>(){}, request, hashtags); + } + + public Map getVREHashtagsWithOccurrenceLib(String vreid) { + logger.debug("Request for vre hashtags occurrences"); + String thisMethodSignature = "get-vre-hashtags-occurrences-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid; + return HttpClient.get(new GenericType>>(){}, request); + } + + public Map getVREHashtagsWithOccurrenceFilteredByTimeLib(String vreid, long timestamp){ + logger.debug("Request for vre hashtags occurrences with time"); + String thisMethodSignature = "get-vre-hashtags-occurrences-time-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&time=" + timestamp; + return HttpClient.get(new GenericType>>(){}, request); + } + + + public List getVREPostsByHashtagLib(String vreid, String hashtag){ + hashtag = hashtag.substring(1); + logger.debug("Request for vre of hashtags"); + String thisMethodSignature = "get-vre-post-by-hashtag-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&hashtag=" + hashtag; + return HttpClient.get(new GenericType>>(){}, request); + } + + //Invites + public String isExistingInviteLib(String vreid, String email){ + Validate.isTrue(email != null, "email to invite cannot be null"); + + logger.debug("Request for inviting to vre"); + String thisMethodSignature = "is-existing-invite-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&email=" + email; + return HttpClient.get(new GenericType>(){}, request); + } + public InviteOperationResult saveInviteLib(Invite invite){ + Validate.isTrue(invite != null, "likeid to unlike cannot be null"); + + logger.debug("Request for saving invite"); + String thisMethodSignature = "save-invite-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, invite); + } + public Invite readInviteLib(String inviteid){ + Validate.isTrue(inviteid != null, "inviteid to read likes cannot be null"); + + logger.debug("Request for reading invite"); + String thisMethodSignature = "read-invite-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?inviteid=" + inviteid; + return HttpClient.get(new GenericType>(){}, request); + } + public boolean setInviteStatusLib(String vreid, String email, InviteStatus status){ + Validate.isTrue(status != null, "status to set cannot be null"); + + logger.debug("Request for setting invite status"); + String thisMethodSignature = "set-invite-status-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&email=" + email; + return HttpClient.post(new GenericType>(){}, request, status); + } + + public List getInvitedEmailsByVRELib(String vreid, InviteStatus... status){ + Validate.isTrue(status != null, "status to get cannot be null"); + + logger.debug("Request for getting email invites"); + String thisMethodSignature = "get-invited-email-by-vre-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid; + return HttpClient.post(new GenericType>>(){}, request, status); + } + + //Likes + public boolean likeLib(Like like){ + Validate.isTrue(like != null, "like to write cannot be null"); + + logger.debug("Request for liking post"); + String thisMethodSignature = "like-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, like); + } + public boolean unlikeLib(String userid, String likeid, String feedid){ + Validate.isTrue(likeid != null, "likeid to unlike cannot be null"); + + logger.debug("Request for unliking post"); + String thisMethodSignature = "unlike-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&likeid=" + likeid + "&feedid=" + feedid ; + return HttpClient.post(new GenericType>(){}, request, likeid); + } + public ListgetAllLikedPostIdsByUserLib(String userid){ + Validate.isTrue(userid != null, "userid to read likes cannot be null"); + + logger.debug("Request for reading likes of user"); + String thisMethodSignature = "get-all-liked-posts-by-user-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; + return HttpClient.get(new GenericType>>(){}, request); + } + public ListgetAllLikesByPostLib(String postid){ + Validate.isTrue(postid != null, "postid to read likes cannot be null"); + + logger.debug("Request for reading likes of post"); + String thisMethodSignature = "get-all-likes-by-post-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; + return HttpClient.get(new GenericType>>(){}, request); + } + + //Notifications + public boolean saveNotificationLib(Notification n){ + Validate.isTrue(n != null, "Notification cannot be null"); + logger.debug("Request for saving notification"); + String thisMethodSignature = "save-notification-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, n); + } + public Notification readNotificationLib(String notificationid){ + logger.debug("Request for getting notification by id"); + String thisMethodSignature = "read-notification-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?notid=" + notificationid; + return HttpClient.get(new GenericType>(){}, request); + } + public boolean setNotificationReadLib(String notificationid){ + Validate.isTrue(notificationid != null, "Notificationid cannot be null"); + logger.debug("Request for setting notification read"); + String thisMethodSignature = "set-notification-read-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?notid=" + notificationid;; + return HttpClient.post(new GenericType>(){}, request, notificationid); + } + + public List getAllNotificationByUserLib(String userid, int limit) { + logger.debug("Request for getting notification by user"); + String thisMethodSignature = "get-all-notifications-user"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&limit=" + limit; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getUnreadNotificationsByUserLib(String userid) { + logger.debug("Request for getting unread notification by user"); + String thisMethodSignature = "get-unread-notifications-user"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getRangeNotificationsByUserLib(String userid,int from, int quantity) { + logger.debug("Request for getting range notification by user"); + String thisMethodSignature = "get-range-notifications-user"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&from=" + from + "&quantity=" + quantity; + return HttpClient.get(new GenericType>>(){}, request); + } + + public boolean setAllNotificationReadByUserLib(String userid) { + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for setting all notification read"); + String thisMethodSignature = "set-all-notification-read-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; + return HttpClient.post(new GenericType>(){}, request, userid); + } + public boolean checkUnreadNotificationsLib(String userid) { + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for check unread notifications"); + String thisMethodSignature = "check-unread-notification-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; + return HttpClient.post(new GenericType>(){}, request, userid); + } + public boolean checkUnreadMessagesNotificationsLib(String userid) { + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for check unread messages notifications"); + String thisMethodSignature = "check-unread-messages-notification-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; + return HttpClient.post(new GenericType>(){}, request, userid); + + } + + public List getUserNotificationChannelsLib(String userid, NotificationType notificationType) { + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for get user notification channels"); + String thisMethodSignature = "get-user-notification-channels-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; + return HttpClient.post(new GenericType>>(){}, request, notificationType); + + } + + public boolean setUserNotificationPreferencesLib(String userid, Map enabledChannels){ + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for set user notification preferences"); + String thisMethodSignature = "set-notification-preference-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; + return HttpClient.post(new GenericType>(){}, request, enabledChannels); + + } + + public Map getUserNotificationPreferencesLib(String userid){ + Validate.isTrue(userid != null, "userid cannot be null"); + logger.debug("Request for getting notification preferences"); + String thisMethodSignature = "get-notification-preference-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; + return HttpClient.get(new GenericType>>(){}, request); + } + + + public boolean saveUserPostLib(Post post){ + Validate.isTrue(post != null, "Post to write cannot be null"); + + logger.debug("Request for save user post"); + String thisMethodSignature = "save-user-post-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, post); + } //bool + + public boolean saveAttachmentEntryLib(String postkey, Attachment attachment){ + Validate.isTrue(attachment != null, "Attachment to write cannot be null"); + + logger.debug("Request for save attachment"); + String thisMethodSignature = "save-attachment-lib" + "?postid=" + postkey; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, attachment); + } + + public boolean saveUserPostLib(Post post, List attachments ){ + Validate.isTrue(post != null, "Post to write cannot be null"); + + if (attachments != null && !attachments.isEmpty()) + post.setMultiFileUpload(true); + boolean savePostResult = saveUserPostLib(post); + if (savePostResult) { + logger.info("Post has been saved"); + String postkey = post.getKey(); + for (Attachment attachment : attachments) { + boolean attachSaveResult = saveAttachmentEntryLib(postkey, attachment); + if (!attachSaveResult) + logger.info("Some of the attachments failed to be saved: " + attachment.getName()); + } + return true; + } + else return false; + } + + public boolean saveAppPostLib(Post post, List attachments) { + Validate.isTrue(post != null, "Post to write cannot be null"); + + if (attachments != null && !attachments.isEmpty()) + post.setMultiFileUpload(true); + boolean savePostResult = saveAppPostLib(post); + if (savePostResult) { + logger.info("Post has been saved"); + String postkey = post.getKey(); + for (Attachment attachment : attachments) { + boolean attachSaveResult = saveAttachmentEntryLib(postkey, attachment); + if (!attachSaveResult) + logger.info("Some of the attachments failed to be saved: " + attachment.getName()); + } + return true; + } + else return false; + + } + + public boolean saveAppPostLib(Post post){ + Validate.isTrue(post != null, "Post to write cannot be null"); + + logger.debug("Request for saving application post"); + String thisMethodSignature = "save-app-post-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.post(new GenericType>(){}, request, post); + } //bool + + public boolean savePostToVRETimelineLib(String postkey, String vreid){ + Validate.isTrue(postkey != null, "Post to write cannot be null"); + + logger.debug("Request for writing post to vretimeline"); + String thisMethodSignature = "save-post-to-vretimeline-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postkey + "&vreid=" + vreid; + return HttpClient.post(new GenericType>(){}, request, postkey); + } //bool + + public Post readPostLib(String postid){ + logger.debug("Request for getting post with id"); + String thisMethodSignature = "read-post-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; + return HttpClient.get(new GenericType>(){}, request); + } //post + + public List getRecentPostsByUserAndDateLib(String userid, long timeinmillis){ + logger.debug("Request for getting recent posts by user"); + String thisMethodSignature = "get-recent-posts-by-user-date-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&time=" + timeinmillis; + return HttpClient.get(new GenericType>>(){}, request); + } //list + + public boolean deletePostLib(String postid){ + Validate.isTrue(postid != null, "feed to delete cannot be null"); + + logger.debug("Request for delete user post"); + String thisMethodSignature = "delete-post-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; + return HttpClient.post(new GenericType>(){}, request, postid); + } //bool + + public List getAllPostsByUserLib(String userid) { + logger.debug("Request for getting all posts by user"); + String thisMethodSignature = "get-all-posts-by-user-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid ; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getAllPostsByAppLib(String appid) { + logger.debug("Request for getting all posts by app"); + String thisMethodSignature = "get-all-posts-by-app-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?appid=" + appid ; + return HttpClient.get(new GenericType>>(){}, request); + + } + + public List getRecentCommentedPostsByUserAndDateLib(String userid, + long timeInMillis) { + logger.debug("Request for getting recent commented posts by user and date"); + String thisMethodSignature = "get-recent-commented-posts-by-user-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&time=" + timeInMillis; + return HttpClient.get(new GenericType>>(){}, request); + + } + + public List getAllPortalPrivacyLevelPostsLib(){ + logger.debug("Request for getting portal privacy level posts"); + String thisMethodSignature = "get-portal-privacy-level-posts-lib"; + String request = getServiceEndpoint() + thisMethodSignature; + return HttpClient.get(new GenericType>>(){}, request); + } //list + + public List getRecentPostsByUserLib(String userid, int quantity) { + logger.debug("Request for getting recent posts by user"); + String thisMethodSignature = "get-recent-posts-by-user-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&quantity=" + quantity ; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getAllPostsByVRELib(String vreid) { + logger.debug("Request for getting all posts by vre"); + String thisMethodSignature = "get-all-posts-by-vre-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid ; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getRecentPostsByVRELib(String vreid, int quantity) { + logger.debug("Request for getting recent posts by vre"); + String thisMethodSignature = "get-recent-posts-by-vre-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&quantity=" + quantity ; + return HttpClient.get(new GenericType>>(){}, request); + + } + + public RangePosts getRecentPostsByVREAndRangeLib(String vreid, int from, int quantity) { + logger.debug("Request for getting recent posts by vre and range"); + String thisMethodSignature = "get-recent-posts-by-vre-range-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&from=" + from + "&quantity=" + quantity; + return HttpClient.get(new GenericType>(){}, request); + } + + public List getAttachmentsByFeedIdLib(String feedId) { + logger.debug("Request for getting attachment by postid"); + String thisMethodSignature = "get-attachment-by-postid-lib"; + String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + feedId ; + return HttpClient.get(new GenericType>>(){}, request); + } + + public List getAllVREIdsLib(){ + logger.debug("Request for getting all vre ids"); + String thisMethodSignature = "get-all-vre-ids-lib"; + String request = getServiceEndpoint() + thisMethodSignature ; + return HttpClient.get(new GenericType>>(){}, request); + } +} diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/LikeClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/LikeClient.java deleted file mode 100644 index cdbaa67..0000000 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/LikeClient.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.gcube.social_networking.social_networking_client_library; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.core.GenericType; - -import org.apache.commons.lang.Validate; -import org.gcube.portal.databook.shared.Like; -import org.gcube.social_networking.social_networking_client_library.utils.HttpClient; -import org.gcube.social_networking.socialnetworking.model.output.ResponseBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Posts client. - * @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it) - */ -public class LikeClient extends BaseClient{ - - private static final String SUB_SERVICE_PATH = "2/likes/"; - private static Logger logger = LoggerFactory.getLogger(LikeClient.class); - - - public LikeClient() throws Exception { - super(SUB_SERVICE_PATH); - } - - public boolean likeLib(Like like){ - Validate.isTrue(like != null, "like to write cannot be null"); - - logger.debug("Request for liking post"); - String thisMethodSignature = "like-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, like); - } - public boolean unlikeLib(String userid, String likeid, String feedid){ - Validate.isTrue(likeid != null, "likeid to unlike cannot be null"); - - logger.debug("Request for unliking post"); - String thisMethodSignature = "unlike-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&likeid=" + likeid + "&feedid=" + feedid ; - return HttpClient.post(new GenericType>(){}, request, likeid); - } - public ListgetAllLikedPostIdsByUserLib(String userid){ - Validate.isTrue(userid != null, "userid to read likes cannot be null"); - - logger.debug("Request for reading likes of user"); - String thisMethodSignature = "get-all-liked-posts-by-user-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; - return HttpClient.get(new GenericType>>(){}, request); - } - public ListgetAllLikesByPostLib(String postid){ - Validate.isTrue(postid != null, "postid to read likes cannot be null"); - - logger.debug("Request for reading likes of post"); - String thisMethodSignature = "get-all-likes-by-post-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; - return HttpClient.get(new GenericType>>(){}, request); - } - -} diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/NotificationClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/NotificationClient.java index d94a757..87ef544 100644 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/NotificationClient.java +++ b/src/main/java/org/gcube/social_networking/social_networking_client_library/NotificationClient.java @@ -98,99 +98,4 @@ public class NotificationClient extends BaseClient{ HttpClient.post(new GenericType>(){}, request, event); } - - - - //library api - - public boolean saveNotificationLib(Notification n){ - Validate.isTrue(n != null, "Notification cannot be null"); - logger.debug("Request for saving notification"); - String thisMethodSignature = "save-notification-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, n); - } - public Notification readNotificationLib(String notificationid){ - logger.debug("Request for getting notification by id"); - String thisMethodSignature = "read-notification-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?notid=" + notificationid; - return HttpClient.get(new GenericType>(){}, request); - } - public boolean setNotificationReadLib(String notificationid){ - Validate.isTrue(notificationid != null, "Notificationid cannot be null"); - logger.debug("Request for setting notification read"); - String thisMethodSignature = "set-notification-read-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?notid=" + notificationid;; - return HttpClient.post(new GenericType>(){}, request, notificationid); - } - - public List getAllNotificationByUserLib(String userid, int limit) { - logger.debug("Request for getting notification by user"); - String thisMethodSignature = "get-all-notifications-user"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&limit=" + limit; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getUnreadNotificationsByUserLib(String userid) { - logger.debug("Request for getting unread notification by user"); - String thisMethodSignature = "get-unread-notifications-user"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getRangeNotificationsByUserLib(String userid,int from, int quantity) { - logger.debug("Request for getting range notification by user"); - String thisMethodSignature = "get-range-notifications-user"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&from=" + from + "&quantity=" + quantity; - return HttpClient.get(new GenericType>>(){}, request); - } - - public boolean setAllNotificationReadByUserLib(String userid) { - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for setting all notification read"); - String thisMethodSignature = "set-all-notification-read-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; - return HttpClient.post(new GenericType>(){}, request, userid); - } - public boolean checkUnreadNotificationsLib(String userid) { - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for check unread notifications"); - String thisMethodSignature = "check-unread-notification-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; - return HttpClient.post(new GenericType>(){}, request, userid); - } - public boolean checkUnreadMessagesNotificationsLib(String userid) { - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for check unread messages notifications"); - String thisMethodSignature = "check-unread-messages-notification-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; - return HttpClient.post(new GenericType>(){}, request, userid); - - } - - public List getUserNotificationChannelsLib(String userid, NotificationType notificationType) { - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for get user notification channels"); - String thisMethodSignature = "get-user-notification-channels-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid; - return HttpClient.post(new GenericType>>(){}, request, notificationType); - - } - - public boolean setUserNotificationPreferencesLib(String userid, Map enabledChannels){ - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for set user notification preferences"); - String thisMethodSignature = "set-notification-preference-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; - return HttpClient.post(new GenericType>(){}, request, enabledChannels); - - } - - public Map getUserNotificationPreferencesLib(String userid){ - Validate.isTrue(userid != null, "userid cannot be null"); - logger.debug("Request for getting notification preferences"); - String thisMethodSignature = "get-notification-preference-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid;; - return HttpClient.get(new GenericType>>(){}, request); - } } diff --git a/src/main/java/org/gcube/social_networking/social_networking_client_library/PostClient.java b/src/main/java/org/gcube/social_networking/social_networking_client_library/PostClient.java index 239689d..ddbb78c 100644 --- a/src/main/java/org/gcube/social_networking/social_networking_client_library/PostClient.java +++ b/src/main/java/org/gcube/social_networking/social_networking_client_library/PostClient.java @@ -186,156 +186,4 @@ public class PostClient extends BaseClient{ return HttpClient.get(new GenericType>>(){}, request); } - - - - //library api calls - - public boolean saveUserPostLib(Post post){ - Validate.isTrue(post != null, "Post to write cannot be null"); - - logger.debug("Request for save user post"); - String thisMethodSignature = "save-user-post-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, post); - } //bool - - public boolean saveUserPostLib(Post post, List attachments) { - Validate.isTrue(post != null, "Post to write cannot be null"); - - logger.debug("Request for saving application post"); - String thisMethodSignature = "save-user-post-attachments-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - Map> obj = new HashMap<>(); - obj.put(post, attachments); - return HttpClient.post(new GenericType>(){}, request, obj); - } - - public boolean saveAppPostLib(Post post, List attachments) { - Validate.isTrue(post != null, "Post to write cannot be null"); - - logger.debug("Request for saving application post"); - String thisMethodSignature = "save-app-post-attachments-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - Map> obj = new HashMap<>(); - obj.put(post, attachments); - return HttpClient.post(new GenericType>(){}, request, obj); - - } - - public boolean saveAppPostLib(Post post){ - Validate.isTrue(post != null, "Post to write cannot be null"); - - logger.debug("Request for saving application post"); - String thisMethodSignature = "save-app-post-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.post(new GenericType>(){}, request, post); - } //bool - - public boolean savePostToVRETimelineLib(String postkey, String vreid){ - Validate.isTrue(postkey != null, "Post to write cannot be null"); - - logger.debug("Request for writing post to vretimeline"); - String thisMethodSignature = "save-post-to-vretimeline-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postkey + "&vreid=" + vreid; - return HttpClient.post(new GenericType>(){}, request, postkey); - } //bool - - public Post readPostLib(String postid){ - logger.debug("Request for getting post with id"); - String thisMethodSignature = "read-post-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; - return HttpClient.get(new GenericType>(){}, request); - } //post - - public List getRecentPostsByUserAndDateLib(String userid, long timeinmillis){ - logger.debug("Request for getting recent posts by user"); - String thisMethodSignature = "get-recent-posts-by-user-date-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&time=" + timeinmillis; - return HttpClient.get(new GenericType>>(){}, request); - } //list - - public boolean deletePostLib(String postid){ - Validate.isTrue(postid != null, "feed to delete cannot be null"); - - logger.debug("Request for delete user post"); - String thisMethodSignature = "delete-post-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + postid; - return HttpClient.post(new GenericType>(){}, request, postid); - } //bool - - public List getAllPostsByUserLib(String userid) { - logger.debug("Request for getting all posts by user"); - String thisMethodSignature = "get-all-posts-by-user-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid ; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getAllPostsByAppLib(String appid) { - logger.debug("Request for getting all posts by app"); - String thisMethodSignature = "get-all-posts-by-app-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?appid=" + appid ; - return HttpClient.get(new GenericType>>(){}, request); - - } - - public List getRecentCommentedPostsByUserAndDateLib(String userid, - long timeInMillis) { - logger.debug("Request for getting recent commented posts by user and date"); - String thisMethodSignature = "get-recent-commented-posts-by-user-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&time=" + timeInMillis; - return HttpClient.get(new GenericType>>(){}, request); - - } - - public List getAllPortalPrivacyLevelPostsLib(){ - logger.debug("Request for getting portal privacy level posts"); - String thisMethodSignature = "get-portal-privacy-level-posts-lib"; - String request = getServiceEndpoint() + thisMethodSignature; - return HttpClient.get(new GenericType>>(){}, request); - } //list - - public List getRecentPostsByUserLib(String userid, int quantity) { - logger.debug("Request for getting recent posts by user"); - String thisMethodSignature = "get-recent-posts-by-user-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?userid=" + userid + "&quantity=" + quantity ; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getAllPostsByVRELib(String vreid) { - logger.debug("Request for getting all posts by vre"); - String thisMethodSignature = "get-all-posts-by-vre-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid ; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getRecentPostsByVRELib(String vreid, int quantity) { - logger.debug("Request for getting recent posts by vre"); - String thisMethodSignature = "get-recent-posts-by-vre-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&quantity=" + quantity ; - return HttpClient.get(new GenericType>>(){}, request); - - } - - public RangePosts getRecentPostsByVREAndRangeLib(String vreid, int from, int quantity) { - logger.debug("Request for getting recent posts by vre and range"); - String thisMethodSignature = "get-recent-posts-by-vre-range-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?vreid=" + vreid + "&from=" + from + "&quantity=" + quantity; - return HttpClient.get(new GenericType>(){}, request); - } - - public List getAttachmentsByFeedIdLib(String feedId) { - logger.debug("Request for getting attachment by postid"); - String thisMethodSignature = "get-attachment-by-postid-lib"; - String request = getServiceEndpoint() + thisMethodSignature + "?postid=" + feedId ; - return HttpClient.get(new GenericType>>(){}, request); - } - - public List getAllVREIdsLib(){ - logger.debug("Request for getting all vre ids"); - String thisMethodSignature = "get-all-vre-ids-lib"; - String request = getServiceEndpoint() + thisMethodSignature ; - return HttpClient.get(new GenericType>>(){}, request); - } - }