|
|
@ -4,6 +4,7 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Properties;
|
|
|
@ -39,6 +40,8 @@ import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
|
|
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
|
|
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
@ -270,27 +273,46 @@ public class PeriodicTask implements Runnable {
|
|
|
|
String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
|
|
|
|
String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
MessageManagerClient mmClient = AbstractPlugin.messages().build();
|
|
|
|
MessageManagerClient mmClient = AbstractPlugin.messages().build();
|
|
|
|
org.gcube.common.storagehub.model.messages.Message theMessage = mmClient.get(messageId);
|
|
|
|
org.gcube.common.storagehub.model.messages.Message theMessage = null;
|
|
|
|
String[] addresses = theMessage.getAddresses();
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < addresses.length; i++) {
|
|
|
|
theMessage = mmClient.get(messageId);
|
|
|
|
recipientIds.add(addresses[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//add the sender and remove the person who is replying from the recipients
|
|
|
|
catch (IdNotFoundException e) {
|
|
|
|
String sender = theMessage.getSender().getUserName();
|
|
|
|
_log.warn("Message with id "+ messageId + " could not be found, trying by name ...");
|
|
|
|
String originalText = theMessage.getBody();
|
|
|
|
List<org.gcube.common.storagehub.model.messages.Message> messages = mmClient.getReceivedMessages();
|
|
|
|
Date originalSentTime = theMessage.getCreationTime().getTime();
|
|
|
|
Collections.reverse(messages); //the messages are returned in chronological order, but the messages we look for is one of the newests
|
|
|
|
recipientIds.add(sender);
|
|
|
|
_log.warn("Messages size="+messages.size());
|
|
|
|
recipientIds.remove(fakeSession.getUsername());
|
|
|
|
for(org.gcube.common.storagehub.model.messages.Message msg: messages) {
|
|
|
|
|
|
|
|
if (msg.getName().equals(messageId)) {
|
|
|
|
_log.debug("Message Recipients:");
|
|
|
|
theMessage = msg;
|
|
|
|
for (String rec : recipientIds) {
|
|
|
|
break;
|
|
|
|
_log.debug(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_log.debug("Constructing reply message");
|
|
|
|
if (theMessage != null) {
|
|
|
|
messageText += getReplyHeaderMessage(sender, originalSentTime, originalText);
|
|
|
|
String[] addresses = theMessage.getAddresses();
|
|
|
|
|
|
|
|
for (int i = 0; i < addresses.length; i++) {
|
|
|
|
|
|
|
|
recipientIds.add(addresses[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//add the sender and remove the person who is replying from the recipients
|
|
|
|
|
|
|
|
String sender = theMessage.getSender().getUserName();
|
|
|
|
|
|
|
|
String originalText = theMessage.getBody();
|
|
|
|
|
|
|
|
Date originalSentTime = theMessage.getCreationTime().getTime();
|
|
|
|
|
|
|
|
recipientIds.add(sender);
|
|
|
|
|
|
|
|
recipientIds.remove(fakeSession.getUsername());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug("Message Recipients:");
|
|
|
|
|
|
|
|
for (String rec : recipientIds) {
|
|
|
|
|
|
|
|
_log.debug(rec);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_log.debug("Constructing reply message");
|
|
|
|
|
|
|
|
messageText += getReplyHeaderMessage(sender, originalSentTime, originalText);
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug("Trying to send message with subject: " + subject + " to: " + recipientIds.toString());
|
|
|
|
_log.debug("Trying to send message with subject: " + subject + " to: " + recipientIds.toString());
|
|
|
|
newMessageId = mmClient.sendMessage(recipientIds, subject, messageText, new ArrayList<String>());
|
|
|
|
newMessageId = mmClient.sendMessage(recipientIds, subject, messageText, new ArrayList<String>());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_log.error("Message with id "+ messageId + " could not be found even iterating by name, exiting.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -605,7 +627,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
sb.append("\n");
|
|
|
|
sb.append("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String toReturn = sb.toString().trim();
|
|
|
|
String toReturn = sb.toString().trim();
|
|
|
|
//check if the reply is from iOS which add illegal character
|
|
|
|
//check if the reply is from iOS which add illegal character
|
|
|
|
String sanytisedLine = StringEscapeUtils.escapeJava(toReturn);
|
|
|
|
String sanytisedLine = StringEscapeUtils.escapeJava(toReturn);
|
|
|
@ -618,6 +640,6 @@ public class PeriodicTask implements Runnable {
|
|
|
|
return toReturn;
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|