tries looking for email message by id first and name as fallback
This commit is contained in:
parent
0c5a5bc110
commit
f769c3d1ce
|
@ -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,7 +273,23 @@ 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;
|
||||||
|
try {
|
||||||
|
theMessage = mmClient.get(messageId);
|
||||||
|
}
|
||||||
|
catch (IdNotFoundException e) {
|
||||||
|
_log.warn("Message with id "+ messageId + " could not be found, trying by name ...");
|
||||||
|
List<org.gcube.common.storagehub.model.messages.Message> messages = mmClient.getReceivedMessages();
|
||||||
|
Collections.reverse(messages); //the messages are returned in chronological order, but the messages we look for is one of the newests
|
||||||
|
_log.warn("Messages size="+messages.size());
|
||||||
|
for(org.gcube.common.storagehub.model.messages.Message msg: messages) {
|
||||||
|
if (msg.getName().equals(messageId)) {
|
||||||
|
theMessage = msg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (theMessage != null) {
|
||||||
String[] addresses = theMessage.getAddresses();
|
String[] addresses = theMessage.getAddresses();
|
||||||
for (int i = 0; i < addresses.length; i++) {
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
recipientIds.add(addresses[i]);
|
recipientIds.add(addresses[i]);
|
||||||
|
@ -291,6 +310,9 @@ public class PeriodicTask implements Runnable {
|
||||||
|
|
||||||
_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();
|
||||||
|
|
Loading…
Reference in New Issue