Added moderation link
This commit is contained in:
parent
eff29b0176
commit
ff7b8d7399
|
@ -1,9 +1,18 @@
|
||||||
package org.gcube.gcat.moderation.thread;
|
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.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.api.moderation.CMItemStatus;
|
||||||
import org.gcube.gcat.moderation.thread.social.SocialMessageModerationThread;
|
import org.gcube.gcat.moderation.thread.social.SocialMessageModerationThread;
|
||||||
import org.gcube.gcat.persistence.ckan.CKANUser;
|
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)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -15,6 +24,8 @@ public abstract class ModerationThread {
|
||||||
protected String itemTitle;
|
protected String itemTitle;
|
||||||
protected String itemURL;
|
protected String itemURL;
|
||||||
|
|
||||||
|
protected String moderationURL;
|
||||||
|
|
||||||
protected boolean create;
|
protected boolean create;
|
||||||
protected CMItemStatus cmItemStatus;
|
protected CMItemStatus cmItemStatus;
|
||||||
protected boolean itemAuthor;
|
protected boolean itemAuthor;
|
||||||
|
@ -31,7 +42,7 @@ public abstract class ModerationThread {
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
this.itemAuthor = false;
|
this.itemAuthor = false;
|
||||||
this.create = false;
|
this.create = false;
|
||||||
cmItemStatus = CMItemStatus.PENDING;
|
this.cmItemStatus = CMItemStatus.PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemCoordinates(String itemID, String itemName, String itemTitle, String itemURL) {
|
public void setItemCoordinates(String itemID, String itemName, String itemTitle, String itemURL) {
|
||||||
|
@ -49,6 +60,32 @@ public abstract class ModerationThread {
|
||||||
this.ckanUser = ckanUser;
|
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
|
* The message is sent as gCat
|
||||||
* @param message
|
* @param message
|
||||||
|
|
|
@ -37,7 +37,11 @@ public class SocialMessageModerationThread extends ModerationThread {
|
||||||
stringBuffer.append(itemID);
|
stringBuffer.append(itemID);
|
||||||
stringBuffer.append("\n");
|
stringBuffer.append("\n");
|
||||||
stringBuffer.append("URL: ");
|
stringBuffer.append("URL: ");
|
||||||
|
if(cmItemStatus == CMItemStatus.APPROVED) {
|
||||||
stringBuffer.append(itemURL);
|
stringBuffer.append(itemURL);
|
||||||
|
}else {
|
||||||
|
stringBuffer.append(getModerationURL());
|
||||||
|
}
|
||||||
stringBuffer.append("\n\n");
|
stringBuffer.append("\n\n");
|
||||||
return stringBuffer;
|
return stringBuffer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue