Added author information to item in case of moderation

This commit is contained in:
Luca Frosini 2023-03-01 13:55:50 +01:00
parent 72a2233dbe
commit 4edbf54eb2
3 changed files with 18 additions and 15 deletions

View File

@ -1181,6 +1181,15 @@ public class CKANPackage extends CKAN implements Moderated {
}
}
protected String getItemAuthorFullName() {
String itemAuthorFullName = "";
JsonNode jsonNode = getExtraField(result, Moderated.SYSTEM_CM_ITEM_AUTHOR_FULLNAME);
if(jsonNode!=null) {
itemAuthorFullName = jsonNode.asText();
}
return itemAuthorFullName;
}
protected boolean isModerationEnabled() {
boolean moderationEnabled = configuration.isModerationEnabled();
if(moderationEnabled && moderationThread==null) {
@ -1399,6 +1408,7 @@ public class CKANPackage extends CKAN implements Moderated {
}
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_VISIBILITY, cmItemVisibility.getValue());
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_AUTHOR, ckanUser.getName());
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_AUTHOR_FULLNAME, ckanUser.getNameSurname());
((ObjectNode) jsonNode).put(PRIVATE_KEY, true);
/*
@ -1526,8 +1536,7 @@ public class CKANPackage extends CKAN implements Moderated {
if(scopeBean.is(Type.VRE)) {
// Actions performed after a package has been correctly created on ckan.
String gcubeUsername = CKANUser.getUsernameFromCKANUsername(moderationThread.getItemAuthorCkanUsername());
String authorFullName = CKANUserCache.getCKANUser(gcubeUsername).getNameSurname();
String authorFullName = getItemAuthorFullName();
sendSocialPost(authorFullName);
}

View File

@ -50,6 +50,7 @@ public class CKANUser extends CKAN {
public static final String PORTAL_ROLES = "portal_roles";
protected String nameSurname;
protected Role role;
protected Boolean catalogueModerator;
@ -111,7 +112,9 @@ 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 = getSurnameName();
User user = SecretManagerProvider.instance.get().getUser();
String portalFullname = user.getFullName();
this.nameSurname = user.getFullName(true);
String ckanFullname = "";
if(objectNode.has(FULL_NAME)) {
@ -315,18 +318,15 @@ public class CKANUser extends CKAN {
}
public String getSurnameName(){
User user = SecretManagerProvider.instance.get().getUser();
return user.getFullName();
return result.get(FULL_NAME).asText();
}
public String getNameSurname() {
User user = SecretManagerProvider.instance.get().getUser();
return user.getFullName(true);
return nameSurname;
}
public String getEMail() {
User user = SecretManagerProvider.instance.get().getUser();
return user.getEmail();
return result.get(EMAIL).asText();
}
}

View File

@ -37,11 +37,6 @@ public abstract class CKANUserCache {
public synchronized static CKANUser getCurrrentCKANUser() {
SecretManager secretManager = SecretManagerProvider.instance.get();
String gcubeUsername = secretManager.getUser().getUsername();
return getCKANUser(gcubeUsername);
}
public synchronized static CKANUser getCKANUser(String gcubeUsername) {
SecretManager secretManager = SecretManagerProvider.instance.get();
String context = secretManager.getContext();
Cache<String,CKANUser> userCache = cacheManager.getCache(context);
if(userCache == null) {
@ -51,7 +46,6 @@ public abstract class CKANUserCache {
CKANUser ckanUser = userCache.get(gcubeUsername);
if(ckanUser == null) {
ckanUser = new CKANUser();
ckanUser.setName(gcubeUsername);
ckanUser.retrieve();
userCache.put(gcubeUsername, ckanUser);
}