minor fixes

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-networking-client-library@163387 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-19 15:27:09 +00:00
parent 6a4a66047f
commit e352f90963
14 changed files with 295 additions and 106 deletions

View File

@ -17,6 +17,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -78,11 +78,6 @@
<artifactId>social-networking-service-model</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>javax.ws.rs</groupId> -->
<!-- <artifactId>javax.ws.rs-api</artifactId> -->
<!-- <version>${jaxrs.version}</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>

View File

@ -14,16 +14,16 @@ import org.slf4j.LoggerFactory;
* HashTags client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class HashTagsClient extends BaseClient{
public class HashTagClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/hashtags/";
private static Logger logger = LoggerFactory.getLogger(HashTagsClient.class);
public HashTagsClient() throws Exception {
private static Logger logger = LoggerFactory.getLogger(HashTagClient.class);
public HashTagClient() throws Exception {
super(SUB_SERVICE_PATH);
}
/**
* Get hashtags and their count
* @return a map of type hashtag -> number
@ -34,6 +34,5 @@ public class HashTagsClient extends BaseClient{
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<HashMap<String, Integer>>>(){}, request);
}
}

View File

@ -7,7 +7,7 @@ import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.input.Message;
import org.gcube.portal.socialnetworking.model.beans.Message;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,13 +16,13 @@ import org.slf4j.LoggerFactory;
* Messages client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class MessagesClient extends BaseClient{
public class MessageClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/messages/";
private static Logger logger = LoggerFactory.getLogger(MessagesClient.class);
private static Logger logger = LoggerFactory.getLogger(MessageClient.class);
public MessagesClient() throws Exception {
public MessageClient() throws Exception {
super(SUB_SERVICE_PATH);
}

View File

@ -8,7 +8,7 @@ import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.input.JobNotificationBean;
import org.gcube.portal.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,13 +17,13 @@ import org.slf4j.LoggerFactory;
* Notifications client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class NotificationsClient extends BaseClient{
public class NotificationClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/notifications/";
private static Logger logger = LoggerFactory.getLogger(NotificationsClient.class);
private static Logger logger = LoggerFactory.getLogger(NotificationClient.class);
public NotificationsClient() throws Exception {
public NotificationClient() throws Exception {
super(SUB_SERVICE_PATH);
}

View File

@ -3,8 +3,8 @@ package org.gcube.portal.social_networking_client_library;
import javax.ws.rs.core.GenericType;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.beans.UserProfile;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
public class PeopleClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/people/";
private static Logger logger = LoggerFactory.getLogger(NotificationsClient.class);
private static Logger logger = LoggerFactory.getLogger(NotificationClient.class);
public PeopleClient() throws Exception {
@ -26,12 +26,12 @@ public class PeopleClient extends BaseClient{
* Get profile
* @return user's profile
*/
public JSONObject getProfile(){
public UserProfile getProfile(){
logger.debug("Request for getting profile");
String thisMethodSignature = "profile";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<JSONObject>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<UserProfile>>(){}, request);
}
}

View File

@ -1,5 +1,7 @@
package org.gcube.portal.social_networking_client_library;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@ -8,7 +10,7 @@ import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
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.beans.PostInputBean;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,13 +19,13 @@ import org.slf4j.LoggerFactory;
* Posts client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class PostsClient extends BaseClient{
public class PostClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/posts/";
private static Logger logger = LoggerFactory.getLogger(PostsClient.class);
private static Logger logger = LoggerFactory.getLogger(PostClient.class);
public PostsClient() throws Exception {
public PostClient() throws Exception {
super(SUB_SERVICE_PATH);
}
@ -31,13 +33,13 @@ public class PostsClient extends BaseClient{
* Get posts since date
* @return
*/
public List<Feed> getPostsSinceDate(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;
String request = getServiceEndpoint() + thisMethodSignature + "?time=" + timeInMillis;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -46,9 +48,7 @@ public class PostsClient extends BaseClient{
* Get all posts
* @return
*/
public List<Feed> getAllPosts(long timeInMillis){
Validate.isTrue(timeInMillis >= 0, "time cannot be negative");
public List<Feed> getAllUserPosts(){
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user";
@ -61,13 +61,13 @@ public class PostsClient extends BaseClient{
* Get posts quantity
* @return
*/
public List<Feed> getPostsQuantity(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;
String request = getServiceEndpoint() + thisMethodSignature + "?quantity=" + quantity;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -76,7 +76,7 @@ public class PostsClient extends BaseClient{
* Write post
* @return
*/
public Feed write(PostInputBean toWrite){
public Feed writeUserPost(PostInputBean toWrite){
Validate.isTrue(toWrite != null, "Post to write cannot be null");
@ -131,14 +131,15 @@ public class PostsClient extends BaseClient{
/**
* Get posts hashtag
* @return
* @throws UnsupportedEncodingException
*/
public List<Feed> getHashtagPosts(String hashtag){
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;
String request = getServiceEndpoint() + thisMethodSignature + "?hashtag=" + URLEncoder.encode(hashtag, "UTF-8");
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
}
@ -147,7 +148,7 @@ public class PostsClient extends BaseClient{
* Get liked posts
* @return
*/
public List<Feed> getLikedPost(){
public List<Feed> getUserLikedPost(){
logger.debug("Request for getting posts liked");
String thisMethodSignature = "get-liked-posts";
@ -160,7 +161,7 @@ public class PostsClient extends BaseClient{
* Get liked posts ids
* @return
*/
public List<String> getLikedPostIds(){
public List<String> getUserLikedPostIds(){
logger.debug("Request for getting posts liked");
String thisMethodSignature = "get-id-liked-posts";

View File

@ -4,7 +4,7 @@ import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.input.ApplicationId;
import org.gcube.portal.socialnetworking.model.beans.ApplicationId;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,13 +13,13 @@ import org.slf4j.LoggerFactory;
* Tokens client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class TokensClient extends BaseClient{
public class TokenClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/tokens/";
private static Logger logger = LoggerFactory.getLogger(TokensClient.class);
private static Logger logger = LoggerFactory.getLogger(TokenClient.class);
public TokensClient() throws Exception {
public TokenClient() throws Exception {
super(SUB_SERVICE_PATH);
}

View File

@ -9,8 +9,8 @@ import javax.ws.rs.core.GenericType;
import org.apache.commons.lang.Validate;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.beans.UserProfileExtended;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -18,13 +18,13 @@ import org.slf4j.LoggerFactory;
* Users client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class UsersClient extends BaseClient{
public class UserClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/users/";
private static Logger logger = LoggerFactory.getLogger(UsersClient.class);
private static Logger logger = LoggerFactory.getLogger(UserClient.class);
public UsersClient() throws Exception {
public UserClient() throws Exception {
super(SUB_SERVICE_PATH);
}
@ -73,12 +73,12 @@ public class UsersClient extends BaseClient{
* Get profile
* @return
*/
public JSONObject getProfile(){
public UserProfileExtended getProfile(){
logger.debug("Request for getting profile");
String thisMethodSignature = "get-profile";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<JSONObject>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<UserProfileExtended>>(){}, request);
}

View File

@ -1,10 +1,12 @@
package org.gcube.portal.social_networking_client_library;
import java.util.List;
import javax.ws.rs.core.GenericType;
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
import org.gcube.portal.socialnetworking.model.beans.MyVRE;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -12,13 +14,13 @@ import org.slf4j.LoggerFactory;
* Vres client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class VREsClient extends BaseClient{
public class VREClient extends BaseClient{
private static final String SUB_SERVICE_PATH = "2/vres/";
private static Logger logger = LoggerFactory.getLogger(VREsClient.class);
private static Logger logger = LoggerFactory.getLogger(VREClient.class);
public VREsClient() throws Exception {
public VREClient() throws Exception {
super(SUB_SERVICE_PATH);
}
@ -26,12 +28,12 @@ public class VREsClient extends BaseClient{
* Get my Vres
* @return my vres
*/
public JSONArray getMyVRES(){
public List<MyVRE> getMyVRES(boolean retrieveManagers){
logger.debug("Request for writing new message");
String thisMethodSignature = "get-my-vres";
String request = getServiceEndpoint() + thisMethodSignature + "?";
return HttpClient.get(new GenericType<ResponseBean<JSONArray>>(){}, request);
String request = getServiceEndpoint() + thisMethodSignature + "?" + "getManagers=" + retrieveManagers;
return HttpClient.get(new GenericType<ResponseBean<List<MyVRE>>>(){}, request);
}

View File

@ -3,19 +3,24 @@ package org.gcube.portal.social_networking_client_library.filter;
import java.io.IOException;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Authorization filter for the jersey client.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AuthorizationFilter {
public class AuthorizationFilter implements ClientRequestFilter{
private final static String AUTH_TOKEN_PARAMETER = "gcube-token";
private static Logger logger = LoggerFactory.getLogger(AuthorizationFilter.class);
public void filter(ClientRequestContext clientRequestContext) throws IOException {
@Override
public void filter(ClientRequestContext original) throws IOException {
logger.debug("Adding token to the request " + original.getUri());
String token = SecurityTokenProvider.instance.get();
clientRequestContext.getHeaders().add(AUTH_TOKEN_PARAMETER, token);
original.getHeaders().add(AUTH_TOKEN_PARAMETER, token);
}
}

View File

@ -7,7 +7,9 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.portal.social.networking.model.providers.CustomObjectMapper;
import org.gcube.portal.social_networking_client_library.filter.AuthorizationFilter;
import org.gcube.portal.socialnetworking.model.output.ResponseBean;
import org.glassfish.jersey.client.ClientConfig;
@ -15,10 +17,8 @@ import org.glassfish.jersey.jackson.JacksonFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* Http client with post and get methods (jersey is used)
* Jersey client with post and get methods
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class HttpClient{
@ -27,61 +27,63 @@ public class HttpClient{
/**
* Executes a get request
* @param genericType
* @param genericType
* @param genericType
* @param returnType
* @param requestUrl
* @param token
* @return
*/
public static <R> R get(GenericType<ResponseBean<R>> returnType, String requestUrl){
logger.debug("Executing get request at url " + requestUrl);
ClientConfig cc = new ClientConfig().register(new JacksonFeature()).register(new AuthorizationFilter());
ClientConfig cc = new ClientConfig().register(new JacksonFeature()).register(new AuthorizationFilter()).register(new CustomObjectMapper());
Client client = ClientBuilder.newClient(cc);
WebTarget webResourceGet = client.target(requestUrl);
ResponseBean<R> response = webResourceGet.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get(returnType);
Response response = webResourceGet.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get();
if(response == null)
throw new WebApplicationException("Response returned by the service is null");
if (response.getMessage() != null && !response.getMessage().isEmpty())
throw new WebApplicationException(
"Error message is " + response.getMessage());
if(response.getStatus() >= 300)
throw new WebApplicationException("There was an error at server side: " + response.getStatusInfo());
return response.getResult();
ResponseBean<R> result = response.readEntity(returnType);
if (!result.isSuccess())
throw new WebApplicationException(
"Error message is " + result.getMessage());
return result.getResult();
}
/**
* Executes a post request
* @param returnType
* @param requestUrl
* @param token
* @param body
* @param obj
* @return
* @throws JsonProcessingException
*/
public static <R> R post(GenericType<ResponseBean<R>> returnType, String requestUrl, Object obj){
logger.debug("Executing post request at url " + requestUrl);
ClientConfig cc = new ClientConfig().register(new JacksonFeature()).register(new AuthorizationFilter());
ClientConfig cc = new ClientConfig().register(new JacksonFeature()).register(new AuthorizationFilter()).register(new CustomObjectMapper());;
Client client = ClientBuilder.newClient(cc);
WebTarget webResourceGet = client.target(requestUrl);
logger.debug("Entity looks like " + Entity.json(obj));
ResponseBean<R> response = webResourceGet.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(Entity.json(obj), returnType);
Response response = webResourceGet.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(Entity.json(obj));
if(response == null)
throw new WebApplicationException("Response returned by the service is null");
if (response.getMessage() != null && !response.getMessage().isEmpty())
throw new WebApplicationException(
"Error message is " + response.getMessage());
if(response.getStatus() >= 300)
throw new WebApplicationException("There was an error at server side: " + response.getStatusInfo());
return response.getResult();
ResponseBean<R> result = response.readEntity(returnType);
if (!result.isSuccess())
throw new WebApplicationException(
"Error message is " + result.getMessage());
return result.getResult();
}
}

View File

@ -16,6 +16,10 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Discovers the social networking service endpoint in a given context
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ServiceDiscoverer {
private static final String resource = "jersey-servlet";
@ -38,7 +42,7 @@ public class ServiceDiscoverer {
try{
logger.info("set scope "+currentScope);
logger.debug("set scope "+currentScope);
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));

View File

@ -9,14 +9,17 @@ import java.util.UUID;
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.JobStatusType;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.socialnetworking.model.input.ApplicationId;
import org.gcube.portal.socialnetworking.model.input.JobNotificationBean;
import org.gcube.portal.socialnetworking.model.input.Message;
import org.gcube.portal.socialnetworking.model.input.Recipient;
import org.json.JSONArray;
import org.json.JSONObject;
import org.gcube.portal.socialnetworking.model.beans.ApplicationId;
import org.gcube.portal.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.portal.socialnetworking.model.beans.Message;
import org.gcube.portal.socialnetworking.model.beans.MyVRE;
import org.gcube.portal.socialnetworking.model.beans.PostInputBean;
import org.gcube.portal.socialnetworking.model.beans.Recipient;
import org.gcube.portal.socialnetworking.model.beans.UserProfile;
import org.gcube.portal.socialnetworking.model.beans.UserProfileExtended;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
@ -30,7 +33,7 @@ public class TestClientServices {
public void setContextAndToken(){
ScopeProvider.instance.set("/gcube/devNext/NextNext");
SecurityTokenProvider.instance.set("d423aed7-e9e2-424a-b9e7-2bbbd151d9c4-98187548");
SecurityTokenProvider.instance.set("...");
}
@ -56,14 +59,14 @@ public class TestClientServices {
//@Test
public void testHashTags() throws Exception {
HashTagsClient hashtags = new HashTagsClient();
HashTagClient hashtags = new HashTagClient();
Map<String, Integer> hashtagsCount = hashtags.getHashtagsCount();
logger.debug("Returned tags " + hashtagsCount);
}
//@Test
public void testMessagesReceived() throws Exception {
MessagesClient messagesClient = new MessagesClient();
MessageClient messagesClient = new MessageClient();
List<Message> receivedMessages = messagesClient.getReceivedMessages();
for (Message workspaceMessage : receivedMessages) {
logger.debug("Received message " + workspaceMessage.toString());
@ -72,7 +75,7 @@ public class TestClientServices {
//@Test
public void testMessagesSent() throws Exception {
MessagesClient messagesClient = new MessagesClient();
MessageClient messagesClient = new MessageClient();
List<Message> sentMessages = messagesClient.getSentMessages();
for (Message workspaceMessage : sentMessages) {
logger.debug("Sent message was " + workspaceMessage);
@ -82,7 +85,7 @@ public class TestClientServices {
//@Test
public void sendMessage() throws Exception{
logger.debug("Sending message ");
MessagesClient messagesClient = new MessagesClient();
MessageClient messagesClient = new MessageClient();
List<Recipient> rec = Arrays.asList(new Recipient("andrea.rossi"));
Message message = new Message(
"Test message",
@ -94,7 +97,7 @@ public class TestClientServices {
//@Test
public void testNotifications() throws Exception {
NotificationsClient notificationsClient = new NotificationsClient();
NotificationClient notificationsClient = new NotificationClient();
List<Notification> latestNotifications = notificationsClient.getNotifications(1, 2);
for (Notification notification : latestNotifications) {
logger.debug("Notification is " + notification);
@ -103,7 +106,7 @@ public class TestClientServices {
//@Test
public void sendJobNotification() throws Exception {
NotificationsClient notificationsClient = new NotificationsClient();
NotificationClient notificationsClient = new NotificationClient();
JobNotificationBean notification = new JobNotificationBean(
"costantino.perciante",
UUID.randomUUID().toString(),
@ -118,24 +121,198 @@ public class TestClientServices {
//@Test
public void getProfile() throws Exception {
PeopleClient getProfile = new PeopleClient();
JSONObject profile = getProfile.getProfile();
UserProfile profile = getProfile.getProfile();
logger.debug("Profile retrieved is " + profile);
}
//@Test
public void generateAppToken() throws Exception {
TokensClient tokenClient = new TokensClient();
String token = tokenClient.generateApplicationToken(new ApplicationId("test_app"));
TokenClient tokenClient = new TokenClient();
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
logger.debug("Generated token is " + token);
}
//@Test
public void getMyVres() throws Exception{
VREsClient myVresClient = new VREsClient();
JSONArray myVres = myVresClient.getMyVRES();
VREClient myVresClient = new VREClient();
List<MyVRE> myVres = myVresClient.getMyVRES(false);
logger.debug("My Vres " + myVres);
}
//@Test
public void UsersClientTests() throws Exception{
UserClient userClient = new UserClient();
// 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());
logger.debug("Vre Managers are " + vreManagers);
String myEmail = userClient.getEmail();
assert(myEmail != null && !myEmail.isEmpty());
logger.debug("My email is " + myEmail);
String fullname = userClient.getFullName();
assert(fullname != null && !fullname.isEmpty());
logger.debug("My fullname is " + fullname);
String industry = userClient.getCustomAttribute("Industry");
assert(industry != null && !industry.isEmpty());
logger.debug("My Industry is " + industry);
List<String> usernamesInThisContext = userClient.getAllUsernamesContext();
assert(usernamesInThisContext != null && !usernamesInThisContext.isEmpty());
logger.debug("List of usernames in this context is " + usernamesInThisContext);
Map<String, String> usernamesFullnameInThisContext = userClient.getAllUsernamesFullnamesContext();
assert(usernamesFullnameInThisContext != null && !usernamesFullnameInThisContext.isEmpty());
logger.debug("List of tuples usernames/fullnames in this context is " + usernamesFullnameInThisContext);
UserProfileExtended profile = userClient.getProfile();
assert(profile != null);
logger.debug("My wonderful profile is " + profile);
// Requires application token bound to the root context
// Boolean userExists = userClient.userExists("andrea.rossi");
//
// assert(userExists != null && userExists == true);
//
// logger.debug("does Andrea Rossi exist? " + userExists);
}
//@Test
public void getUserPostsSinceDate() throws Exception{
PostClient postClient = new PostClient();
List<Feed> sinceLastYearPost = postClient.getUserPostsSinceDate(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 12);
logger.debug("Posts are " + sinceLastYearPost);
}
//@Test
public void getAllUserPosts() throws Exception{
PostClient postClient = new PostClient();
List<Feed> allposts = postClient.getAllUserPosts();
logger.debug("All posts are " + allposts);
}
//@Test
public void getUserPostsQuantity() throws Exception{
PostClient postClient = new PostClient();
List<Feed> quantityPosts = postClient.getUserPostsQuantity(3);
logger.debug("Some posts are " + quantityPosts);
}
//@Test
public void writeUserPost() throws Exception{
PostClient postClient = new PostClient();
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);
}
//@Test
public void getAllApplicationPosts() throws Exception{
TokenClient tokenClient = new TokenClient();
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
logger.debug("Generated token is " + token);
String currentToken = SecurityTokenProvider.instance.get();
SecurityTokenProvider.instance.set(token);
PostClient postClient = new PostClient();
List<Feed> applicationPosts = postClient.getAllApplicationPosts();
logger.debug("Application posts are " + applicationPosts);
SecurityTokenProvider.instance.set(currentToken);
}
//@Test
public void writeApplicationPost() throws Exception{
TokenClient tokenClient = new TokenClient();
String token = tokenClient.generateApplicationToken(new ApplicationId("org.gcube.datacatalogue.GRSFNotifier"));
logger.debug("Generated token is " + token);
String currentToken = SecurityTokenProvider.instance.get();
SecurityTokenProvider.instance.set(token);
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);
Feed written = postClient.writeApplicationPost(toWrite);
logger.debug("Written post is " + written);
SecurityTokenProvider.instance.set(currentToken);
}
//@Test
public void getPostsVRE() throws Exception{
PostClient postClient = new PostClient();
List<Feed> vrePosts = postClient.getPostsVRE();
logger.debug("VRE posts are " + vrePosts);
}
//@Test
public void getHashtagPosts() throws Exception{
PostClient postClient = new PostClient();
List<Feed> postsWithHashtag = postClient.getHashtagPosts("#connect");
logger.debug("Posts with hashtag #connect are " + postsWithHashtag);
}
//@Test
public void getUserLikedPost() throws Exception{
PostClient postClient = new PostClient();
List<Feed> postsLiked = postClient.getUserLikedPost();
logger.debug("Posts liked are " + postsLiked);
}
//@Test
public void getUserLikedPostIds() throws Exception{
PostClient postClient = new PostClient();
List<String> postsLikedIds = postClient.getUserLikedPostIds();
logger.debug("Posts liked's ids are " + postsLikedIds);
}
@After
public void reset(){
ScopeProvider.instance.reset();