Feature #23887 possibility to get-usernames-by-role in UserClient

This commit is contained in:
Massimiliano Assante 2022-10-20 14:38:36 +02:00
parent 34dc31ced0
commit de923b5f61
5 changed files with 64 additions and 35 deletions

View File

@ -18,8 +18,9 @@
<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/Java 8">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>

View File

@ -2,7 +2,7 @@
## [v1.1.1-SNAPSHOT] - 2022-09-06
- Minor fix on a megthod name
- Minor fix on a method name
## [v1.1.0] - 2022-04-06

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -9,6 +9,7 @@ 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.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;
@ -33,14 +34,14 @@ public class PostClient extends BaseClient{
* Get posts since date
* @return
*/
public List<Feed> getUserPostsSinceDate(long timeInMillis){
public List<Post> 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<Feed>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
@ -48,12 +49,12 @@ public class PostClient extends BaseClient{
* Get all posts
* @return
*/
public List<Feed> getAllUserPosts(){
public List<Post> getAllUserPosts(){
logger.debug("Request for getting posts");
String thisMethodSignature = "get-posts-user";
String request = getServiceEndpoint() + thisMethodSignature;
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Feed>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
@ -61,14 +62,14 @@ public class PostClient extends BaseClient{
* Get posts quantity
* @return
*/
public List<Feed> getUserPostsQuantity(int quantity){
public List<Post> 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<Feed>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
@ -76,14 +77,14 @@ public class PostClient extends BaseClient{
* Write post
* @return
*/
public Feed writeUserPost(PostInputBean toWrite){
public Post 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<Feed>>(){}, request, toWrite);
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
}
@ -91,12 +92,12 @@ public class PostClient extends BaseClient{
* Get posts application (token set must belong to the application)
* @return
*/
public List<Feed> getAllApplicationPosts(){
public List<Post> 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);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
@ -104,18 +105,19 @@ public class PostClient extends BaseClient{
* Write post application (token set must belong to the application)
* @return
*/
public Feed writeApplicationPost(PostInputBean toWrite){
public Post 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, toWrite);
return HttpClient.post(new GenericType<ResponseBean<Post>>(){}, request, toWrite);
}
/**
* @deprecated use List<Post> getVREPosts()
* Get posts vre
* @return
*/
@ -126,6 +128,18 @@ 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);
}
/**
@ -133,14 +147,14 @@ public class PostClient extends BaseClient{
* @return
* @throws UnsupportedEncodingException
*/
public List<Feed> getHashtagPosts(String hashtag) throws UnsupportedEncodingException{
public List<Post> 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<Feed>>>(){}, request);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}
@ -148,12 +162,12 @@ public class PostClient extends BaseClient{
* Get liked posts
* @return
*/
public List<Feed> getUserLikedPost(){
public List<Post> getUserLikedPost(){
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);
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Post>>>(){}, request);
}

View File

@ -14,6 +14,7 @@ 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;
@ -53,8 +54,10 @@ public class TestClientServices {
@Before
public void setContextAndToken(){
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/gCube");
String umaToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJySUJPYjZZY3p2ZE4xNVpuNHFkUTRLdEQ5VUhyY1dwNWJCT3NaLXpYbXM0In0.eyJleHAiOjE2NjM2NjU2NTgsImlhdCI6MTY2MzY2NTM1OCwiYXV0aF90aW1lIjoxNjYzNjY0MTg1LCJqdGkiOiIxMjNhYmY0MS1lZmE1LTQ4ZjEtYmE2Zi03MjNkOWZjNDAwMWQiLCJpc3MiOiJodHRwczovL2FjY291bnRzLmQ0c2NpZW5jZS5vcmcvYXV0aC9yZWFsbXMvZDRzY2llbmNlIiwiYXVkIjoiJTJGZDRzY2llbmNlLnJlc2VhcmNoLWluZnJhc3RydWN0dXJlcy5ldSUyRmdDdWJlQXBwcyUyRmdDdWJlIiwic3ViIjoiMzM4OGQwZjgtM2E0OS00ZGEwLWE3OGUtN2I2MjI1OTI2M2U2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoidmxhYi5pc3RpLmNuci5pdCIsInNlc3Npb25fc3RhdGUiOiI3MjRkMmJmOS00NjQ2LTQwZjAtOTY1ZC02MzFlODJiZWZkMmEiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbIi8qIl0sInJlc291cmNlX2FjY2VzcyI6eyIlMkZkNHNjaWVuY2UucmVzZWFyY2gtaW5mcmFzdHJ1Y3R1cmVzLmV1JTJGZ0N1YmVBcHBzJTJGZ0N1YmUiOnsicm9sZXMiOlsiVlJFLU1hbmFnZXIiLCJNZW1iZX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ZXIiXX0sIiUyRmdjdWJlJTJGZGV2c2VjJTJGZGV2VlJFIjp7InJvbGVzIjpbIk1lbWJlciJdfX0sImF1dGhvcml6YXRpb24iOnsicGVybWlzc2lvbnMiOlt7InJzaWQiOiI1NzI4NTUxMC0zOTM5LTRkZTctOGZjMS1lM2E5ZDNjY2UyODEiLCJyc25hbWUiOiJEZWZhdWx0IFJlc291cmNlIn1dfSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsIm5hbWUiOiJNYXNzaW1pbGlhbiBBc3NhbnRlIiwicHJlZmVycmVkX3VzZXJuYW1lIjoibWFzc2ltaWxpYW5vLmFzc2FudGUiLCJnaXZlbl9uYW1lIjoiTWFzc2ltaWxpYW4iLCJsb2NhbGUiOiJlbiIsImZhbWlseV9uYW1lIjoiQXNzYW50ZSIsImVtYWlsIjoibWFzc2ltaWxpYW5vLmFzc2FudGVAaXN0aS5jbnIuaXQifQ.IkYaHojPyKuM-xIQexIf8KDyR41-vnE8DVm7LzVfbRuPEmkprICxHIrrrnrCWTP1ZfgCfhgjlHTvzkGpGUCdM5NxtQbMcm4k4yqfbOAyJ-S0BQJGgpkA-jLYAfC-OrRPeyNul_nTpn-L0vro3-FWRfqgpS3fYGfPbxqQpGxlpqmxJ-V05vKhILkp6uXN0lcrKKuWjAO0VchgnLF0f_J6dlPdsueLKRGMIs_Xsq-RErrhe2vsbw7kt-2hZ29rNHDLcpnXtka-4LK_bVZbHhglIAn1TVPb8YPQmfooIu35fggDSY7qtXIrsJjbRlQzlVUCmjbNd-fykgoex0cojcsjaQ";
AccessTokenProvider.instance.set(umaToken);
SecurityTokenProvider.instance.set("");
}
@ -255,31 +258,39 @@ public class TestClientServices {
}
//@Test
@Test
public void getUserPostsSinceDate() throws Exception{
PostClient postClient = new PostClient();
List<Feed> sinceLastYearPost = postClient.getUserPostsSinceDate(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 12);
List<Post> 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<Feed> allposts = postClient.getAllUserPosts();
logger.debug("All posts are " + allposts);
List<Post> allposts = postClient.getAllUserPosts();
logger.debug("All posts found:");
for (Post post : allposts) {
logger.debug(post.toString());
}
}
//@Test
@Test
public void getUserPostsQuantity() throws Exception{
PostClient postClient = new PostClient();
List<Feed> quantityPosts = postClient.getUserPostsQuantity(3);
logger.debug("Some posts are " + quantityPosts);
List<Post> quantityPosts = postClient.getUserPostsQuantity(3);
logger.debug("Some posts are ");
logger.debug(quantityPosts + " posts found:");
for (Post post : quantityPosts) {
logger.debug(post.toString());
}
}
//@Test
@ -287,7 +298,7 @@ public class TestClientServices {
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);
Post written = postClient.writeUserPost(toWrite);
logger.debug("Written post is " + written);
}
@ -303,7 +314,7 @@ public class TestClientServices {
SecurityTokenProvider.instance.set(token);
PostClient postClient = new PostClient();
List<Feed> applicationPosts = postClient.getAllApplicationPosts();
List<Post> applicationPosts = postClient.getAllApplicationPosts();
logger.debug("Application posts are " + applicationPosts);
SecurityTokenProvider.instance.set(currentToken);
@ -322,7 +333,7 @@ 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);
Feed written = postClient.writeApplicationPost(toWrite);
Post written = postClient.writeApplicationPost(toWrite);
logger.debug("Written post is " + written);
SecurityTokenProvider.instance.set(currentToken);
@ -333,8 +344,11 @@ public class TestClientServices {
public void getPostsVRE() throws Exception{
PostClient postClient = new PostClient();
List<Feed> vrePosts = postClient.getPostsVRE();
logger.debug("VRE posts are " + vrePosts);
List<Post> vrePosts = postClient.getVREPosts();
logger.debug("VRE posts : ");
for (Post post : vrePosts) {
logger.debug(post.toString());
}
}
@ -342,7 +356,7 @@ public class TestClientServices {
public void getHashtagPosts() throws Exception{
PostClient postClient = new PostClient();
List<Feed> postsWithHashtag = postClient.getHashtagPosts("#connect");
List<Post> postsWithHashtag = postClient.getHashtagPosts("#connect");
logger.debug("Posts with hashtag #connect are " + postsWithHashtag);
}
@ -351,7 +365,7 @@ public class TestClientServices {
public void getUserLikedPost() throws Exception{
PostClient postClient = new PostClient();
List<Feed> postsLiked = postClient.getUserLikedPost();
List<Post> postsLiked = postClient.getUserLikedPost();
logger.debug("Posts liked are " + postsLiked);
}