social-service-client/src/main/java/org/gcube/portal/social_networking_client_li.../PostsClient.java

174 lines
5.2 KiB
Java

package org.gcube.portal.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.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.input.PostInputBean;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Posts client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class PostsClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/posts/";
private static Logger logger = LoggerFactory.getLogger(PostsClient.class);
public PostsClient() throws Exception {
super(SUB_SERVICE_PATH);
}
/**
* Get posts since date
* @return
*/
public List<Feed> getPostsSinceDate(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;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Get all posts
* @return
*/
public List<Feed> getAllPosts(long timeInMillis){
Validate.isTrue(timeInMillis >= 0, "time cannot be negative");
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Get posts quantity
* @return
*/
public List<Feed> getPostsQuantity(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;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Write post
* @return
*/
public Feed write(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<Feed>>(){}, request, SecurityTokenProvider.instance.get(), toWrite);
}
/**
* Get posts application (token set must belong to the application)
* @return
*/
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<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Write post application (token set must belong to the application)
* @return
*/
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<Feed>>(){}, request, SecurityTokenProvider.instance.get(), toWrite);
}
/**
* Get posts vre
* @return
*/
public List<Feed> getPostsVRE(){
logger.debug("Request for getting posts vre");
String thisMethodSignature = "get-posts-vre";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Get posts hashtag
* @return
*/
public List<Feed> getHashtagPosts(String hashtag){
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;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Get liked posts
* @return
*/
public List<Feed> getLikedPost(){
logger.debug("Request for getting posts liked");
String thisMethodSignature = "get-liked-posts";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request, SecurityTokenProvider.instance.get());
}
/**
* Get liked posts ids
* @return
*/
public List<String> getLikedPostIds(){
logger.debug("Request for getting posts liked");
String thisMethodSignature = "get-id-liked-posts";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request, SecurityTokenProvider.instance.get());
}
}