Search in sources :

Example 36 with ShouldNeverHappenException

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

the class ReportPointValueTimeSerializer method putBytes.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getBytes(com.serotonin.m2m2.db.dao.nosql.NoSQLDataEntry)
	 */
@Override
public void putBytes(ByteArrayBuilder b, ITime obj, long timestamp, String seriesId) {
    PointValueTime value = (PointValueTime) obj;
    // First put in the data type
    b.putShort((short) value.getValue().getDataType());
    // Second put in the data value
    switch(value.getValue().getDataType()) {
        case DataTypes.ALPHANUMERIC:
            b.putString(value.getStringValue());
            break;
        case DataTypes.BINARY:
            b.putBoolean(value.getBooleanValue());
            break;
        case DataTypes.IMAGE:
            ImageValue imageValue = (ImageValue) value.getValue();
            if (!imageValue.isSaved()) {
                throw new ImageSaveException(new IOException("Image not saved."));
            }
            b.putString(imageValue.getFilename());
            break;
        case DataTypes.MULTISTATE:
            b.putInt(value.getIntegerValue());
            break;
        case DataTypes.NUMERIC:
            b.putDouble(value.getDoubleValue());
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + value.getValue().getDataType() + " is not supported");
    }
    // Put in annotation
    if (value.isAnnotated()) {
        AnnotatedPointValueTime apv = (AnnotatedPointValueTime) value;
        b.putString(apv.getSourceMessage().serialize());
    } else
        b.putString(null);
}
Also used : AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 37 with ShouldNeverHappenException

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

the class RTMDefinition method initialize.

@Override
public void initialize(boolean safe) {
    List<ReportVO> reports = ReportDao.instance.getReports();
    for (ReportVO report : reports) {
        try {
            String host = InetAddress.getLocalHost().getHostName();
            int port = Common.envProps.getInt("web.port", 8080);
            ReportJob.scheduleReportJob(host, port, report);
        } catch (ShouldNeverHappenException | UnknownHostException e) {
            // Don't stop the startup if there is an error. Just log it.
            LOG.error("Error starting report " + report.getName(), e);
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 38 with ShouldNeverHappenException

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

the class M2MReportDao method query.

private List<M2MReportVO> query(String sql, M2MReportRowMapper rowMapper) {
    Statement stmt = null;
    ResultSet rs = null;
    List<M2MReportVO> reports = new ArrayList<M2MReportVO>();
    try {
        stmt = createStatement();
        rs = stmt.executeQuery(sql);
        int i = 0;
        while (rs.next()) {
            M2MReportVO report = rowMapper.mapRow(rs, i);
            reports.add(report);
            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);
            }
        }
    }
    return reports;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 39 with ShouldNeverHappenException

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

the class M2MReportDao method getUsername.

/**
 * @param userId
 * @return
 */
public String getUsername(int userId) {
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = this.connection.createStatement();
        stmt.execute(USER_NAME_SELECT + " where id = " + userId);
        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)

Example 40 with ShouldNeverHappenException

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

the class M2MReportPointVO method convert.

/**
 * @return
 */
public ReportPointVO convert(M2MReportDao legacyDao) {
    ReportPointVO point = new ReportPointVO();
    // Lookup point from M2M
    String legacyXid = legacyDao.getDataPointXid(this.pointId);
    // Lookup the new point by XID
    DataPointVO dp = DataPointDao.instance.getByXid(legacyXid);
    if (dp != null)
        point.setPointId(dp.getId());
    else
        throw new ShouldNeverHappenException("No point found in Mango that corresponds to M2M XID: " + legacyXid);
    point.setColour(colour);
    point.setConsolidatedChart(consolidatedChart);
    point.setPlotType(DataPointVO.PlotTypes.STEP);
    point.setPointKey("");
    point.setWeight(1);
    return point;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ReportPointVO(com.serotonin.m2m2.reports.vo.ReportPointVO)

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