Fixing moderator issues
This commit is contained in:
parent
29202bf152
commit
f117096847
|
@ -786,7 +786,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
return itemURL;
|
return itemURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendSocialPost() {
|
protected void sendSocialPost(String userFullName) {
|
||||||
try {
|
try {
|
||||||
boolean makePost = false;
|
boolean makePost = false;
|
||||||
try {
|
try {
|
||||||
|
@ -801,6 +801,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
if(makePost) {
|
if(makePost) {
|
||||||
ArrayNode arrayNode = (ArrayNode) result.get(TAGS_KEY);
|
ArrayNode arrayNode = (ArrayNode) result.get(TAGS_KEY);
|
||||||
SocialPost socialPost = new SocialPost();
|
SocialPost socialPost = new SocialPost();
|
||||||
|
socialPost.setUserFullName(userFullName);
|
||||||
socialPost.setItemID(itemID);
|
socialPost.setItemID(itemID);
|
||||||
socialPost.setItemURL(itemURL);
|
socialPost.setItemURL(itemURL);
|
||||||
socialPost.setItemTitle(itemTitle);
|
socialPost.setItemTitle(itemTitle);
|
||||||
|
@ -910,7 +911,8 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
if(!isModerationEnabled()) {
|
if(!isModerationEnabled()) {
|
||||||
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.
|
||||||
sendSocialPost();
|
String userFullName = CKANUserCache.getCurrrentCKANUser().getNameSurname();
|
||||||
|
sendSocialPost(userFullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1372,6 +1374,15 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
|
|
||||||
protected void setToRejected(JsonNode jsonNode) {
|
protected void setToRejected(JsonNode jsonNode) {
|
||||||
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_STATUS, CMItemStatus.REJECTED.getValue());
|
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_STATUS, CMItemStatus.REJECTED.getValue());
|
||||||
|
/*
|
||||||
|
* This version is not properly managed by CKAN.
|
||||||
|
* It is converted to:
|
||||||
|
* searchable: "false"
|
||||||
|
* which is considered as true value.
|
||||||
|
* We need to provide a string with F as capitol letters to make it working
|
||||||
|
* ((ObjectNode) jsonNode).put(SEARCHABLE_KEY, false);
|
||||||
|
*/
|
||||||
|
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, "False");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setItemToPending(JsonNode jsonNode) {
|
protected void setItemToPending(JsonNode jsonNode) {
|
||||||
|
@ -1515,7 +1526,9 @@ 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.
|
||||||
sendSocialPost();
|
String gcubeUsername = CKANUser.getUsernameFromCKANUsername(moderationThread.getItemAuthorCkanUsername());
|
||||||
|
String authorFullName = CKANUserCache.getCKANUser(gcubeUsername).getNameSurname();
|
||||||
|
sendSocialPost(authorFullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,6 +35,12 @@ public abstract class CKANUserCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static CKANUser getCurrrentCKANUser() {
|
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();
|
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);
|
||||||
|
@ -42,7 +48,6 @@ public abstract class CKANUserCache {
|
||||||
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
String gcubeUsername = secretManager.getUser().getUsername();
|
|
||||||
CKANUser ckanUser = userCache.get(gcubeUsername);
|
CKANUser ckanUser = userCache.get(gcubeUsername);
|
||||||
if(ckanUser == null) {
|
if(ckanUser == null) {
|
||||||
ckanUser = new CKANUser();
|
ckanUser = new CKANUser();
|
||||||
|
@ -52,6 +57,7 @@ public abstract class CKANUserCache {
|
||||||
return ckanUser;
|
return ckanUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized static void removeUserFromCache() {
|
public synchronized static void removeUserFromCache() {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
String gcubeUsername = secretManager.getUser().getUsername();
|
String gcubeUsername = secretManager.getUser().getUsername();
|
||||||
|
|
|
@ -250,7 +250,7 @@ public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interf
|
||||||
}
|
}
|
||||||
|
|
||||||
String accept = httpHeaders.getHeaderString("Accept");
|
String accept = httpHeaders.getHeaderString("Accept");
|
||||||
if(accept.contains(GCatConstants.APPLICATION_JSON_API)) {
|
if(accept!=null && accept.contains(GCatConstants.APPLICATION_JSON_API)) {
|
||||||
return resultAsJsonAPI(ret);
|
return resultAsJsonAPI(ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class License extends REST<CKANLicense> implements org.gcube.gcat.api.int
|
||||||
String ret = super.list(-1, -1);
|
String ret = super.list(-1, -1);
|
||||||
|
|
||||||
String accept = httpHeaders.getHeaderString("Accept");
|
String accept = httpHeaders.getHeaderString("Accept");
|
||||||
if(accept.contains(GCatConstants.APPLICATION_JSON_API)) {
|
if(accept!=null && accept.contains(GCatConstants.APPLICATION_JSON_API)) {
|
||||||
return resultAsJsonAPI(ret);
|
return resultAsJsonAPI(ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -6,14 +6,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
||||||
import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
|
import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
|
||||||
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
|
||||||
import org.gcube.gcat.utils.Constants;
|
import org.gcube.gcat.utils.Constants;
|
||||||
import org.gcube.portal.databook.shared.Post;
|
import org.gcube.portal.databook.shared.Post;
|
||||||
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
||||||
|
@ -31,6 +28,7 @@ public class SocialPost extends Thread {
|
||||||
protected static final String NOTIFICATION_MESSAGE = "%s just published the item \"%s\"\n"
|
protected static final String NOTIFICATION_MESSAGE = "%s just published the item \"%s\"\n"
|
||||||
+ "Please find it at %s\n";
|
+ "Please find it at %s\n";
|
||||||
|
|
||||||
|
protected String userFullName;
|
||||||
protected String itemID;
|
protected String itemID;
|
||||||
protected String itemURL;
|
protected String itemURL;
|
||||||
protected String itemTitle;
|
protected String itemTitle;
|
||||||
|
@ -41,6 +39,14 @@ public class SocialPost extends Thread {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserFullName() {
|
||||||
|
return userFullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserFullName(String userFullName) {
|
||||||
|
this.userFullName = userFullName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getItemID() {
|
public String getItemID() {
|
||||||
return itemID;
|
return itemID;
|
||||||
}
|
}
|
||||||
|
@ -131,11 +137,8 @@ public class SocialPost extends Thread {
|
||||||
public void sendSocialPost(boolean notifyUsers) {
|
public void sendSocialPost(boolean notifyUsers) {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
try {
|
try {
|
||||||
String fullName = CKANUserCache.getCurrrentCKANUser().getNameSurname();
|
|
||||||
|
|
||||||
|
|
||||||
StringWriter messageWriter = new StringWriter();
|
StringWriter messageWriter = new StringWriter();
|
||||||
messageWriter.append(String.format(NOTIFICATION_MESSAGE, fullName, itemTitle, itemURL));
|
messageWriter.append(String.format(NOTIFICATION_MESSAGE, userFullName, itemTitle, itemURL));
|
||||||
|
|
||||||
for(String tag : tags) {
|
for(String tag : tags) {
|
||||||
tag = tag.trim();
|
tag = tag.trim();
|
||||||
|
|
Loading…
Reference in New Issue