Author will be in the form <Surname Name> #21479

This commit is contained in:
Luca Frosini 2021-06-21 15:24:22 +02:00
parent 1d81da329a
commit dfe711f419
4 changed files with 33 additions and 10 deletions

View File

@ -254,12 +254,13 @@ public class CKANPackage extends CKAN {
objectNode.remove(CAPACITY_KEY);
}
String authorName = ckanUser.getPortalUser().getFullName();
PortalUser portalUser = ckanUser.getPortalUser();
String authorName = String.format("%s %s", portalUser.getSurname(), portalUser.getName());
if(authorName==null || authorName.compareTo("")==0) {
authorName = ckanUser.getName();
}
objectNode.put(AUTHOR_KEY, authorName);
String authorEmail = ckanUser.getPortalUser().getEMail();
String authorEmail = portalUser.getEMail();
objectNode.put(AUTHOR_EMAIL_KEY, authorEmail);

View File

@ -100,7 +100,7 @@ public class CKANUser extends CKAN {
* @return true if the display name and the full name has been updated in objectNode
*/
private boolean checkAndSetFullName(ObjectNode objectNode) {
String portalFullname = getPortalUser().getFullName();
String portalFullname = getPortalUser().getSurnameName();
String ckanFullname = "";
if(objectNode.has(FULL_NAME)) {

View File

@ -30,7 +30,11 @@ public class PortalUser {
protected static final String SOCIAL_SERVICE_GET_OAUTH_USER_PROFILE_PATH = "2/users/get-oauth-profile";
// This key contains the fullname
protected static final String OAUTH_USER_PROFILE_NAME_KEY = "name";
//protected static final String OAUTH_USER_PROFILE_FULLNAME_KEY = "name";
protected static final String OAUTH_USER_PROFILE_NAME_KEY = "given_name";
protected static final String OAUTH_USER_PROFILE_SURNAME_KEY = "family_name";
protected static final String OAUTH_USER_PROFILE_EMAIL_KEY = "email";
protected static final String OAUTH_USER_PROFILE_JOB_TITLE_KEY = "job_title";
protected static final String OAUTH_USER_PROFILE_ROLES_KEY = "roles";
@ -40,7 +44,9 @@ public class PortalUser {
// private JsonNode gCubeUserProfile;
protected JsonNode oAuthUserProfile;
protected String fullName;
protected String name;
protected String surname;
protected String eMail;
protected String jobTitle;
@ -95,11 +101,26 @@ public class PortalUser {
return oAuthUserProfile;
}
public String getFullName() {
if(fullName == null) {
fullName = getOAuthUserProfile().get(OAUTH_USER_PROFILE_NAME_KEY).asText();
public String getSurnameName() {
return String.format("%s %s", getSurname(), getName());
}
return fullName;
public String getNameSurname() {
return String.format("%s %s", getName(), getSurname());
}
public String getName() {
if(name == null) {
name = getOAuthUserProfile().get(OAUTH_USER_PROFILE_NAME_KEY).asText();
}
return name;
}
public String getSurname() {
if(surname == null) {
surname = getOAuthUserProfile().get(OAUTH_USER_PROFILE_SURNAME_KEY).asText();
}
return surname;
}
public String getEMail() {

View File

@ -128,7 +128,8 @@ public class SocialPost extends Thread {
public void sendSocialPost(boolean notifyUsers) {
try {
String fullName = CKANUserCache.getCurrrentCKANUser().getPortalUser().getFullName();
PortalUser portalUser = CKANUserCache.getCurrrentCKANUser().getPortalUser();
String fullName = portalUser.getNameSurname();
String basePath = SocialService.getSocialService().getServiceBasePath();
if(basePath == null) {