Search in sources :

Example 21 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 22 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 23 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 24 with MailStatus

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();
}
Also used : MailStatus(org.xwiki.mail.MailStatus)

Example 25 with MailStatus

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);
    }
}
Also used : MailStoreException(org.xwiki.mail.MailStoreException) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) MailStoreException(org.xwiki.mail.MailStoreException) HibernateException(org.hibernate.HibernateException) List(java.util.List) XWikiHibernateBaseStore(com.xpn.xwiki.store.XWikiHibernateBaseStore) MailStatus(org.xwiki.mail.MailStatus) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Aggregations

MailStatus (org.xwiki.mail.MailStatus)27 Test (org.junit.Test)14 MailStoreException (org.xwiki.mail.MailStoreException)9 MailStatusStore (org.xwiki.mail.MailStatusStore)8 ExtendedMimeMessage (org.xwiki.mail.ExtendedMimeMessage)7 MailContentStore (org.xwiki.mail.MailContentStore)7 MailListener (org.xwiki.mail.MailListener)7 ArrayList (java.util.ArrayList)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 Properties (java.util.Properties)3 Session (javax.mail.Session)3 MimeMessage (javax.mail.internet.MimeMessage)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 MemoryMailListener (org.xwiki.mail.internal.MemoryMailListener)3 UpdateableMailStatusResult (org.xwiki.mail.internal.UpdateableMailStatusResult)3 Map (java.util.Map)2 MailSender (org.xwiki.mail.MailSender)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiHibernateBaseStore (com.xpn.xwiki.store.XWikiHibernateBaseStore)1 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)1