Compare commits

..

No commits in common. "master" and "Feature/23186" have entirely different histories.

14 changed files with 133 additions and 798 deletions

View File

@ -8,9 +8,9 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">

View File

@ -1,24 +1,8 @@
# Changelog
## [v2.0.1] - 2024-04-16
## [v1.0.0] - 2022-04-06
- fixed dependency versions
## [v2.0.0] - 2023-12-04
- Integrated corresponding API calls for all the public functions in Social Networking Library
## [v1.2.0] - 2022-10-20
- Minor fix on a method name
- Feature #23887 possibility to get-usernames-by-role in UserClient
- Feature #23995 Social Service add support for set Message read / unread
## [v1.1.0] - 2022-04-06
- First release
- Feature #23186 - Full notifications support for social service
First release
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

View File

@ -20,12 +20,10 @@ See [Releases](https://code-repo.d4science.org/gCubeSystem/social-service-client
## Authors
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
## Maintainers
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
## License
@ -40,4 +38,4 @@ by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)

44
pom.xml
View File

@ -1,18 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.2.0</version>
<version>1.1.0</version>
</parent>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>2.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<name>social-networking-service-client</name>
<packaging>jar</packaging>
<description>The social networking web service client library</description>
@ -22,14 +20,14 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.0.2</version>
<version>2.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>2.1.1</version>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -37,7 +35,7 @@
</dependencyManagement>
<properties>
<java-version>1.8</java-version>
<java-version>1.8</java-version>
<jaxrs.version>2.0.1</jaxrs.version>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<gCubeSubsystem>social-networking</gCubeSubsystem>
@ -56,29 +54,9 @@
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<version>[2.0.0, 3.0.0)</version>
<version>[1.16.0, 2.0.0)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
@ -87,13 +65,7 @@
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-model</artifactId>
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
<version>[1.0.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@ -10,18 +10,20 @@ import org.slf4j.LoggerFactory;
*/
public abstract class BaseClient {
private static Logger logger = LoggerFactory.getLogger(BaseClient.class);
private String serviceEndpoint;
private static Logger logger = LoggerFactory.getLogger(BaseClient.class);
private String serviceEndpoint;
public BaseClient(String subPath) throws Exception {
ServiceDiscoverer discoverer = new ServiceDiscoverer();
logger.debug("Discovering service...");
serviceEndpoint = discoverer.getEntryPoint();
serviceEndpoint = serviceEndpoint.endsWith("/") ? serviceEndpoint + subPath :
serviceEndpoint + "/" + subPath;
logger.debug("Discovered service " + serviceEndpoint);
}
public BaseClient(String subPath) throws Exception {
ServiceDiscoverer discoverer = new ServiceDiscoverer();
serviceEndpoint = discoverer.getEntryPoint();
logger.debug("Discovering service...");
serviceEndpoint = serviceEndpoint.endsWith("/") ? serviceEndpoint + subPath : serviceEndpoint + "/" + subPath;
logger.info("Discovered service " + serviceEndpoint);
}
public String getServiceEndpoint() {
return serviceEndpoint;
}
public String getServiceEndpoint() {
return serviceEndpoint;
}
}

View File

@ -1,16 +1,10 @@
package org.gcube.social_networking.social_networking_client_library;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.Post;
import org.gcube.portal.databook.shared.ex.*;
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
import org.gcube.social_networking.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
@ -19,7 +13,6 @@ import org.slf4j.LoggerFactory;
/**
* HashTags client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it)
*/
public class HashTagClient extends BaseClient{
@ -41,4 +34,5 @@ public class HashTagClient extends BaseClient{
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<HashMap<String, Integer>>>(){}, request);
}
}

View File

@ -1,487 +0,0 @@
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 = "2/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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Comment>>(){}, request);
}
public List<Comment> 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<ResponseBean<ArrayList<Comment>>>(){}, request);
}
public List<Comment> 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<ResponseBean<ArrayList<Comment>>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, request, postid);
}
//Hashtags
public boolean saveHashTagsLib(String feedid, String vreid, List<String> 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<ResponseBean<Boolean>>(){}, request, hashtags);
}
public boolean deleteHashTagsLib(String feedid, String vreid, List<String> 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<ResponseBean<Boolean>>(){}, request, hashtags);
}
public boolean saveHashTagsCommentLib(String commentId, String vreid, List<String> 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<ResponseBean<Boolean>>(){}, request, hashtags);
}
public boolean deleteHashTagsCommentLib(String commentId, String vreid, List<String> 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<ResponseBean<Boolean>>(){}, request, hashtags);
}
public Map<String, Integer> 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<ResponseBean<HashMap<String, Integer>>>(){}, request);
}
public Map<String, Integer> 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<ResponseBean<HashMap<String, Integer>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, 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<ResponseBean<String>>(){}, 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<ResponseBean<InviteOperationResult>>(){}, 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<ResponseBean<Invite>>(){}, 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<ResponseBean<Boolean>>(){}, request, status);
}
public List<Invite> 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<ResponseBean<ArrayList<Invite>>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, request, likeid);
}
public List<String>getAllLikedPostIdsByUserLib(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<ResponseBean<ArrayList<String>>>(){}, request);
}
public List<Like>getAllLikesByPostLib(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<ResponseBean<ArrayList<Like>>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Notification>>(){}, 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<ResponseBean<Boolean>>(){}, request, notificationid);
}
public List<Notification> 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<ResponseBean<ArrayList<Notification>>>(){}, request);
}
public List<Notification> 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<ResponseBean<ArrayList<Notification>>>(){}, request);
}
public List<Notification> 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<ResponseBean<ArrayList<Notification>>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, request, userid);
}
public List<NotificationChannelType> 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 + "&type=" + notificationType.toString();
return HttpClient.get(new GenericType<ResponseBean<ArrayList<NotificationChannelType>>>(){}, request);
}
public boolean setUserNotificationPreferencesLib(String userid, Map<NotificationType, NotificationChannelType[]> 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;
for(NotificationType notificationType: enabledChannels.keySet()){
logger.info("Type: " + notificationType.toString());
for(NotificationChannelType channelType: enabledChannels.get(notificationType)){
logger.info(channelType.toString());
}
}
return HttpClient.post(new GenericType<ResponseBean<Boolean>>(){}, request, enabledChannels);
}
public Map<NotificationType, NotificationChannelType[]> 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<ResponseBean<HashMap<NotificationType, NotificationChannelType[]>>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, request, attachment);
}
public boolean saveUserPostLib(Post post, List<Attachment> 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<Attachment> 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Boolean>>(){}, 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<ResponseBean<Post>>(){}, request);
} //post
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
} //list<post>
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<ResponseBean<Boolean>>(){}, request, postid);
} //bool
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
} //list<post>
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, request);
}
public List<Post> 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<ResponseBean<ArrayList<Post>>>(){}, 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<ResponseBean<RangePosts>>(){}, request);
}
public List<Attachment> 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<ResponseBean<ArrayList<Attachment>>>(){}, request);
}
public List<String> 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<ResponseBean<ArrayList<String>>>(){}, request);
}
}

View File

@ -3,13 +3,12 @@ package org.gcube.social_networking.social_networking_client_library;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
import org.gcube.social_networking.socialnetworking.model.beans.Message;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInbox;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
import org.gcube.social_networking.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -58,7 +57,7 @@ public class MessageClient extends BaseClient{
* Write message
* @return message id
*/
public String writeMessage(MessageInputBean m){
public String writeMessage(Message m){
Validate.isTrue(m != null, "Message cannot be null");
@ -68,26 +67,4 @@ public class MessageClient extends BaseClient{
return HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, m);
}
/**
* mark the message read or not
* @param messageId the message identifier
* @param read true to set read, false to set unread
* @return the result of the operation
*/
public String markMessageRead(String messageId, boolean read) {
Validate.isTrue(messageId != null, "Message id cannot be null");
logger.debug("set Message id:" + messageId + " read?" + read);
String thisMethodSignature = "set-message-read";
String request = getServiceEndpoint() + thisMethodSignature;
Form form = new Form();
form.param("messageId", messageId);
form.param("read", read+"");
return HttpClient.postFormData(new GenericType<ResponseBean<String>>(){}, request, form);
}
}

View File

@ -1,20 +1,12 @@
package org.gcube.social_networking.social_networking_client_library;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
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.ex.ColumnNameNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
@ -28,7 +20,6 @@ import org.slf4j.LoggerFactory;
/**
* Notifications client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it)
*/
public class NotificationClient extends BaseClient{
@ -49,7 +40,7 @@ public class NotificationClient extends BaseClient{
public List<Notification> getNotifications(int from, int quantity){
Validate.isTrue(from >= 1, "From cannot be negative");
Validate.isTrue(quantity >= 0, "Quantity cannot be negative");
Validate.isTrue(from >= 0, "Quantity cannot be negative");
logger.debug("Request for getting notifications");
String thisMethodSignature = "get-range-notifications";
@ -98,4 +89,5 @@ public class NotificationClient extends BaseClient{
HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, event);
}
}

View File

@ -3,15 +3,12 @@ package org.gcube.social_networking.social_networking_client_library;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.databook.shared.*;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
import org.gcube.social_networking.socialnetworking.model.output.ResponseBean;
@ -21,7 +18,6 @@ import org.slf4j.LoggerFactory;
/**
* Posts client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it)
*/
public class PostClient extends BaseClient{
@ -37,14 +33,14 @@ public class PostClient extends BaseClient{
* Get posts since date
* @return
*/
public List<Post> getUserPostsSinceDate(long timeInMillis){
public List<Feed> getUserPostsSinceDate(long timeInMillis){
Validate.isTrue(timeInMillis >= 0, "time cannot be negative");
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user-since";
String request = getServiceEndpoint() + thisMethodSignature + "?time=" + timeInMillis;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -52,12 +48,12 @@ public class PostClient extends BaseClient{
* Get all posts
* @return
*/
public List<Post> getAllUserPosts(){
public List<Feed> getAllUserPosts(){
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -65,14 +61,14 @@ public class PostClient extends BaseClient{
* Get posts quantity
* @return
*/
public List<Post> getUserPostsQuantity(int quantity){
public List<Feed> getUserPostsQuantity(int quantity){
Validate.isTrue(quantity >= 0, "quantity cannot be negative");
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user-quantity";
String request = getServiceEndpoint() + thisMethodSignature + "?quantity=" + quantity;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -80,14 +76,14 @@ public class PostClient extends BaseClient{
* Write post
* @return
*/
public Post writeUserPost(PostInputBean toWrite){
public Feed writeUserPost(PostInputBean toWrite){
Validate.isTrue(toWrite != null, "Post to write cannot be null");
logger.debug("Request for writing post");
String thisMethodSignature = "write-post-user";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
return HttpClient.post(new GenericType<ResponseBean<Feed>>(){}, request, toWrite);
}
@ -95,12 +91,12 @@ public class PostClient extends BaseClient{
* Get posts application (token set must belong to the application)
* @return
*/
public List<Post> getAllApplicationPosts(){
public List<Feed> getAllApplicationPosts(){
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-app";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -108,19 +104,18 @@ public class PostClient extends BaseClient{
* Write post application (token set must belong to the application)
* @return
*/
public Post writeApplicationPost(PostInputBean toWrite){
public Feed writeApplicationPost(PostInputBean toWrite){
Validate.isTrue(toWrite != null, "Post to write cannot be null");
logger.debug("Request for writing application post");
String thisMethodSignature = "write-post-app";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
return HttpClient.post(new GenericType<ResponseBean<Feed>>(){}, request, toWrite);
}
/**
* @deprecated use List<Post> getVREPosts()
* Get posts vre
* @return
*/
@ -131,18 +126,6 @@ public class PostClient extends BaseClient{
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
/**
* Get posts vre
* @return
*/
public List<Post> getVREPosts(){
logger.debug("Request for getting posts vre");
String thisMethodSignature = "get-posts-vre";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
/**
@ -150,14 +133,14 @@ public class PostClient extends BaseClient{
* @return
* @throws UnsupportedEncodingException
*/
public List<Post> getHashtagPosts(String hashtag) throws UnsupportedEncodingException{
public List<Feed> getHashtagPosts(String hashtag) throws UnsupportedEncodingException{
Validate.isTrue(hashtag != null, "hashtag cannot be null");
logger.debug("Request for getting posts with hashtag " + hashtag);
String thisMethodSignature = "get-posts-by-hashtag";
String request = getServiceEndpoint() + thisMethodSignature + "?hashtag=" + URLEncoder.encode(hashtag, "UTF-8");
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -165,12 +148,12 @@ public class PostClient extends BaseClient{
* Get liked posts
* @return
*/
public List<Post> getUserLikedPost(){
public List<Feed> getUserLikedPost(){
logger.debug("Request for getting posts liked");
String thisMethodSignature = "get-liked-posts";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -186,4 +169,5 @@ public class PostClient extends BaseClient{
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
}
}

View File

@ -2,10 +2,8 @@ package org.gcube.social_networking.social_networking_client_library;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.core.GenericType;
@ -29,146 +27,130 @@ public class UserClient extends BaseClient{
public UserClient() throws Exception {
super(SUB_SERVICE_PATH);
}
/**
* Get attribute value
* @return
*/
public String getCustomAttribute(String attributeKey){
Validate.isTrue(attributeKey != null, "attribute key cannot be null");
logger.debug("Request for attribute value");
String thisMethodSignature = "get-custom-attribute";
String request = getServiceEndpoint() + thisMethodSignature + "?attribute=" + attributeKey;
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
}
/**
* Get fullname
* @return user's fullname
*/
public String getFullName(){
logger.debug("Request for fullname");
String thisMethodSignature = "get-fullname";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
}
/**
* Get email
* @return users'email
*/
public String getEmail(){
logger.debug("Request for email");
String thisMethodSignature = "get-email";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
}
/**
* Get profile
* @return
*/
public UserProfileExtended getProfile(){
logger.debug("Request for getting profile");
String thisMethodSignature = "get-profile";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<UserProfileExtended>>(){}, request);
}
/**
* Get all usernames in this context
* @return
*/
public List<String> getAllUsernamesContext(){
logger.debug("Request for getting usernames in this context");
String thisMethodSignature = "get-all-usernames";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
}
/**
* Get all usernames and fullnames in this context
* @return
*/
public Map<String, String> getAllUsernamesFullnamesContext(){
logger.debug("Request for getting usernames and fullnames in this context");
String thisMethodSignature = "get-all-fullnames-and-usernames";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<HashMap<String, String>>>(){}, request);
}
/**
* Get usernames by global role
* @return
*/
public List<String> getAllUsernamesByGlobalRole(String globalRole){
Validate.isTrue(globalRole != null, "role cannot be null");
logger.debug("Request for getting usernames with global role");
String thisMethodSignature = "get-usernames-by-global-role";
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + globalRole;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
}
/**
* Get usernames by role
* @deprecated use #getAllUsernamesByRole(String rolename) instead
* @return the usernames having such role
* Get usernames by local role
* @return
*/
@Deprecated
public List<String> getAllUsernamesByLocalRole(String localRole){
Validate.isTrue(localRole != null, "role cannot be null");
logger.debug("Request for getting usernames by role role");
logger.debug("Request for getting usernames with global role");
String thisMethodSignature = "get-usernames-by-role";
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + localRole;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
}
/**
* Get usernames by role, the environment (i.e. VRE/VLab) is inferred from the token
* @return the usernames having such role
*/
public Set<String>getAllUsernamesByRole(String rolename){
Validate.isTrue(rolename != null, "role cannot be null");
logger.debug("Request for getting usernames with global role");
String thisMethodSignature = "get-usernames-by-role";
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + rolename;
ArrayList<String> sourceList = HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
Set<String> usernames = new HashSet<>(sourceList);
return usernames;
}
/**
* Check if user exists
* @return
*/
public Boolean userExists(String username){
Validate.isTrue(username != null, "username cannot be null");
logger.debug("Request for getting usernames with global role");
String thisMethodSignature = "user-exists";
String request = getServiceEndpoint() + thisMethodSignature + "?username=" + username;
return HttpClient.get(new GenericType<ResponseBean<Boolean>>(){}, request);
}
}

View File

@ -4,9 +4,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -88,36 +86,4 @@ public class HttpClient{
return result.getResult();
}
/**
* Executes a post request
* @param returnType
* @param requestUrl
* @param obj
* @return
*/
public static <R> R postFormData(GenericType<ResponseBean<R>> returnType, String requestUrl, Form form){
logger.debug("Executing post request at url " + requestUrl);
ClientConfig cc = new ClientConfig().register(new JacksonFeature()).register(new AuthorizationFilter()).register(new CustomObjectMapper());;
Client client = ClientBuilder.newClient(cc);
WebTarget webResourceGet = client.target(requestUrl);
Builder basicRequest = webResourceGet.request();
Response response = basicRequest.post(Entity.form(form), Response.class);
if(response == null)
throw new WebApplicationException("Response returned by the service is null");
if(response.getStatus() >= 300)
throw new WebApplicationException("There was an error at server side: " + response.getStatusInfo());
ResponseBean<R> result = response.readEntity(returnType);
if (!result.isSuccess())
throw new WebApplicationException(
"Error message is " + result.getMessage());
return result.getResult();
}
}

View File

@ -3,18 +3,16 @@ package org.gcube.portal.social_networking_client_library;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.Post;
import org.gcube.social_networking.social_networking_client_library.FullTextSearchClient;
import org.gcube.social_networking.social_networking_client_library.HashTagClient;
import org.gcube.social_networking.social_networking_client_library.MessageClient;
@ -27,8 +25,8 @@ import org.gcube.social_networking.social_networking_client_library.VREClient;
import org.gcube.social_networking.socialnetworking.model.beans.ApplicationId;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.JobStatusModelType;
import org.gcube.social_networking.socialnetworking.model.beans.Message;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInbox;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
import org.gcube.social_networking.socialnetworking.model.beans.MyVRE;
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
@ -51,34 +49,27 @@ public class TestClientServices {
private static Logger logger = LoggerFactory.getLogger(TestClientServices.class);
@SuppressWarnings("deprecation")
@Before
public void setContextAndToken(){
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/gCube");
//String umaToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJySUJPYjZZY3p2ZE4xNVpuNHFkUTRLdEQ5VUhyY1dwNWJCT3NaLXpYbXM0In0.eyJleHAiOjE2NjM2NjU2NTgsImlhdCI6MTY2MzY2NTM1OCwiYXV0aF90aW1lIjoxNjYzNjY0MTg1LCJqdGkiOiIxMjNhYmY0MS1lZmE1LTQ4ZjEtYmE2Zi03MjNkOWZjNDAwMWQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmQ0c2NpZW5jZS5vcmcvYXV0aC9yZWFsbXMvZDRzY2llbmNlIiwiYXVkIjoiJTJGZDRzY2llbmNlLnJlc2VhcmNoLWluZnJhc3RydWN0dXJlcy5ldSUyRmdDdWJlQXBwcyUyRmdDdWJlIiwic3ViIjoiMzM4OGQwZjgtM2E0OS00ZGEwLWE3OGUtN2I2MjI1OTI2M2U2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoidmxhYi5pc3RpLmNuci5pdCIsInNlc3Npb25fc3RhdGUiOiI3MjRkMmJmOS00NjQ2LTQwZjAtOTY1ZC02MzFlODJiZWZkMmEiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbIi8qIl0sInJlc291cmNlX2FjY2VzcyI6eyIlMkZkNHNjaWVuY2UucmVzZWFyY2gtaW5mcmFzdHJ1Y3R1cmVzLmV1JTJGZ0N1YmVBcHBzJTJGZ0N1YmUiOnsicm9sZXMiOlsiVlJ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sicGVybWlzc2lvbnMiOlt7InJzaWQiOiI1NzI4NTUxMC0zOTM5LTRkZTctOGZjMS1lM2E5ZDNjY2UyODEiLCJyc25hbWUiOiJEZWZhdWx0IFJlc291cmNlIn1dfSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwic2lkIjoiZjI2MjU0MjAtNzRjNS00NTQ0LWI2NmEtZGZhMDhkNjdkNDU0IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsIm5hbWUiOiJMdWNhIEZyb3NpbmkiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsdWNhLmZyb3NpbmkiLCJnaXZlbl9uYW1lIjoiTHVjYSIsImZhbWlseV9uYW1lIjoiRnJvc2luaSIsImVtYWlsIjoibHVjYS5mcm9zaW5pQGlzdGkuY25yLml0In0.jt43mGeSm_4hVNFThTBmmOxzotsTHPp0DKDzBNAgESFkzNRb7ZE1j7Ab_1M6fqjpciLsk093XTEpws0OksUEAWUgxj5iAOXopJKRr6cCnmQXitWTa8WpwWZyj6AiI8PSgHCQhY3-CU8mptmd4acDtagHSbhZ320aNx7rLTaZ_7KEdRmErmgzWhnPwD3O2ONcnxIuAL1rqu4o8SJl-cj5ppFc2V54VSY56AT2IK2GmP_he9R32_0K_F0SAwsuDmv7eF1MwQM7j27H9ewfEKP8w9RooZtZYj3Pm7-Ac4XSir9w5eG1xKOyiGbIlvJZU4FQwXINntUVTVPVfPaXZ_ZbOw";
AccessTokenProvider.instance.set(umaToken);
SecurityTokenProvider.instance.set("");
AccessTokenProvider.instance.set("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDkyMzQ3NDksImlhdCI6MTY0OTIzNDQ0OSwiYXV0aF90aW1lIjoxNjQ5MjM0NDQ0LCJqdGkiOiJhMzI3NmY4Ny05NmZjLTRmZTQtYjIyZC1jNzFmZTQ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YTStBSDT84ZJMrspHIjstAinax0sY0h2tG-DBhdK6AI0D-MFiOL07FW4iQgizXh4qnpzVNL0vxIUQMYo99R4DYsZzcsrxnUL0qzhNHfN4PqdMRWpt-eRyKO15FvA7_HExAemOzYEFbRrw8JSpsXj6BNcRg9ZwRV7815WhbqhV-Cq3_PDjyiSw3mVGjeh1QmNTOSbBKniGYJo2nWBng3tP_HS0yoS1xRCS9d0PrjBEVdbRn-HlM4M43DA");
//SecurityTokenProvider.instance.set("");
}
@Test
public void testCatalogueEvents() throws Exception {
NotificationClient nc = new NotificationClient();
String[] idstoNotify = {"andrea.rossi"};
String[] idstoNotify = {"andrea.rossi", "mister.pink"};
CatalogueEvent event =
new CatalogueEvent(
CatalogueEventType.ITEM_SUBMITTED,
idstoNotify,
"Submitted item RESTful Transaction Model",
"Giorgino Giorgetti created the item RESTful Transaction Model. You are kindly requested to review it and decide either to APPROVE or REJECT it. ",
new URL("https://data-dev.d4science.net/rU7T"));
"Wyscout soccer-logs dataset",
"submitted \"Wyscout soccer-logs dataset\", a dataset of soccer-logs for all the main soccer leagues in the world, from season 2014/2015 to the current one. ",
new URL("http://data.d4science.org/ctlg/ResourceCatalogue/wyscout_soccer-logs_dataset"));
nc.sendCatalogueEvent(event);
}
@Test
@ -90,7 +81,7 @@ public class TestClientServices {
FileItemBean fileItem = new FileItemBean("90b8da48-d363-441a-f0a2-4f413ae747d7", "updated item.pdf", "updated item.pdf",
"/Workspace/_shared attachments/test updated item from client", folder);
String[] idstoNotify = {"andrea.rossi"};
String[] idstoNotify = {"andrea.rossi", "mister.pink"};
WorkspaceEvent event = new UpdatedItemEvent(idstoNotify, fileItem);
nc.sendWorkspaceEvent(event);
event = new AddedItemEvent(idstoNotify, fileItem);
@ -98,7 +89,7 @@ public class TestClientServices {
event = new DeletedItemEvent(idstoNotify, "theDeletedFilenName.pdf", folder);
nc.sendWorkspaceEvent(event);
String[] contextIdstoNotify = {"/pred4s/preprod/preVRE"};
String[] contextIdstoNotify = {"/gcube/devsec/devVRE"};
event = new UpdatedItemEvent(contextIdstoNotify, true, fileItem);
nc.sendWorkspaceEvent(event);
}
@ -154,24 +145,14 @@ public class TestClientServices {
public void sendMessage() throws Exception{
logger.debug("Sending message ");
MessageClient messagesClient = new MessageClient();
List<Recipient> rec = Arrays.asList(new Recipient("andrea.rossi"), new Recipient("giancarlo.panichi"));
MessageInputBean message = new MessageInputBean(
List<Recipient> rec = Arrays.asList(new Recipient("andrea.rossi"));
Message message = new Message(
"Test message",
"Sending message via client " + System.currentTimeMillis(),
new ArrayList<Recipient>(rec));
String idMessage = messagesClient.writeMessage(message);
assert(idMessage != null);
}
@Test
public void markMessageRead() throws Exception{
logger.debug("markMessageRead message ");
MessageClient messagesClient = new MessageClient();
String idMessage = messagesClient.markMessageRead("a7b825c3-a0ca-42d7-b228-00b9e8f015e4", false);
assert(idMessage != null);
}
//@Test
public void testNotifications() throws Exception {
@ -217,19 +198,23 @@ public class TestClientServices {
logger.debug("My Vres " + myVres);
}
@Test
public void TestUsersClient() throws Exception{
//@Test
public void UsersClientTests() throws Exception{
UserClient userClient = new UserClient();
Set<String> vreManagers = userClient.getAllUsernamesByRole("Data-Manager");
// Requires user token bound to the root context
// List<String> administrators = userClient.getAllUsernamesByGlobalRole("administrator");
//
// assert(administrators != null && !administrators.isEmpty());
// logger.debug("Administrators are " + administrators);
List<String> vreManagers = userClient.getAllUsernamesByLocalRole("vre-manager");
assert(vreManagers != null && !vreManagers.isEmpty());
System.out.println("Data Managers are " + vreManagers);
List<String> moderators = userClient.getAllUsernamesByLocalRole("VRE-Managers");
assert(moderators != null && !moderators.isEmpty());
System.out.println("Catalogue-Moderators are " + moderators);
logger.debug("Vre Managers are " + vreManagers);
String myEmail = userClient.getEmail();
@ -245,7 +230,7 @@ public class TestClientServices {
String industry = userClient.getCustomAttribute("Industry");
//assert(industry != null && !industry.isEmpty());
assert(industry != null && !industry.isEmpty());
logger.debug("My Industry is " + industry);
@ -276,51 +261,40 @@ public class TestClientServices {
}
@Test
//@Test
public void getUserPostsSinceDate() throws Exception{
PostClient postClient = new PostClient();
List<Post> sinceLastYearPost = postClient.getUserPostsSinceDate(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 12);
List<Feed> sinceLastYearPost = postClient.getUserPostsSinceDate(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 12);
logger.debug("Posts are " + sinceLastYearPost);
}
@Test
//@Test
public void getAllUserPosts() throws Exception{
PostClient postClient = new PostClient();
List<Post> allposts = postClient.getAllUserPosts();
logger.debug("All posts found:");
for (Post post : allposts) {
logger.debug(post.toString());
}
List<Feed> allposts = postClient.getAllUserPosts();
logger.debug("All posts are " + allposts);
}
@Test
//@Test
public void getUserPostsQuantity() throws Exception{
PostClient postClient = new PostClient();
List<Post> quantityPosts = postClient.getUserPostsQuantity(3);
logger.debug("Some posts are ");
logger.debug(quantityPosts + " posts found:");
for (Post post : quantityPosts) {
logger.debug(post.toString());
}
List<Feed> quantityPosts = postClient.getUserPostsQuantity(3);
logger.debug("Some posts are " + quantityPosts);
}
@Test
//@Test
public void writeUserPost() throws Exception{
PostClient postClient = new PostClient();
PostInputBean postInputBean = new PostInputBean();
postInputBean.setText("Testing social networking rest client at " + new Date());
//Post post = postClient.writeApplicationPost(postInputBean);
PostInputBean post = new PostInputBean("Testing social networking rest client", null, null, null, null, null, false, null);
Post written = postClient.writeUserPost(postInputBean);
logger.debug("Written post is " + post);
PostInputBean toWrite = new PostInputBean("Testing social networking rest client", null, null, null, null, null, false, null);
Feed written = postClient.writeUserPost(toWrite);
logger.debug("Written post is " + written);
}
@ -335,7 +309,7 @@ public class TestClientServices {
SecurityTokenProvider.instance.set(token);
PostClient postClient = new PostClient();
List<Post> applicationPosts = postClient.getAllApplicationPosts();
List<Feed> applicationPosts = postClient.getAllApplicationPosts();
logger.debug("Application posts are " + applicationPosts);
SecurityTokenProvider.instance.set(currentToken);
@ -354,22 +328,19 @@ public class TestClientServices {
PostClient postClient = new PostClient();
PostInputBean toWrite = new PostInputBean("Testing social networking rest client [via application token] #apptoken #rest #client #java", null, null, null, null, null, false, null);
Post written = postClient.writeApplicationPost(toWrite);
Feed written = postClient.writeApplicationPost(toWrite);
logger.debug("Written post is " + written);
SecurityTokenProvider.instance.set(currentToken);
}
@Test
//@Test
public void getPostsVRE() throws Exception{
PostClient postClient = new PostClient();
List<Post> vrePosts = postClient.getVREPosts();
logger.debug("VRE posts : ");
for (Post post : vrePosts) {
logger.debug(post.toString());
}
List<Feed> vrePosts = postClient.getPostsVRE();
logger.debug("VRE posts are " + vrePosts);
}
@ -377,21 +348,21 @@ public class TestClientServices {
public void getHashtagPosts() throws Exception{
PostClient postClient = new PostClient();
List<Post> postsWithHashtag = postClient.getHashtagPosts("#connect");
List<Feed> postsWithHashtag = postClient.getHashtagPosts("#connect");
logger.debug("Posts with hashtag #connect are " + postsWithHashtag);
}
@Test
//@Test
public void getUserLikedPost() throws Exception{
PostClient postClient = new PostClient();
List<Post> postsLiked = postClient.getUserLikedPost();
List<Feed> postsLiked = postClient.getUserLikedPost();
logger.debug("Posts liked are " + postsLiked);
}
@Test
//@Test
public void getUserLikedPostIds() throws Exception{
PostClient postClient = new PostClient();