Added moderation link

This commit is contained in:
Luca Frosini 2022-05-19 12:06:59 +02:00
parent eff29b0176
commit ff7b8d7399
2 changed files with 43 additions and 2 deletions

View File

@ -1,9 +1,18 @@
package org.gcube.gcat.moderation.thread;
import java.util.HashMap;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
import org.gcube.gcat.api.moderation.CMItemStatus;
import org.gcube.gcat.moderation.thread.social.SocialMessageModerationThread;
import org.gcube.gcat.persistence.ckan.CKANUser;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryString.MODERATION_OP;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryStringBuilder;
/**
* @author Luca Frosini (ISTI - CNR)
@ -14,6 +23,8 @@ public abstract class ModerationThread {
protected String itemName;
protected String itemTitle;
protected String itemURL;
protected String moderationURL;
protected boolean create;
protected CMItemStatus cmItemStatus;
@ -31,7 +42,7 @@ public abstract class ModerationThread {
this.objectMapper = new ObjectMapper();
this.itemAuthor = false;
this.create = false;
cmItemStatus = CMItemStatus.PENDING;
this.cmItemStatus = CMItemStatus.PENDING;
}
public void setItemCoordinates(String itemID, String itemName, String itemTitle, String itemURL) {
@ -49,6 +60,32 @@ public abstract class ModerationThread {
this.ckanUser = ckanUser;
}
public String getModerationURL() {
if(moderationURL==null) {
try {
SecretManager secretManager = SecretManagerProvider.instance.get();
String context = secretManager.getContext();
UriResolverManager resolver = new UriResolverManager("CTLG");
Map<String, String> params = new HashMap<String, String>();
params.put("gcube_scope", context); //e.g. /gcube/devsec/devVRE
params.put("entity_context", "organization");
params.put("entity_name", CatalogueConfiguration.getOrganizationName(context)); //e.g. devvre
CatalogueResolverQueryStringBuilder builder = new CatalogueResolverQueryStringBuilder(itemName); //item name under moderation
builder.itemStatus(cmItemStatus.name()). //e.g. pending, approved, rejected
moderation(MODERATION_OP.show);
String queryString = builder.buildQueryParametersToQueryString();
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
moderationURL = resolver.getLink(params, true);
}catch (Exception e) {
return itemURL;
}
}
return moderationURL;
}
/**
* The message is sent as gCat
* @param message

View File

@ -37,7 +37,11 @@ public class SocialMessageModerationThread extends ModerationThread {
stringBuffer.append(itemID);
stringBuffer.append("\n");
stringBuffer.append("URL: ");
stringBuffer.append(itemURL);
if(cmItemStatus == CMItemStatus.APPROVED) {
stringBuffer.append(itemURL);
}else {
stringBuffer.append(getModerationURL());
}
stringBuffer.append("\n\n");
return stringBuffer;
}