Search in sources :

Example 11 with SystemEventType

use of com.serotonin.m2m2.rt.event.type.SystemEventType in project ma-core-public by infiniteautomation.

the class EmailWorkItem method execute.

@Override
public void execute() {
    Exception failedEx = null;
    boolean success = true;
    try {
        if (fromAddress == null) {
            String addr = SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_FROM_ADDRESS);
            String pretty = SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_FROM_NAME);
            fromAddress = new InternetAddress(addr, pretty);
        }
        EmailSender emailSender = new EmailSender(SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_HOST), SystemSettingsDao.getIntValue(SystemSettingsDao.EMAIL_SMTP_PORT), SystemSettingsDao.getBooleanValue(SystemSettingsDao.EMAIL_AUTHORIZATION), SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_USERNAME), SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_PASSWORD), SystemSettingsDao.getBooleanValue(SystemSettingsDao.EMAIL_TLS));
        emailSender.send(fromAddress, toAddresses, subject, content);
    } catch (Exception e) {
        LOG.warn("Error sending email", e);
        failedEx = e;
        success = false;
        String to = "";
        for (InternetAddress addr : toAddresses) {
            if (to.length() > 0)
                to += ", ";
            to += addr.getAddress();
        }
        SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_EMAIL_SEND_FAILURE), Common.timer.currentTimeMillis(), false, new TranslatableMessage("event.email.failure", subject, to, e.getMessage()));
    } finally {
        if (postSendExecution != null) {
            for (PostEmailRunnable runnable : postSendExecution) runnable.emailFinished(success, failedEx);
        }
    }
}
Also used : PostEmailRunnable(com.serotonin.m2m2.email.PostEmailRunnable) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) InternetAddress(javax.mail.internet.InternetAddress) EmailSender(com.serotonin.web.mail.EmailSender) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) AddressException(javax.mail.internet.AddressException)

Example 12 with SystemEventType

use of com.serotonin.m2m2.rt.event.type.SystemEventType in project ma-core-public by infiniteautomation.

the class EventDao method createEventType.

/**
 * Get an event type from a result set
 *
 * eventTypeName = offset
 * eventSubtypeName = offset + 1
 * eventTypeRef1 = offset + 2
 * eventTypeRef2 = offset + 3
 *
 * @param rs
 * @param offset
 * @return
 * @throws SQLException
 */
public static EventType createEventType(ResultSet rs, int offset) throws SQLException {
    String typeName = rs.getString(offset);
    String subtypeName = rs.getString(offset + 1);
    EventType type;
    if (typeName.equals(EventType.EventTypeNames.DATA_POINT))
        type = new DataPointEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.DATA_SOURCE))
        type = new DataSourceEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.SYSTEM))
        type = new SystemEventType(subtypeName, rs.getInt(offset + 2));
    else if (typeName.equals(EventType.EventTypeNames.PUBLISHER))
        type = new PublisherEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.AUDIT))
        // TODO allow tracking the various types of audit events...
        type = new AuditEventType(subtypeName, -1, rs.getInt(offset + 3));
    else {
        EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(typeName);
        if (def == null) {
            // Create Missing Event Type
            type = new MissingEventType(typeName, null, rs.getInt(offset + 2), rs.getInt(offset + 3));
        } else {
            type = def.createEventType(subtypeName, rs.getInt(offset + 2), rs.getInt(offset + 3));
            if (type == null) {
                // Create Missing Event type
                type = new MissingEventType(typeName, subtypeName, rs.getInt(offset + 2), rs.getInt(offset + 3));
            }
        }
    }
    return type;
}
Also used : DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) MissingEventType(com.serotonin.m2m2.rt.event.type.MissingEventType) DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) MissingEventType(com.serotonin.m2m2.rt.event.type.MissingEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition)

Aggregations

SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)9 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 DataPointEventType (com.serotonin.m2m2.rt.event.type.DataPointEventType)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 PostEmailRunnable (com.serotonin.m2m2.email.PostEmailRunnable)2 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)2 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)2 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)2 EventType (com.serotonin.m2m2.rt.event.type.EventType)2 MissingEventType (com.serotonin.m2m2.rt.event.type.MissingEventType)2 PublisherEventType (com.serotonin.m2m2.rt.event.type.PublisherEventType)2 User (com.serotonin.m2m2.vo.User)2 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IntStringPair (com.serotonin.db.pair.IntStringPair)1 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)1 UsedImagesDirective (com.serotonin.m2m2.email.UsedImagesDirective)1 Translations (com.serotonin.m2m2.i18n.Translations)1 EventManagerListenerDefinition (com.serotonin.m2m2.module.EventManagerListenerDefinition)1