feature #23887 implemented
This commit is contained in:
parent
6baee4ca85
commit
34dc31ced0
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## [v1.1.1-SNAPSHOT] - 2022-09-06
|
||||
|
||||
- Minor fix on a megthod name
|
||||
|
||||
## [v1.1.0] - 2022-04-06
|
||||
|
||||
- First release
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.social-networking</groupId>
|
||||
<artifactId>social-service-client</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<name>social-networking-service-client</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>The social networking web service client library</description>
|
||||
|
@ -20,14 +20,14 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>2.1.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -65,7 +65,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.social-networking</groupId>
|
||||
<artifactId>social-service-model</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0)</version>
|
||||
<version>[1.0.0, 2.0.0)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
|
|
|
@ -2,8 +2,10 @@ package org.gcube.social_networking.social_networking_client_library;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.core.GenericType;
|
||||
|
||||
|
@ -27,130 +29,146 @@ public class UserClient extends BaseClient{
|
|||
public UserClient() throws Exception {
|
||||
super(SUB_SERVICE_PATH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get attribute value
|
||||
* @return
|
||||
*/
|
||||
public String getCustomAttribute(String attributeKey){
|
||||
|
||||
|
||||
Validate.isTrue(attributeKey != null, "attribute key cannot be null");
|
||||
|
||||
|
||||
logger.debug("Request for attribute value");
|
||||
String thisMethodSignature = "get-custom-attribute";
|
||||
String request = getServiceEndpoint() + thisMethodSignature + "?attribute=" + attributeKey;
|
||||
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get fullname
|
||||
* @return user's fullname
|
||||
*/
|
||||
public String getFullName(){
|
||||
|
||||
|
||||
logger.debug("Request for fullname");
|
||||
String thisMethodSignature = "get-fullname";
|
||||
String request = getServiceEndpoint() + thisMethodSignature;
|
||||
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get email
|
||||
* @return users'email
|
||||
*/
|
||||
public String getEmail(){
|
||||
|
||||
|
||||
logger.debug("Request for email");
|
||||
String thisMethodSignature = "get-email";
|
||||
String request = getServiceEndpoint() + thisMethodSignature;
|
||||
return HttpClient.get(new GenericType<ResponseBean<String>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get profile
|
||||
* @return
|
||||
*/
|
||||
public UserProfileExtended getProfile(){
|
||||
|
||||
|
||||
logger.debug("Request for getting profile");
|
||||
String thisMethodSignature = "get-profile";
|
||||
String request = getServiceEndpoint() + thisMethodSignature;
|
||||
return HttpClient.get(new GenericType<ResponseBean<UserProfileExtended>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all usernames in this context
|
||||
* @return
|
||||
*/
|
||||
public List<String> getAllUsernamesContext(){
|
||||
|
||||
|
||||
logger.debug("Request for getting usernames in this context");
|
||||
String thisMethodSignature = "get-all-usernames";
|
||||
String request = getServiceEndpoint() + thisMethodSignature;
|
||||
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all usernames and fullnames in this context
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getAllUsernamesFullnamesContext(){
|
||||
|
||||
|
||||
logger.debug("Request for getting usernames and fullnames in this context");
|
||||
String thisMethodSignature = "get-all-fullnames-and-usernames";
|
||||
String request = getServiceEndpoint() + thisMethodSignature;
|
||||
return HttpClient.get(new GenericType<ResponseBean<HashMap<String, String>>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get usernames by global role
|
||||
* @return
|
||||
*/
|
||||
public List<String> getAllUsernamesByGlobalRole(String globalRole){
|
||||
|
||||
|
||||
Validate.isTrue(globalRole != null, "role cannot be null");
|
||||
|
||||
|
||||
logger.debug("Request for getting usernames with global role");
|
||||
String thisMethodSignature = "get-usernames-by-global-role";
|
||||
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + globalRole;
|
||||
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get usernames by local role
|
||||
* @return
|
||||
* Get usernames by role
|
||||
* @deprecated use #getAllUsernamesByRole(String rolename) instead
|
||||
* @return the usernames having such role
|
||||
*/
|
||||
@Deprecated
|
||||
public List<String> getAllUsernamesByLocalRole(String localRole){
|
||||
|
||||
|
||||
Validate.isTrue(localRole != null, "role cannot be null");
|
||||
|
||||
|
||||
logger.debug("Request for getting usernames with global role");
|
||||
String thisMethodSignature = "get-usernames-by-role";
|
||||
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + localRole;
|
||||
return HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get usernames by role, the environment (i.e. VRE/VLab) is inferred from the token
|
||||
* @return the usernames having such role
|
||||
*/
|
||||
public Set<String>getAllUsernamesByRole(String rolename){
|
||||
Validate.isTrue(rolename != null, "role cannot be null");
|
||||
|
||||
logger.debug("Request for getting usernames with global role");
|
||||
String thisMethodSignature = "get-usernames-by-role";
|
||||
String request = getServiceEndpoint() + thisMethodSignature + "?role-name=" + rolename;
|
||||
ArrayList<String> sourceList = HttpClient.get(new GenericType<ResponseBean<ArrayList<String>>>(){}, request);
|
||||
Set<String> usernames = new HashSet<>(sourceList);
|
||||
return usernames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user exists
|
||||
* @return
|
||||
*/
|
||||
public Boolean userExists(String username){
|
||||
|
||||
|
||||
Validate.isTrue(username != null, "username cannot be null");
|
||||
|
||||
|
||||
logger.debug("Request for getting usernames with global role");
|
||||
String thisMethodSignature = "user-exists";
|
||||
String request = getServiceEndpoint() + thisMethodSignature + "?username=" + username;
|
||||
return HttpClient.get(new GenericType<ResponseBean<Boolean>>(){}, request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
|
@ -53,8 +54,8 @@ public class TestClientServices {
|
|||
public void setContextAndToken(){
|
||||
|
||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/gCube");
|
||||
String umaToken = "";
|
||||
//AccessTokenProvider.instance.set(umaToken);
|
||||
String umaToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJySUJPYjZZY3p2ZE4xNVpuNHFkUTRLdEQ5VUhyY1dwNWJCT3Na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m8iLCJmYW1pbHlfbmFtZSI6IkFzc2FudGUiLCJlbWFpbCI6Im1hc3NpbWlsaWFuby5hc3NhbnRlQGlzdGkuY25yLml0In0.KIxC9QYGZCp6jAdye_82q648JjZli9KMxe-lqyFWkuA-HaZ-Ig2lWyn747iKp3UmstQgCTTonmOsVANHp1Feu_U1CuiWqRZ8OhmrTj8Q5v-FKwVtN2GfbjOF9b4aMXySFPd1HtCGHJ4o57uUrIQvvOV_SJOK5SOjG0YzOmsrOcXzSPl97ZZLKwio-Py0rxN6fdK8Obx7TL1eGgllhAI7ZDFRfoZrbz-F1YL1IPlQ6RI76rb7sbt6oL-T6LirP92AmUaW_nTLBBqrFR7uCaZdZKIDd4zxBmyzXjkNHncMKg8yFl-i1SRe58EcucMwEN0O-kUkhIb2CzaClsiWcLjP5g";
|
||||
AccessTokenProvider.instance.set(umaToken);
|
||||
SecurityTokenProvider.instance.set("");
|
||||
}
|
||||
|
||||
|
@ -205,19 +206,9 @@ public class TestClientServices {
|
|||
public void TestUsersClient() 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);
|
||||
Set<String> vreManagers = userClient.getAllUsernamesByRole("Data-Manager");
|
||||
assert(vreManagers != null && !vreManagers.isEmpty());
|
||||
System.out.println("Data Managers are " + vreManagers);
|
||||
|
||||
String myEmail = userClient.getEmail();
|
||||
|
||||
|
|
Loading…
Reference in New Issue