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