Merge remote-tracking branch 'origin/master' into feature/23103
This commit is contained in:
commit
8c455f0f05
|
@ -1 +1,2 @@
|
|||
/org.eclipse.jdt.core.prefs
|
||||
/org.eclipse.core.resources.prefs
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -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,54 +51,62 @@ 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
|
||||
*/
|
||||
public abstract void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception;
|
||||
|
||||
protected abstract void createModerationThread() throws Exception ;
|
||||
protected abstract void createModerationThread() throws Exception;
|
||||
|
||||
public void postItemCreated() throws Exception{
|
||||
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{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
postMessage(cmItemStatus, stringBuffer.toString());
|
||||
@Override
|
||||
public void postItemApproved(String userMessage) throws Exception {
|
||||
create = false;
|
||||
cmItemStatus = CMItemStatus.APPROVED;
|
||||
postItemManaged(userMessage);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ public class ISProfile {
|
|||
public boolean createOrUpdate(String name, String xml) throws SAXException {
|
||||
try {
|
||||
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||
if(ckanUser.getRole().ordinal()<Role.ADMIN.ordinal()) {
|
||||
if(ckanUser.getRole().ordinal()<Role.EDITOR.ordinal()) {
|
||||
throw new NotAuthorizedException("You are not authorized to manage profiles, only Catalogue Editor can manipulate profiles.");
|
||||
}
|
||||
MetadataUtility metadataUtility = new MetadataUtility();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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;
|
||||
import org.gcube.gcat.persistence.ckan.CKANUser;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import org.junit.Test;
|
|||
public class ModerationThreadTest extends ContextTest {
|
||||
|
||||
@Test
|
||||
// @JsonIgnore
|
||||
@Ignore
|
||||
public void test() throws Exception {
|
||||
ModerationThread moderationThread = ModerationThread.getDefaultInstance();
|
||||
moderationThread.setItemCoordinates("e31a6ba8-66ef-47b8-b61f-99a1366b4a69", "my_first_restful_transaction_model", "RESTful Transaction Model", "https://data.dev.d4science.org/ctlg/devVRE/my_first_restful_transaction_model");
|
||||
|
@ -23,8 +23,10 @@ public class ModerationThreadTest extends ContextTest {
|
|||
moderationThread.setCKANUser(ckanUser);
|
||||
moderationThread.postItemCreated();
|
||||
moderationThread.postItemUpdated();
|
||||
moderationThread.postItemRejected("Non mi garba");
|
||||
moderationThread.postItemApproved("Ora mi garba");
|
||||
moderationThread.postItemRejected(null);
|
||||
moderationThread.postItemRejected("reject con messaggio: Non mi garba");
|
||||
moderationThread.postItemApproved(null);
|
||||
moderationThread.postItemApproved("approve con messaggio: Ora mi garba");
|
||||
moderationThread.setItemAuthor(true);
|
||||
moderationThread.postUserMessage(CMItemStatus.APPROVED, "Grazie");
|
||||
Thread.sleep(1000);
|
||||
|
|
Loading…
Reference in New Issue