use of com.serotonin.m2m2.view.stats.ITime 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.m2m2.view.stats.ITime in project ma-modules-public by infiniteautomation.
the class ReportDao method reportInstanceDataNoSQL.
public void reportInstanceDataNoSQL(int instanceId, final ExportDataStreamHandler handler) {
// Retrieve point information.
List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {
@Override
public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
int i = 0;
ExportPointInfo rp = new ExportPointInfo();
rp.setReportPointId(rs.getInt(++i));
rp.setDeviceName(rs.getString(++i));
rp.setPointName(rs.getString(++i));
rp.setXid(rs.getString(++i));
rp.setDataType(rs.getInt(++i));
String startValue = rs.getString(++i);
if (startValue != null)
rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
rp.setColour(rs.getString(++i));
rp.setWeight(rs.getFloat(++i));
rp.setConsolidatedChart(charToBool(rs.getString(++i)));
rp.setPlotType(rs.getInt(++i));
return rp;
}
});
final ExportDataValue edv = new ExportDataValue();
for (final ExportPointInfo point : pointInfos) {
if (point.getDataType() == DataTypes.IMAGE) {
DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
if (vo != null)
point.setDataPointId(vo.getId());
else
point.setDataPointId(-1);
}
handler.startPoint(point);
edv.setReportPointId(point.getReportPointId());
final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
final String pointStore = instanceId + "_" + point.getReportPointId();
dao.getData(pointStore, 0, Long.MAX_VALUE, -1, false, new NoSQLQueryCallback() {
@Override
public void entry(String storeName, long timestamp, ITime entry) {
PointValueTime pvt = (PointValueTime) entry;
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
handler.pointData(edv);
}
});
}
handler.done();
}
use of com.serotonin.m2m2.view.stats.ITime 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);
}
}
Aggregations