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() { protected boolean isModerationEnabled() {
boolean moderationEnabled = configuration.isModerationEnabled(); boolean moderationEnabled = configuration.isModerationEnabled();
if(moderationEnabled && moderationThread==null) { 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_VISIBILITY, cmItemVisibility.getValue());
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_AUTHOR, ckanUser.getName()); 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); ((ObjectNode) jsonNode).put(PRIVATE_KEY, true);
/* /*
@ -1526,8 +1536,7 @@ public class CKANPackage extends CKAN implements Moderated {
if(scopeBean.is(Type.VRE)) { if(scopeBean.is(Type.VRE)) {
// Actions performed after a package has been correctly created on ckan. // Actions performed after a package has been correctly created on ckan.
String gcubeUsername = CKANUser.getUsernameFromCKANUsername(moderationThread.getItemAuthorCkanUsername()); String authorFullName = getItemAuthorFullName();
String authorFullName = CKANUserCache.getCKANUser(gcubeUsername).getNameSurname();
sendSocialPost(authorFullName); sendSocialPost(authorFullName);
} }

View File

@ -50,6 +50,7 @@ public class CKANUser extends CKAN {
public static final String PORTAL_ROLES = "portal_roles"; public static final String PORTAL_ROLES = "portal_roles";
protected String nameSurname;
protected Role role; protected Role role;
protected Boolean catalogueModerator; 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 * @return true if the display name and the full name has been updated in objectNode
*/ */
private boolean checkAndSetFullName(ObjectNode 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 = ""; String ckanFullname = "";
if(objectNode.has(FULL_NAME)) { if(objectNode.has(FULL_NAME)) {
@ -315,18 +318,15 @@ public class CKANUser extends CKAN {
} }
public String getSurnameName(){ public String getSurnameName(){
User user = SecretManagerProvider.instance.get().getUser(); return result.get(FULL_NAME).asText();
return user.getFullName();
} }
public String getNameSurname() { public String getNameSurname() {
User user = SecretManagerProvider.instance.get().getUser(); return nameSurname;
return user.getFullName(true);
} }
public String getEMail() { public String getEMail() {
User user = SecretManagerProvider.instance.get().getUser(); return result.get(EMAIL).asText();
return user.getEmail();
} }
} }

View File

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