100 lines
4.1 KiB
Java
100 lines
4.1 KiB
Java
package org.gcube.gcat.moderation.thread;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.gcube.gcat.api.moderation.CMItemStatus;
|
|
import org.gcube.gcat.moderation.thread.social.SocialMessageModerationThread;
|
|
import org.gcube.gcat.persistence.ckan.CKANUser;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public abstract class ModerationThread {
|
|
|
|
protected String itemID;
|
|
protected String itemName;
|
|
protected String itemURL;
|
|
|
|
protected CKANUser ckanUser;
|
|
protected ObjectMapper objectMapper;
|
|
|
|
public static ModerationThread getDefaultInstance() {
|
|
// return new FakeModerationThread();
|
|
return new SocialMessageModerationThread();
|
|
}
|
|
|
|
public ModerationThread() {
|
|
this.objectMapper = new ObjectMapper();
|
|
}
|
|
|
|
public void setItemCoordinates(String itemID, String itemName, String itemURL) {
|
|
this.itemID = itemID;
|
|
this.itemName = itemName;
|
|
this.itemURL = itemURL;
|
|
}
|
|
|
|
public void setCKANUser(CKANUser ckanUser) {
|
|
this.ckanUser = ckanUser;
|
|
}
|
|
|
|
/**
|
|
* The message is sent as gCat
|
|
* @param cmItemStatus
|
|
* @param message
|
|
* @throws Exception
|
|
*/
|
|
protected abstract void postMessage(CMItemStatus cmItemStatus, 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 ;
|
|
|
|
public void postItemCreated() throws Exception{
|
|
createModerationThread();
|
|
String fullName = ckanUser.getNameSurname();
|
|
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
|
// String message = String.format("@**%s** has created the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
|
// username, itemName, itemID, cmItemStatus.getFancyValue());
|
|
String message = String.format("%s has 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);
|
|
}
|
|
|
|
public void postItemUpdated() throws Exception {
|
|
String fullName = ckanUser.getNameSurname();
|
|
CMItemStatus cmItemStatus = CMItemStatus.PENDING;
|
|
// String message = String.format("@**%s** has updated the item with name '%s' (id='%s'). The item is now in **%s** state and must be moderated.",
|
|
// username, itemName, itemID, cmItemStatus.getFancyValue());
|
|
String message = String.format("%s has updated the item with name '%s' (id='%s'). The item is now in %s state and must be moderated.",
|
|
fullName, itemName, itemID, cmItemStatus.getFancyValue(), itemURL);
|
|
postMessage(cmItemStatus, message);
|
|
}
|
|
|
|
public void postItemRejected(String userMessage) throws Exception {
|
|
String fullName = ckanUser.getNameSurname();
|
|
CMItemStatus cmItemStatus = CMItemStatus.REJECTED;
|
|
// String message = String.format("@**%s** has **%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.",
|
|
// username, cmItemStatus.getFancyValue(), itemName, itemID,);
|
|
String message = String.format("%s has %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);
|
|
postUserMessage(cmItemStatus, userMessage);
|
|
}
|
|
|
|
public void postItemApproved(String userMessage) throws Exception{
|
|
String fullName = ckanUser.getNameSurname();
|
|
CMItemStatus cmItemStatus = CMItemStatus.APPROVED;
|
|
// String message = String.format("@**%s** has **%s** the item with name '%s' (id='%s'). The item is now available in the catalogue. The item is available at %s",
|
|
// username, cmItemStatus.getFancyValue(), itemName, itemID, itemURL);
|
|
String message = String.format("%s has %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);
|
|
postUserMessage(cmItemStatus, userMessage);
|
|
}
|
|
}
|