use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailListener method onPrepareMessageError.
@Override
public void onPrepareMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters) {
super.onPrepareMessageError(message, exception, parameters);
MailStatus status = new MailStatus(getBatchId(), message, MailState.PREPARE_ERROR);
status.setWiki(((XWikiContext) execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).getWikiId());
status.setError(exception);
saveStatus(status, parameters);
// This mail will not reach the send queue, so its processing is done now.
mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailListener method onSendMessageSuccess.
@Override
public void onSendMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters) {
super.onSendMessageSuccess(message, parameters);
String uniqueMessageId = message.getUniqueMessageId();
MailStatus status = retrieveExistingMailStatus(uniqueMessageId, MailState.SEND_SUCCESS);
if (status != null) {
status.setState(MailState.SEND_SUCCESS);
} else {
this.logger.warn("Forcing a new mail status for message [{}] of batch [{}] to send_success state.", uniqueMessageId, getBatchId());
status = new MailStatus(getBatchId(), message, MailState.SEND_SUCCESS);
}
// Since the mail was sent successfully we don't need to keep its serialized content
deleteMailContent(status);
// If the user doesn't want to keep success status, we remove the mail status, otherwise we just update it
if (configuration.discardSuccessStatuses()) {
deleteStatus(status, parameters);
} else {
saveStatus(status, parameters);
}
mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailListener method onSendMessageError.
@Override
public void onSendMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters) {
super.onSendMessageError(message, exception, parameters);
String uniqueMessageId = message.getUniqueMessageId();
MailStatus status = retrieveExistingMailStatus(uniqueMessageId, MailState.SEND_ERROR);
if (status != null) {
status.setState(MailState.SEND_ERROR);
} else {
this.logger.warn("Forcing a new mail status for message [{}] of batch [{}] to send_error state.", uniqueMessageId, getBatchId());
status = new MailStatus(getBatchId(), message, MailState.SEND_ERROR);
}
status.setError(exception);
saveStatus(status, parameters);
this.mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailListener method onSendMessageFatalError.
@Override
public void onSendMessageFatalError(String uniqueMessageId, Exception exception, Map<String, Object> parameters) {
super.onSendMessageFatalError(uniqueMessageId, exception, parameters);
MailStatus status = retrieveExistingMailStatus(uniqueMessageId, MailState.SEND_FATAL_ERROR);
if (status != null) {
status.setState(MailState.SEND_FATAL_ERROR);
status.setError(exception);
saveStatus(status, parameters);
} else {
this.logger.error("Unable to report the fatal error encountered during mail sending for message [{}] " + "of batch [{}].", uniqueMessageId, getBatchId(), exception);
}
this.mailStatusResult.incrementCurrentSize();
}
use of org.xwiki.mail.MailStatus in project xwiki-platform by xwiki.
the class DatabaseMailStatusStore method load.
@Override
public List<MailStatus> load(final Map<String, Object> filterMap, final int offset, final int count, String sortField, boolean sortAscending) throws MailStoreException {
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
final XWikiContext xwikiContext = this.contextProvider.get();
// Load from the main wiki
String currentWiki = xwikiContext.getWikiId();
xwikiContext.setWikiId(xwikiContext.getMainXWiki());
// Compute the Query string based on the passed filter map
final String queryString = computeSelectQueryString(filterMap, sortField, sortAscending);
// Log query and parameters
logQuery(queryString, filterMap);
try {
List<MailStatus> mailStatuses = store.executeRead(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<List<MailStatus>>() {
@Override
public List<MailStatus> doInHibernate(Session session) throws HibernateException, XWikiException {
Query query = session.createQuery(queryString);
if (offset > 0) {
query.setFirstResult(offset);
}
if (count > 0) {
query.setMaxResults(count);
}
query.setProperties(filterMap);
List<MailStatus> queryResult = (List<MailStatus>) query.list();
return queryResult;
}
});
// Log loaded statuses
if (this.logger.isDebugEnabled()) {
for (MailStatus mailStatus : mailStatuses) {
this.logger.debug("Loaded mail status [{}]", mailStatus);
}
}
return mailStatuses;
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to load mail statuses matching the filter [%s] from the database.", filterMap), e);
} finally {
xwikiContext.setWikiId(currentWiki);
}
}
Aggregations