Adding support for Messages
This commit is contained in:
parent
e291485133
commit
013af6c3f3
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>gcat</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
<name>gCube Catalogue (gCat) Service</name>
|
||||
<description>
|
||||
This service allows any client to publish on the gCube Catalogue.
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +17,8 @@ public abstract class ModerationThread {
|
|||
protected ObjectMapper objectMapper;
|
||||
|
||||
public static ModerationThread getDefaultInstance() {
|
||||
return new FakeModerationThread();
|
||||
// return new FakeModerationThread();
|
||||
return new SocialMessageModerationThread();
|
||||
}
|
||||
|
||||
public ModerationThread() {
|
||||
|
|
|
@ -3,12 +3,16 @@ package org.gcube.gcat.moderation.thread.social;
|
|||
import java.io.StringWriter;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.gcube.gcat.api.moderation.Moderated;
|
||||
import org.gcube.gcat.moderation.thread.ModerationThread;
|
||||
import org.gcube.gcat.social.Message;
|
||||
import org.gcube.gcat.social.SocialMessage;
|
||||
import org.gcube.gcat.social.SocialUsers;
|
||||
import org.gcube.gcat.utils.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -21,10 +25,11 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
|
||||
protected String getSubject(CMItemStatus cmItemStatus) {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(cmItemStatus.getFancyValue());
|
||||
stringWriter.append(itemName);
|
||||
stringWriter.append(" (id:");
|
||||
stringWriter.append(itemID);
|
||||
|
||||
stringWriter.append(") - status:");
|
||||
stringWriter.append(cmItemStatus.getFancyValue());
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
|
@ -33,25 +38,36 @@ public class SocialMessageModerationThread extends ModerationThread {
|
|||
message.setMessage(messageString);
|
||||
message.setSubject(getSubject(cmItemStatus));
|
||||
Set<String> moderators = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
|
||||
|
||||
message.setUsers(moderators);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void postMessage(CMItemStatus cmItemStatus, String message) throws Exception {
|
||||
|
||||
protected void postMessage(CMItemStatus cmItemStatus, String messageString) throws Exception {
|
||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||
String username = secretManager.getUser().getUsername();
|
||||
Message message = getMessage(cmItemStatus, messageString);
|
||||
message.addUser(username);
|
||||
Secret secret = Constants.getCatalogueSecret();
|
||||
secretManager.startSession(secret);
|
||||
sendMessage(message);
|
||||
secretManager.endSession();
|
||||
}
|
||||
|
||||
@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);
|
||||
Message message = getMessage(cmItemStatus, userMessage);
|
||||
String itemAuthor = ckanUser.getEMail();
|
||||
message.addUser(itemAuthor);
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
protected void sendMessage(Message message) throws Exception {
|
||||
SocialMessage socialMessage = new SocialMessage();
|
||||
socialMessage.setMessage(message);
|
||||
socialMessage.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createModerationThread() throws Exception {
|
||||
// Nothing to do
|
||||
|
|
|
@ -34,6 +34,10 @@ public class Message {
|
|||
public void setUsers(Collection<String> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public void addUser(String user) {
|
||||
this.users.add(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -1,23 +1,14 @@
|
|||
package org.gcube.gcat.social;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
import org.gcube.common.authorization.utils.socialservice.SocialService;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
||||
import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
|
||||
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
||||
import org.gcube.gcat.utils.Constants;
|
||||
import org.gcube.gcat.utils.HTTPUtility;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -41,8 +32,6 @@ public class SocialMessage extends Thread {
|
|||
protected final ObjectMapper objectMapper;
|
||||
|
||||
protected Message message;
|
||||
protected String itemURL;
|
||||
protected String itemTitle;
|
||||
|
||||
public SocialMessage() throws Exception {
|
||||
super();
|
||||
|
@ -61,14 +50,9 @@ public class SocialMessage extends Thread {
|
|||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
CatalogueConfiguration instance = CatalogueConfigurationFactory.getInstance();
|
||||
|
||||
logger.info("Going to send Message about the Item {} available at {}", message, itemURL);
|
||||
|
||||
logger.info("Going to send Message {}", message);
|
||||
// write message
|
||||
sendSocialMessage();
|
||||
|
||||
} catch(Exception e) {
|
||||
logger.error("Error while executing post creation actions", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue