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);
}
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);
}
}
}
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;
}
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);
}
}
}
}
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;
}
Aggregations