Search in sources :

Example 46 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class ExpandTimePeriodAdjuster method adjustInto.

/* (non-Javadoc)
     * @see java.time.temporal.TemporalAdjuster#adjustInto(java.time.temporal.Temporal)
     */
@Override
public Temporal adjustInto(Temporal temporal) {
    ZonedDateTime zdt = startTime;
    ZonedDateTime adjustTime = (ZonedDateTime) temporal;
    while (zdt.isBefore(adjustTime)) {
        // adjusted in that manner if appropriate, and none of the time advances should alter a lesser field harmfully.
        switch(periodType) {
            case TimePeriods.MILLISECONDS:
                zdt = zdt.plus(periods, ChronoUnit.MILLIS);
                break;
            case TimePeriods.SECONDS:
                zdt = zdt.plus(periods, ChronoUnit.SECONDS);
                break;
            case TimePeriods.MINUTES:
                zdt = zdt.plus(periods, ChronoUnit.MINUTES);
                break;
            case TimePeriods.HOURS:
                zdt = zdt.plus(periods, ChronoUnit.HOURS);
                break;
            case TimePeriods.DAYS:
                zdt = zdt.plus(periods, ChronoUnit.DAYS);
                break;
            case TimePeriods.WEEKS:
                // Don't set the DoW since this may be governed by last year, and shouldn't change by adding weeks
                zdt = zdt.plus(periods, ChronoUnit.WEEKS);
                break;
            case TimePeriods.MONTHS:
                zdt = zdt.plus(periods, ChronoUnit.MONTHS);
                break;
            case TimePeriods.YEARS:
                zdt = zdt.plus(periods, ChronoUnit.YEARS);
                break;
            default:
                throw new ShouldNeverHappenException("Unsupported time period: " + periodType);
        }
    }
    return zdt;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 47 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class M2MRecipientListEntryBean method convert.

/**
 * @param legacyDao
 * @return
 */
public RecipientListEntryBean convert(M2MReportDao legacyDao) {
    RecipientListEntryBean bean = new RecipientListEntryBean();
    bean.setRecipientType(recipientType);
    switch(recipientType) {
        case EmailRecipient.TYPE_USER:
            String username = legacyDao.getUsername(referenceId);
            User user = UserDao.instance.getUser(username);
            if (user != null)
                bean.setReferenceId(user.getId());
            else
                throw new ShouldNeverHappenException("User " + username + " not found in Mango.");
            break;
        case EmailRecipient.TYPE_ADDRESS:
            bean.setReferenceAddress(referenceAddress);
            break;
        case EmailRecipient.TYPE_MAILING_LIST:
            String listXid = legacyDao.getMailingListXid(referenceId);
            MailingList list = MailingListDao.instance.getMailingList(listXid);
            if (list != null)
                bean.setReferenceId(list.getId());
            else
                throw new ShouldNeverHappenException("Mailing list with XID: " + listXid + " not found in Mango.");
            break;
    }
    return bean;
}
Also used : User(com.serotonin.m2m2.vo.User) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Example 48 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class ReportPointValueTimeSerializer method getObject.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getObject(byte[], long)
	 */
@Override
public ITime getObject(ByteArrayBuilder b, long ts, String seriesId) {
    // Get the data type
    int dataType = b.getShort();
    DataValue dataValue = null;
    // Second put in the data value
    switch(dataType) {
        case DataTypes.ALPHANUMERIC:
            String s = b.getString();
            dataValue = new AlphanumericValue(s);
            break;
        case DataTypes.BINARY:
            boolean bool = b.getBoolean();
            dataValue = new BinaryValue(bool);
            break;
        case DataTypes.IMAGE:
            try {
                dataValue = new ImageValue(b.getString());
            } catch (InvalidArgumentException e1) {
            // Probably no file
            }
            break;
        case DataTypes.MULTISTATE:
            int i = b.getInt();
            dataValue = new MultistateValue(i);
            break;
        case DataTypes.NUMERIC:
            double d = b.getDouble();
            dataValue = new NumericValue(d);
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + dataType + " is not supported");
    }
    // Get the annotation
    String annotation = b.getString();
    if (annotation != null) {
        try {
            return new AnnotatedPointValueTime(dataValue, ts, TranslatableMessage.deserialize(annotation));
        } catch (Exception e) {
            throw new ShouldNeverHappenException(e);
        }
    } else {
        return new PointValueTime(dataValue, ts);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) InvalidArgumentException(com.serotonin.InvalidArgumentException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) IOException(java.io.IOException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) InvalidArgumentException(com.serotonin.InvalidArgumentException) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 49 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class M2MReportDao method query.

/**
 * @param string
 * @param objects
 * @param pointValueRowMapper
 * @param callback
 */
protected void query(String sql, M2MReportRowMapper rowMapper, MappedRowCallback<M2MReportVO> callback) {
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = createStatement();
        rs = stmt.executeQuery(sql);
        int i = 0;
        while (rs.next()) {
            M2MReportVO pvt = rowMapper.mapRow(rs, i);
            callback.row(pvt, i);
            i++;
        }
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
        throw new ShouldNeverHappenException(e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e1) {
                LOG.error(e1.getMessage(), e1);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 50 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class M2MReportDao method getDataPointXid.

/**
 * @param pointId
 * @return
 */
public String getDataPointXid(int pointId) {
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = this.connection.createStatement();
        stmt.execute(DATA_POINT_XID_SELECT + " where id = " + pointId);
        rs = stmt.getResultSet();
        if (rs.next()) {
            return rs.getString(1);
        } else
            return null;
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
        throw new ShouldNeverHappenException(e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4