Added missing notification

This commit is contained in:
Luca Frosini 2023-02-01 15:48:41 +01:00
parent a273dd3f8b
commit 2cc08d4b25
3 changed files with 87 additions and 26 deletions

View File

@ -125,8 +125,8 @@ public abstract class ModerationThread {
public void postItemCreated() throws Exception {
createModerationThread();
create = true;
cmItemStatus = CMItemStatus.PENDING;
this.create = true;
this.cmItemStatus = CMItemStatus.PENDING;
String fullName = ckanUser.getNameSurname();
String message = String.format(
"@**%s** created the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
@ -135,7 +135,7 @@ public abstract class ModerationThread {
}
public void postItemUpdated() throws Exception {
cmItemStatus = CMItemStatus.PENDING;
this.cmItemStatus = CMItemStatus.PENDING;
String fullName = ckanUser.getNameSurname();
String message = String.format(
"@**%s** updated the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
@ -144,7 +144,7 @@ public abstract class ModerationThread {
}
public void postItemRejected(String userMessage) throws Exception {
cmItemStatus = CMItemStatus.REJECTED;
this.cmItemStatus = CMItemStatus.REJECTED;
String fullName = ckanUser.getNameSurname();
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.",
@ -154,7 +154,7 @@ public abstract class ModerationThread {
}
public void postItemApproved(String userMessage) throws Exception {
cmItemStatus = CMItemStatus.APPROVED;
this.cmItemStatus = CMItemStatus.APPROVED;
String fullName = ckanUser.getNameSurname();
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",
@ -162,5 +162,13 @@ public abstract class ModerationThread {
postMessage(message);
postUserMessage(cmItemStatus, userMessage);
}
public void postItemDeleted(CMItemStatus cmItemStatus) throws Exception {
this.cmItemStatus = cmItemStatus;
String fullName = ckanUser.getNameSurname();
String message = String.format(
"@**%s** deleted the item with name '%s' (id='%s')",
fullName, itemName, itemID, itemURL);
postMessage(message);
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.gcat.moderation.thread.social.notifications;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import org.gcube.common.authorization.utils.manager.SecretManager;
@ -30,15 +31,14 @@ public class SocialNotificationModerationThread extends ModerationThread {
protected CatalogueEventType catalogueEventType;
protected boolean comment;
protected static final boolean notificationSentByGCat;
static {
notificationSentByGCat = false;
}
protected boolean notificationSentByGCat;
protected boolean notificationToSelfOnly;
public SocialNotificationModerationThread() {
super();
this.comment = false;
this.notificationSentByGCat = false;
this.notificationToSelfOnly = false;
}
/**
@ -61,16 +61,39 @@ public class SocialNotificationModerationThread extends ModerationThread {
stringBuffer = addQuotedTitle(stringBuffer);
stringBuffer.append(". You are kindly requested to review it and decide either to APPROVE or REJECT it. ");
postMessage(stringBuffer.toString());
notificationToSelfOnly = true;
stringBuffer = new StringBuffer();
stringBuffer.append("Thank you for submitting your item ");
stringBuffer = addQuotedTitle(stringBuffer);
stringBuffer.append(" to the catalogue. Please consider this notification as confirmation that your item has been successfully received and will be managed by the catalogue moderators.");
postMessage(stringBuffer.toString());
notificationToSelfOnly = false;
}
protected void notifyItemDeleted() throws Exception {
String fullName = ckanUser.getNameSurname();
StringBuffer stringBuffer = new StringBuffer();
if(notificationSentByGCat) {
stringBuffer.append(fullName);
}
stringBuffer.append(" permanently deleted ");
stringBuffer.append("the item ");
stringBuffer = addQuotedTitle(stringBuffer);
stringBuffer.append(".");
postMessage(stringBuffer.toString());
}
@Override
public void postItemCreated() throws Exception {
create = true;
cmItemStatus = CMItemStatus.PENDING;
catalogueEventType = CatalogueEventType.ITEM_SUBMITTED;
notifyItemToBeManaged();
}
@Override
public void postItemUpdated() throws Exception {
create = false;
cmItemStatus = CMItemStatus.PENDING;
@ -100,7 +123,7 @@ public class SocialNotificationModerationThread extends ModerationThread {
*
* [mister x] approved the item "[TITLE]" with this accompanying message "[MESSAGE]". [Go to catalogue]
*/
create = false;
this.create = false;
String fullName = ckanUser.getNameSurname();
StringBuffer stringBuffer = new StringBuffer();
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
@ -122,20 +145,28 @@ public class SocialNotificationModerationThread extends ModerationThread {
@Override
public void postItemRejected(String userMessage) throws Exception {
create = false;
cmItemStatus = CMItemStatus.REJECTED;
catalogueEventType = CatalogueEventType.ITEM_REJECTED;
this.create = false;
this.cmItemStatus = CMItemStatus.REJECTED;
this.catalogueEventType = CatalogueEventType.ITEM_REJECTED;
postItemManaged(userMessage);
}
@Override
public void postItemApproved(String userMessage) throws Exception {
create = false;
cmItemStatus = CMItemStatus.APPROVED;
catalogueEventType = CatalogueEventType.ITEM_PUBLISHED;
this.create = false;
this.cmItemStatus = CMItemStatus.APPROVED;
this.catalogueEventType = CatalogueEventType.ITEM_PUBLISHED;
postItemManaged(userMessage);
}
@Override
public void postItemDeleted(CMItemStatus cmItemStatus) throws Exception {
this.create = false;
this.cmItemStatus = cmItemStatus;
this.catalogueEventType = CatalogueEventType.ITEM_REMOVED;
notifyItemDeleted();
}
protected StringBuffer addQuotedTitle(StringBuffer stringBuffer, String quotingCharacter) {
stringBuffer.append(quotingCharacter);
stringBuffer.append(itemTitle);
@ -191,16 +222,20 @@ public class SocialNotificationModerationThread extends ModerationThread {
catalogueEvent.setItemURL(new URL(getModerationURL()));
}
Set<String> users = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
Set<String> users = new HashSet<>();
// Adding current ckanUser
users.add(CKANUser.getUsernameFromCKANUsername(ckanUser.getName()));
if(itemAuthorCkanUsername!=null) {
// Adding item author
users.add(CKANUser.getUsernameFromCKANUsername(itemAuthorCkanUsername));
if(!notificationToSelfOnly) {
users.addAll(SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR));
if(itemAuthorCkanUsername!=null) {
// Adding item author
users.add(CKANUser.getUsernameFromCKANUsername(itemAuthorCkanUsername));
}
}
// Adding current user
users.add(CKANUser.getUsernameFromCKANUsername(ckanUser.getName()));
catalogueEvent.setIdsToNotify(users.toArray(new String[users.size()]));
catalogueEvent.setIdsAsGroup(false);

View File

@ -1075,6 +1075,7 @@ public class CKANPackage extends CKAN implements Moderated {
protected void delete() {
checkModerationDelete();
super.delete();
postItemDeleted();
}
@Override
@ -1099,6 +1100,9 @@ public class CKANPackage extends CKAN implements Moderated {
}
}
super.purge();
postItemDeleted();
} catch(WebApplicationException e) {
throw e;
} catch(Exception e) {
@ -1460,6 +1464,20 @@ public class CKANPackage extends CKAN implements Moderated {
}
}
private void postItemDeleted() {
try {
if(isModerationEnabled()) {
CMItemStatus cmItemStatus = getCMItemStatus();
moderationThread.setItemCoordinates(itemID, name, itemTitle, itemURL);
moderationThread.postItemDeleted(cmItemStatus);
}
} catch(WebApplicationException e) {
throw e;
} catch(Exception e) {
throw new InternalServerErrorException(e);
}
}
@Override
public String approve(String moderatorMessage) {
try {