Added missing notification
This commit is contained in:
parent
a273dd3f8b
commit
2cc08d4b25
|
@ -125,8 +125,8 @@ public abstract class ModerationThread {
|
||||||
|
|
||||||
public void postItemCreated() throws Exception {
|
public void postItemCreated() throws Exception {
|
||||||
createModerationThread();
|
createModerationThread();
|
||||||
create = true;
|
this.create = true;
|
||||||
cmItemStatus = CMItemStatus.PENDING;
|
this.cmItemStatus = CMItemStatus.PENDING;
|
||||||
String fullName = ckanUser.getNameSurname();
|
String fullName = ckanUser.getNameSurname();
|
||||||
String message = String.format(
|
String message = String.format(
|
||||||
"@**%s** created the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
"@**%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 {
|
public void postItemUpdated() throws Exception {
|
||||||
cmItemStatus = CMItemStatus.PENDING;
|
this.cmItemStatus = CMItemStatus.PENDING;
|
||||||
String fullName = ckanUser.getNameSurname();
|
String fullName = ckanUser.getNameSurname();
|
||||||
String message = String.format(
|
String message = String.format(
|
||||||
"@**%s** updated the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
"@**%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 {
|
public void postItemRejected(String userMessage) throws Exception {
|
||||||
cmItemStatus = CMItemStatus.REJECTED;
|
this.cmItemStatus = CMItemStatus.REJECTED;
|
||||||
String fullName = ckanUser.getNameSurname();
|
String fullName = ckanUser.getNameSurname();
|
||||||
String message = String.format(
|
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.",
|
"@**%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 {
|
public void postItemApproved(String userMessage) throws Exception {
|
||||||
cmItemStatus = CMItemStatus.APPROVED;
|
this.cmItemStatus = CMItemStatus.APPROVED;
|
||||||
String fullName = ckanUser.getNameSurname();
|
String fullName = ckanUser.getNameSurname();
|
||||||
String message = String.format(
|
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",
|
"@**%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);
|
postMessage(message);
|
||||||
postUserMessage(cmItemStatus, userMessage);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.gcat.moderation.thread.social.notifications;
|
package org.gcube.gcat.moderation.thread.social.notifications;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
|
@ -30,15 +31,14 @@ public class SocialNotificationModerationThread extends ModerationThread {
|
||||||
protected CatalogueEventType catalogueEventType;
|
protected CatalogueEventType catalogueEventType;
|
||||||
protected boolean comment;
|
protected boolean comment;
|
||||||
|
|
||||||
protected static final boolean notificationSentByGCat;
|
protected boolean notificationSentByGCat;
|
||||||
|
protected boolean notificationToSelfOnly;
|
||||||
static {
|
|
||||||
notificationSentByGCat = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SocialNotificationModerationThread() {
|
public SocialNotificationModerationThread() {
|
||||||
super();
|
super();
|
||||||
this.comment = false;
|
this.comment = false;
|
||||||
|
this.notificationSentByGCat = false;
|
||||||
|
this.notificationToSelfOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,16 +61,39 @@ public class SocialNotificationModerationThread extends ModerationThread {
|
||||||
stringBuffer = addQuotedTitle(stringBuffer);
|
stringBuffer = addQuotedTitle(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 it. ");
|
||||||
postMessage(stringBuffer.toString());
|
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 {
|
public void postItemCreated() throws Exception {
|
||||||
create = true;
|
create = true;
|
||||||
cmItemStatus = CMItemStatus.PENDING;
|
cmItemStatus = CMItemStatus.PENDING;
|
||||||
catalogueEventType = CatalogueEventType.ITEM_SUBMITTED;
|
catalogueEventType = CatalogueEventType.ITEM_SUBMITTED;
|
||||||
notifyItemToBeManaged();
|
notifyItemToBeManaged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void postItemUpdated() throws Exception {
|
public void postItemUpdated() throws Exception {
|
||||||
create = false;
|
create = false;
|
||||||
cmItemStatus = CMItemStatus.PENDING;
|
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]
|
* [mister x] approved the item "[TITLE]" with this accompanying message "[MESSAGE]". [Go to catalogue]
|
||||||
*/
|
*/
|
||||||
create = false;
|
this.create = false;
|
||||||
String fullName = ckanUser.getNameSurname();
|
String fullName = ckanUser.getNameSurname();
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
stringBuffer = addUserWithRole(fullName, Moderated.CATALOGUE_MODERATOR, stringBuffer);
|
||||||
|
@ -122,20 +145,28 @@ public class SocialNotificationModerationThread extends ModerationThread {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postItemRejected(String userMessage) throws Exception {
|
public void postItemRejected(String userMessage) throws Exception {
|
||||||
create = false;
|
this.create = false;
|
||||||
cmItemStatus = CMItemStatus.REJECTED;
|
this.cmItemStatus = CMItemStatus.REJECTED;
|
||||||
catalogueEventType = CatalogueEventType.ITEM_REJECTED;
|
this.catalogueEventType = CatalogueEventType.ITEM_REJECTED;
|
||||||
postItemManaged(userMessage);
|
postItemManaged(userMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postItemApproved(String userMessage) throws Exception {
|
public void postItemApproved(String userMessage) throws Exception {
|
||||||
create = false;
|
this.create = false;
|
||||||
cmItemStatus = CMItemStatus.APPROVED;
|
this.cmItemStatus = CMItemStatus.APPROVED;
|
||||||
catalogueEventType = CatalogueEventType.ITEM_PUBLISHED;
|
this.catalogueEventType = CatalogueEventType.ITEM_PUBLISHED;
|
||||||
postItemManaged(userMessage);
|
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) {
|
protected StringBuffer addQuotedTitle(StringBuffer stringBuffer, String quotingCharacter) {
|
||||||
stringBuffer.append(quotingCharacter);
|
stringBuffer.append(quotingCharacter);
|
||||||
stringBuffer.append(itemTitle);
|
stringBuffer.append(itemTitle);
|
||||||
|
@ -191,16 +222,20 @@ public class SocialNotificationModerationThread extends ModerationThread {
|
||||||
catalogueEvent.setItemURL(new URL(getModerationURL()));
|
catalogueEvent.setItemURL(new URL(getModerationURL()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> users = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
|
Set<String> users = new HashSet<>();
|
||||||
|
|
||||||
// Adding current ckanUser
|
if(!notificationToSelfOnly) {
|
||||||
users.add(CKANUser.getUsernameFromCKANUsername(ckanUser.getName()));
|
users.addAll(SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR));
|
||||||
|
|
||||||
if(itemAuthorCkanUsername!=null) {
|
if(itemAuthorCkanUsername!=null) {
|
||||||
// Adding item author
|
// Adding item author
|
||||||
users.add(CKANUser.getUsernameFromCKANUsername(itemAuthorCkanUsername));
|
users.add(CKANUser.getUsernameFromCKANUsername(itemAuthorCkanUsername));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding current user
|
||||||
|
users.add(CKANUser.getUsernameFromCKANUsername(ckanUser.getName()));
|
||||||
|
|
||||||
catalogueEvent.setIdsToNotify(users.toArray(new String[users.size()]));
|
catalogueEvent.setIdsToNotify(users.toArray(new String[users.size()]));
|
||||||
catalogueEvent.setIdsAsGroup(false);
|
catalogueEvent.setIdsAsGroup(false);
|
||||||
|
|
||||||
|
|
|
@ -1075,6 +1075,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
protected void delete() {
|
protected void delete() {
|
||||||
checkModerationDelete();
|
checkModerationDelete();
|
||||||
super.delete();
|
super.delete();
|
||||||
|
postItemDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1099,6 +1100,9 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.purge();
|
super.purge();
|
||||||
|
|
||||||
|
postItemDeleted();
|
||||||
|
|
||||||
} catch(WebApplicationException e) {
|
} catch(WebApplicationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception 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
|
@Override
|
||||||
public String approve(String moderatorMessage) {
|
public String approve(String moderatorMessage) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue