Compare commits

...

3 Commits

3 changed files with 40 additions and 9 deletions

View File

@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.5.5-SNAPSHOT] - 2024-04-16
- Bug #27218 fixed null pointer exception of parsing user from json
## [v2.5.4] - 2022-07-06 ## [v2.5.4] - 2022-07-06
- Feature #23622 added Catalogue-Manager and Moderator roles - Feature #23622 added Catalogue-Manager and Moderator roles

View File

@ -10,7 +10,7 @@
</parent> </parent>
<groupId>org.gcube.dvos</groupId> <groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId> <artifactId>usermanagement-core</artifactId>
<version>2.5.4</version> <version>2.5.5-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>User Management API</name> <name>User Management API</name>

View File

@ -147,8 +147,12 @@ public class LiferayWSUserManager implements UserManager{
private GCubeUser mapLRUser(String json){ private GCubeUser mapLRUser(String json){
try{ try{
if (json != null) { if (json != null) {
logger.info("user json to be parsed: " + json);
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
JSONObject userJSON = (JSONObject)parser.parse(json); JSONObject userJSON = (JSONObject)parser.parse(json);
if(userJSON!=null){
logger.info("parsed user json: " + userJSON.toString());
}
// TODO skip for now // TODO skip for now
List<Email> emails = new ArrayList<Email>(); List<Email> emails = new ArrayList<Email>();
// for (EmailAddress e : u.getEmailAddresses()) { // for (EmailAddress e : u.getEmailAddresses()) {
@ -161,15 +165,17 @@ public class LiferayWSUserManager implements UserManager{
} catch (Exception e1) { } catch (Exception e1) {
logger.warn("Failed to retrieve property " + USER_LOCATION_INDUSTRY_KEY, e1); logger.warn("Failed to retrieve property " + USER_LOCATION_INDUSTRY_KEY, e1);
} }
if(userJSON!=null){
logger.info("parsed user json: " + userJSON.toString());
}
// retrieve the contact id information (it is into the user json) // retrieve the contact id information (it is into the user json)
long contactId = (long)userJSON.get("contactId"); String jsonContact;
JSONObject contactJSON;
// retrieve contact json obj from contactId try{
String jsonContact = getContactJson(contactId); long contactId = (long)userJSON.get("contactId");
JSONObject contactJSON = (JSONObject)parser.parse(jsonContact); jsonContact = getContactJson(contactId);
contactJSON = (JSONObject)parser.parse(jsonContact);
return new GCubeUser( return new GCubeUser(
(long)userJSON.get("userId"), (long)userJSON.get("userId"),
(String)userJSON.get("screenName"), (String)userJSON.get("screenName"),
(String)userJSON.get("emailAddress"), (String)userJSON.get("emailAddress"),
@ -183,6 +189,23 @@ public class LiferayWSUserManager implements UserManager{
(String)userJSON.get("jobTitle"), (String)userJSON.get("jobTitle"),
locationIndustry, locationIndustry,
emails); emails);
}catch (Exception e) {
logger.warn("Failed to retrieve property " + "contactId", e);
return new GCubeUser(
(long)userJSON.get("userId"),
(String)userJSON.get("screenName"),
(String)userJSON.get("emailAddress"),
(String)userJSON.get("firstName"),
(String)userJSON.get("middleName"),
(String)userJSON.get("lastName"),
buildFullName(userJSON),
(long)userJSON.get("createDate"),
getUserAvatarAbsoluteURL((String)userJSON.get("uuid"), (long)userJSON.get("portraitId")), // skip for now TODO getUserAvatarAbsoluteURL(u)
false,
(String)userJSON.get("jobTitle"),
locationIndustry,
emails);
}
} }
}catch(Exception e){ }catch(Exception e){
logger.error("Exception while mapping the json user object to the GCubeUser java object", e); logger.error("Exception while mapping the json user object to the GCubeUser java object", e);
@ -287,10 +310,14 @@ public class LiferayWSUserManager implements UserManager{
@Override @Override
public GCubeUser getUserByUsername(String username) public GCubeUser getUserByUsername(String username)
throws UserManagementSystemException, UserRetrievalFault { throws UserManagementSystemException, UserRetrievalFault {
logger.info("username: " + username);
String jsonUser = String jsonUser =
HttpUtils.executeHTTPGETRequest(API_BASE_URL + GET_USER_BY_USERNAME.replace("$COMPANY_ID", String.valueOf(companyId)).replace("$USER_ID", username), HttpUtils.executeHTTPGETRequest(API_BASE_URL + GET_USER_BY_USERNAME.replace("$COMPANY_ID", String.valueOf(companyId)).replace("$USER_ID", username),
credsProvider, localContext, target); credsProvider, localContext, target);
logger.info("jsonUser: " + jsonUser);
if(jsonUser != null){ if(jsonUser != null){
logger.debug("Json user retrieved"); logger.debug("Json user retrieved");