179 lines
5.1 KiB
Java
179 lines
5.1 KiB
Java
|
package org.gcube.portal.social_networking_client_library;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
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.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
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
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 ArrayList<Feed>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get all posts
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
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 ArrayList<Feed>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get posts quantity
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
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 ArrayList<Feed>(0).getClass(), 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(Feed.class, request, SecurityTokenProvider.instance.get(), toWrite);
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get posts application (token set must belong to the application)
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
public List<Feed> getAllApplicationPosts(){
|
||
|
|
||
|
logger.debug("Request for getting posts");
|
||
|
String thisMethodSignature = "get-posts-app";
|
||
|
String request = getServiceEndpoint() + thisMethodSignature;
|
||
|
return HttpClient.get(new ArrayList<Feed>(0).getClass(), 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(Feed.class, request, SecurityTokenProvider.instance.get(), toWrite);
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get posts vre
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
public List<Feed> getPostsVRE(){
|
||
|
|
||
|
logger.debug("Request for getting posts vre");
|
||
|
String thisMethodSignature = "get-posts-vre";
|
||
|
String request = getServiceEndpoint() + thisMethodSignature;
|
||
|
return HttpClient.get(new ArrayList<Feed>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get posts hashtag
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
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 ArrayList<Feed>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get liked posts
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
public List<Feed> getLikedPost(){
|
||
|
|
||
|
logger.debug("Request for getting posts liked");
|
||
|
String thisMethodSignature = "get-liked-posts";
|
||
|
String request = getServiceEndpoint() + thisMethodSignature;
|
||
|
return HttpClient.get(new ArrayList<String>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get liked posts ids
|
||
|
* @return
|
||
|
*/
|
||
|
@SuppressWarnings("unchecked")
|
||
|
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 ArrayList<String>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|