Fixed messaging
This commit is contained in:
parent
e16940af94
commit
0f86ce828d
|
@ -13,15 +13,13 @@ public class FakeModerationThread extends ModerationThread {
|
|||
private static final Logger logger = LoggerFactory.getLogger(FakeModerationThread.class);
|
||||
|
||||
@Override
|
||||
protected void postMessage(CMItemStatus cmItemStatus, String message) throws Exception {
|
||||
|
||||
protected void postMessage(String message) throws Exception {
|
||||
logger.info("gCat is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
|
||||
ModerationThread.class.getSimpleName(), itemName, itemID, cmItemStatus, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
|
||||
|
||||
logger.info("{} is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
|
||||
SecretManagerProvider.instance.get().getUser().getUsername(),
|
||||
ModerationThread.class.getSimpleName(), itemName, itemID, cmItemStatus, userMessage);
|
||||
|
@ -29,8 +27,8 @@ public class FakeModerationThread extends ModerationThread {
|
|||
|
||||
@Override
|
||||
protected void createModerationThread() throws Exception {
|
||||
|
||||
logger.info("Creating {} for item '{}' (id={})", ModerationThread.class.getSimpleName(), itemName, itemID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ public abstract class ModerationThread {
|
|||
protected String itemTitle;
|
||||
protected String itemURL;
|
||||
|
||||
protected boolean create;
|
||||
protected CMItemStatus cmItemStatus;
|
||||
protected boolean itemAuthor;
|
||||
|
||||
protected CKANUser ckanUser;
|
||||
|
@ -27,7 +29,9 @@ public abstract class ModerationThread {
|
|||
|
||||
public ModerationThread() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
itemAuthor = false;
|
||||
this.itemAuthor = false;
|
||||
this.create = false;
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
}
|
||||
|
||||
public void setItemCoordinates(String itemID, String itemName, String itemTitle, String itemURL) {
|
||||
|
@ -37,10 +41,6 @@ public abstract class ModerationThread {
|
|||
this.itemURL = itemURL;
|
||||
}
|
||||
|
||||
public boolean isItemAuthor() {
|
||||
return itemAuthor;
|
||||
}
|
||||
|
||||
public void setItemAuthor(boolean itemAuthor) {
|
||||
this.itemAuthor = itemAuthor;
|
||||
}
|
||||
|
@ -51,14 +51,16 @@ public abstract class ModerationThread {
|
|||
|
||||
/**
|
||||
* The message is sent as gCat
|
||||
*
|
||||
* @param cmItemStatus
|
||||
* @param message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected abstract void postMessage(CMItemStatus cmItemStatus, String message) throws Exception;
|
||||
protected abstract void postMessage(String message) throws Exception;
|
||||
|
||||
/**
|
||||
* The message is sent as User
|
||||
*
|
||||
* @param cmItemStatus
|
||||
* @param userMessage
|
||||
* @throws Exception
|
||||
|
@ -69,36 +71,42 @@ public abstract class ModerationThread {
|
|||
|
||||
public void postItemCreated() throws Exception {
|
||||
createModerationThread();
|
||||
create = true;
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
||||
String message = String.format("@**%s** created the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
||||
String message = String.format(
|
||||
"@**%s** created the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
||||
fullName, itemName, itemID, cmItemStatus.getFancyValue());
|
||||
postMessage(cmItemStatus, message);
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
public void postItemUpdated() throws Exception {
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
||||
String message = String.format("@**%s** updated the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
||||
String message = String.format(
|
||||
"@**%s** updated the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
||||
fullName, itemName, itemID, cmItemStatus.getFancyValue());
|
||||
postMessage(cmItemStatus, message);
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
public void postItemRejected(String userMessage) throws Exception {
|
||||
cmItemStatus = CMItemStatus.REJECTED;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.REJECTED;
|
||||
String message = String.format("@**%s** **%s** the item with name '%s' (id='%s'). The author can delete the item or update it to try to meet moderators requests if any.",
|
||||
String message = String.format(
|
||||
"@**%s** **%s** the item with name '%s' (id='%s'). The author can delete the item or update it to try to meet moderators requests if any.",
|
||||
fullName, cmItemStatus.getFancyValue(), itemName, itemID);
|
||||
postMessage(cmItemStatus, message);
|
||||
postMessage(message);
|
||||
postUserMessage(cmItemStatus, userMessage);
|
||||
}
|
||||
|
||||
public void postItemApproved(String userMessage) throws Exception {
|
||||
cmItemStatus = CMItemStatus.APPROVED;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.APPROVED;
|
||||
String message = String.format("@**%s** **%s** the item with name '%s' (id='%s'). The item is now available in the catalogue. The item is available at %s",
|
||||
String message = String.format(
|
||||
"@**%s** **%s** the item with name '%s' (id='%s'). The item is now available in the catalogue. The item is available at %s",
|
||||
fullName, cmItemStatus.getFancyValue(), itemName, itemID, itemURL);
|
||||
postMessage(cmItemStatus, message);
|
||||
postMessage(message);
|
||||
postUserMessage(cmItemStatus, userMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SocialMessageModerationThread.class);
|
||||
|
||||
protected StringBuffer getMainItemInfo(CMItemStatus cmItemStatus) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
protected StringBuffer getMainItemInfo(StringBuffer stringBuffer) {
|
||||
stringBuffer.append("Status: ");
|
||||
stringBuffer.append(cmItemStatus.getFancyValue());
|
||||
stringBuffer.append("\n");
|
||||
|
@ -43,37 +42,48 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
return stringBuffer;
|
||||
}
|
||||
|
||||
public void postItemCreated() throws Exception{
|
||||
/**
|
||||
* Create the message for an item that is created/updated
|
||||
*/
|
||||
public void postItemToBeManaged() throws Exception {
|
||||
/*
|
||||
* An example of created message is:
|
||||
*
|
||||
* [mister x] created / updated the following item
|
||||
*
|
||||
* Title: RESTful Transaction Model
|
||||
* Name: my_first_restful_transaction_model
|
||||
* ID: e31a6ba8-66ef-47b8-b61f-99a1366b4a69
|
||||
* URL: https://data.dev.d4science.org/ctlg/devVRE/my_first_restful_transaction_model
|
||||
*
|
||||
* You are kindly requested to review it and decide either to APPROVE or REJECT it at <url of the item>
|
||||
*
|
||||
*/
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
||||
StringBuffer stringBuffer = getMainItemInfo(cmItemStatus);
|
||||
|
||||
stringBuffer.append("Message:\n");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(fullName);
|
||||
stringBuffer.append(" created '");
|
||||
stringBuffer.append(itemTitle);
|
||||
stringBuffer.append("'. It is now in ");
|
||||
stringBuffer.append(cmItemStatus.getFancyValue());
|
||||
stringBuffer.append(" state and must be moderated.");
|
||||
stringBuffer.append(create ? " created " : " updated ");
|
||||
stringBuffer.append("the following item\n\n");
|
||||
stringBuffer = getMainItemInfo(stringBuffer);
|
||||
stringBuffer.append("You are kindly requested to review it and decide either to APPROVE or REJECT it.");
|
||||
// stringBuffer.append("You are kindly requested to review it and decide either to APPROVE or REJECT at");
|
||||
// String manageURL = getManageURL();
|
||||
// stringBuffer.append(manageURL);
|
||||
postMessage(stringBuffer.toString());
|
||||
}
|
||||
|
||||
postMessage(cmItemStatus, stringBuffer.toString());
|
||||
|
||||
public void postItemCreated() throws Exception {
|
||||
create = true;
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
postItemToBeManaged();
|
||||
}
|
||||
|
||||
public void postItemUpdated() throws Exception {
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
||||
StringBuffer stringBuffer = getMainItemInfo(cmItemStatus);
|
||||
|
||||
stringBuffer.append("Message:\n");
|
||||
stringBuffer.append(fullName);
|
||||
stringBuffer.append(" updated '");
|
||||
stringBuffer.append(itemTitle);
|
||||
stringBuffer.append("'. It is now in ");
|
||||
stringBuffer.append(cmItemStatus.getFancyValue());
|
||||
stringBuffer.append(" state and must be moderated.");
|
||||
|
||||
postMessage(cmItemStatus, stringBuffer.toString());
|
||||
create = false;
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
postItemToBeManaged();
|
||||
}
|
||||
|
||||
protected StringBuffer addUserWithRole(String fullName, String role, StringBuffer stringBuffer) {
|
||||
|
@ -84,80 +94,63 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
return stringBuffer;
|
||||
}
|
||||
|
||||
public void postItemManaged(String userMessage) throws Exception {
|
||||
create = false;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append(cmItemStatus.getValue());
|
||||
stringBuffer.append(" the following item");
|
||||
if(userMessage!=null && userMessage.length()>0) {
|
||||
stringBuffer.append(" with this accompanying message\n\n");
|
||||
stringBuffer = getMainItemInfo(stringBuffer);
|
||||
stringBuffer.append(userMessage);
|
||||
}else {
|
||||
stringBuffer.append("\n\n");
|
||||
stringBuffer = getMainItemInfo(stringBuffer);
|
||||
}
|
||||
postMessage(stringBuffer.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postItemRejected(String userMessage) throws Exception {
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.REJECTED;
|
||||
|
||||
StringBuffer stringBuffer = getMainItemInfo(cmItemStatus);
|
||||
|
||||
stringBuffer.append("Message:\n");
|
||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("rejected '");
|
||||
stringBuffer.append(itemTitle);
|
||||
stringBuffer.append("'.");
|
||||
stringBuffer.append(" The author can delete or update it.");
|
||||
|
||||
if(userMessage!=null && userMessage.length()>0) {
|
||||
stringBuffer.append("\n\n");
|
||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("added the following comment:\n");
|
||||
stringBuffer.append(userMessage);
|
||||
}
|
||||
|
||||
postMessage(cmItemStatus, stringBuffer.toString());
|
||||
create = false;
|
||||
cmItemStatus = CMItemStatus.REJECTED;
|
||||
postItemManaged(userMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postItemApproved(String userMessage) throws Exception {
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
CMItemStatus cmItemStatus = CMItemStatus.APPROVED;
|
||||
|
||||
StringBuffer stringBuffer = getMainItemInfo(cmItemStatus);
|
||||
|
||||
stringBuffer.append("Message:\n");
|
||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("approved the '");
|
||||
stringBuffer.append(itemTitle);
|
||||
stringBuffer.append("'.");
|
||||
stringBuffer.append(" It is now available in the catalogue at ");
|
||||
stringBuffer.append(itemURL);
|
||||
|
||||
if(userMessage!=null && userMessage.length()>0) {
|
||||
stringBuffer.append("\n\n");
|
||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("added the following comment:\n");
|
||||
stringBuffer.append(userMessage);
|
||||
create = false;
|
||||
cmItemStatus = CMItemStatus.APPROVED;
|
||||
postItemManaged(userMessage);
|
||||
}
|
||||
|
||||
postMessage(cmItemStatus, stringBuffer.toString());
|
||||
}
|
||||
|
||||
|
||||
protected String getSubject(CMItemStatus cmItemStatus) {
|
||||
protected String getSubject() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
if(!create) {
|
||||
logger.trace("It's a reply");
|
||||
stringWriter.append("Re: [Catalogue Service] ");
|
||||
}
|
||||
stringWriter.append("[Catalogue Service] ");
|
||||
stringWriter.append(itemTitle);
|
||||
stringWriter.append(" (name:");
|
||||
stringWriter.append(itemName);
|
||||
stringWriter.append(" - id:");
|
||||
stringWriter.append(itemID);
|
||||
stringWriter.append(")");
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
protected Message getMessage(CMItemStatus cmItemStatus, String messageString) throws Exception {
|
||||
protected Message getMessage(String messageString) throws Exception {
|
||||
Message message = new Message();
|
||||
message.setMessage(messageString);
|
||||
message.setSubject(getSubject(cmItemStatus));
|
||||
message.setSubject(getSubject());
|
||||
Set<String> moderators = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
|
||||
message.setUsers(moderators);
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postMessage(CMItemStatus cmItemStatus, String messageString) throws Exception {
|
||||
protected void postMessage(String messageString) throws Exception {
|
||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||
String username = secretManager.getUser().getUsername();
|
||||
Message message = getMessage(cmItemStatus, messageString);
|
||||
Message message = getMessage(messageString);
|
||||
message.addUser(username);
|
||||
Secret secret = Constants.getCatalogueSecret();
|
||||
secretManager.startSession(secret);
|
||||
|
@ -170,12 +163,15 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
|
||||
@Override
|
||||
public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
|
||||
this.create = false;
|
||||
this.cmItemStatus = cmItemStatus;
|
||||
String fullName = ckanUser.getNameSurname();
|
||||
StringBuffer stringBuffer = getMainItemInfo(cmItemStatus);
|
||||
stringBuffer = addUserWithRole(fullName, isItemAuthor() ? "Author" : Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("sent the following comment:\n");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer = addUserWithRole(fullName, itemAuthor ? "Author" : Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||
stringBuffer.append("sent a message regarding the following item\n\n");
|
||||
stringBuffer = getMainItemInfo(stringBuffer);
|
||||
stringBuffer.append(userMessage);
|
||||
Message message = getMessage(cmItemStatus, stringBuffer.toString());
|
||||
Message message = getMessage(stringBuffer.toString());
|
||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||
String username = secretManager.getUser().getUsername();
|
||||
message.addUser(username);
|
||||
|
@ -196,7 +192,8 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
|
||||
@Override
|
||||
protected void createModerationThread() throws Exception {
|
||||
// Nothing to do
|
||||
create = true;
|
||||
cmItemStatus = CMItemStatus.PENDING;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -133,20 +133,21 @@ public class ZulipStream extends ModerationThread {
|
|||
executeZulipCall(gCatZulipRestExecutor, postCreateStream);
|
||||
}
|
||||
|
||||
protected void postMessageToStream(ZulipRestExecutor zulipRestExecutor, CMItemStatus cmItemStatus, String message) throws Exception {
|
||||
protected void postMessageToStream(ZulipRestExecutor zulipRestExecutor, String message) throws Exception {
|
||||
PostMessage postMessage = new PostMessage(getStreamName(), cmItemStatus.getFancyValue(), message);
|
||||
logger.debug("Going to send the following message: {}", message);
|
||||
executeZulipCall(zulipRestExecutor, postMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postMessage(CMItemStatus cmItemStatus, String message) throws Exception {
|
||||
postMessageToStream(getGCatZulipRestExecutor(), cmItemStatus, message);
|
||||
protected void postMessage(String message) throws Exception {
|
||||
postMessageToStream(getGCatZulipRestExecutor(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUserMessage(CMItemStatus cmItemStatus, String message) throws Exception {
|
||||
postMessageToStream(getUserZulipRestExecutor(), cmItemStatus, message);
|
||||
this.cmItemStatus = cmItemStatus;
|
||||
postMessageToStream(getUserZulipRestExecutor(), message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.gcat.moderation;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.gcat.ContextTest;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.gcube.gcat.moderation.thread.ModerationThread;
|
||||
|
|
Loading…
Reference in New Issue