2018-02-19 16:35:01 +01:00
|
|
|
package org.gcube.social_networking.social_networking_client_library;
|
2017-10-21 22:35:21 +02:00
|
|
|
|
2018-02-19 16:27:09 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLEncoder;
|
2017-10-21 22:35:21 +02:00
|
|
|
import java.util.ArrayList;
|
2023-11-21 18:36:28 +01:00
|
|
|
import java.util.HashMap;
|
2017-10-21 22:35:21 +02:00
|
|
|
import java.util.List;
|
2023-11-21 18:36:28 +01:00
|
|
|
import java.util.Map;
|
2017-10-21 22:35:21 +02:00
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
import javax.ws.rs.core.GenericType;
|
|
|
|
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.apache.commons.lang.Validate;
|
2023-11-21 14:08:50 +01:00
|
|
|
import org.gcube.portal.databook.shared.*;
|
|
|
|
|
2018-02-19 16:35:01 +01:00
|
|
|
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;
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts client.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
2023-11-24 11:54:53 +01:00
|
|
|
* @author Ahmed Ibrahim at ISTI-CNR (ahmed.ibrahim@isti.cnr.it)
|
2017-10-21 22:35:21 +02:00
|
|
|
*/
|
2018-02-19 16:27:09 +01:00
|
|
|
public class PostClient extends BaseClient{
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
private static final String SUB_SERVICE_PATH = "2/posts/";
|
2018-02-19 16:27:09 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(PostClient.class);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
|
2018-02-19 16:27:09 +01:00
|
|
|
public PostClient() throws Exception {
|
2017-10-21 22:35:21 +02:00
|
|
|
super(SUB_SERVICE_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get posts since date
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getUserPostsSinceDate(long timeInMillis){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
Validate.isTrue(timeInMillis >= 0, "time cannot be negative");
|
|
|
|
|
|
|
|
logger.debug("Request for getting posts");
|
|
|
|
String thisMethodSignature = "get-posts-user-since";
|
2018-02-19 16:27:09 +01:00
|
|
|
String request = getServiceEndpoint() + thisMethodSignature + "?time=" + timeInMillis;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all posts
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getAllUserPosts(){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
logger.debug("Request for getting posts");
|
|
|
|
String thisMethodSignature = "get-posts-user";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get posts quantity
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getUserPostsQuantity(int quantity){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
Validate.isTrue(quantity >= 0, "quantity cannot be negative");
|
|
|
|
|
|
|
|
logger.debug("Request for getting posts");
|
|
|
|
String thisMethodSignature = "get-posts-user-quantity";
|
2018-02-19 16:27:09 +01:00
|
|
|
String request = getServiceEndpoint() + thisMethodSignature + "?quantity=" + quantity;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write post
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public Post writeUserPost(PostInputBean toWrite){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
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;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get posts application (token set must belong to the application)
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getAllApplicationPosts(){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
logger.debug("Request for getting posts");
|
|
|
|
String thisMethodSignature = "get-posts-app";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write post application (token set must belong to the application)
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public Post writeApplicationPost(PostInputBean toWrite){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
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;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-20 14:38:36 +02:00
|
|
|
* @deprecated use List<Post> getVREPosts()
|
2017-10-21 22:35:21 +02:00
|
|
|
* Get posts vre
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Feed> getPostsVRE(){
|
|
|
|
|
|
|
|
logger.debug("Request for getting posts vre");
|
|
|
|
String thisMethodSignature = "get-posts-vre";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2018-02-17 18:51:38 +01:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
2022-10-20 14:38:36 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-10-21 22:35:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get posts hashtag
|
|
|
|
* @return
|
2018-02-19 16:27:09 +01:00
|
|
|
* @throws UnsupportedEncodingException
|
2017-10-21 22:35:21 +02:00
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getHashtagPosts(String hashtag) throws UnsupportedEncodingException{
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
Validate.isTrue(hashtag != null, "hashtag cannot be null");
|
|
|
|
|
|
|
|
logger.debug("Request for getting posts with hashtag " + hashtag);
|
|
|
|
String thisMethodSignature = "get-posts-by-hashtag";
|
2018-02-19 16:27:09 +01:00
|
|
|
String request = getServiceEndpoint() + thisMethodSignature + "?hashtag=" + URLEncoder.encode(hashtag, "UTF-8");
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
2018-02-16 19:22:14 +01:00
|
|
|
|
2017-10-21 22:35:21 +02:00
|
|
|
/**
|
|
|
|
* Get liked posts
|
|
|
|
* @return
|
|
|
|
*/
|
2022-10-20 14:38:36 +02:00
|
|
|
public List<Post> getUserLikedPost(){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
logger.debug("Request for getting posts liked");
|
|
|
|
String thisMethodSignature = "get-liked-posts";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2022-10-20 14:38:36 +02:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get liked posts ids
|
|
|
|
* @return
|
|
|
|
*/
|
2018-02-19 16:27:09 +01:00
|
|
|
public List<String> getUserLikedPostIds(){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
logger.debug("Request for getting posts liked");
|
|
|
|
String thisMethodSignature = "get-id-liked-posts";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2018-02-17 18:51:38 +01:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|