use of com.serotonin.m2m2.rt.dataImage.types.ImageValue 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.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.
the class ReportDao method reportInstanceDataSQL.
public void reportInstanceDataSQL(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 int dataType = point.getDataType();
ejt.query(REPORT_INSTANCE_DATA_SELECT + "where rd.reportInstancePointId=? order by rd.ts", new Object[] { point.getReportPointId() }, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
switch(dataType) {
case (DataTypes.NUMERIC):
edv.setValue(new NumericValue(rs.getDouble(1)));
break;
case (DataTypes.BINARY):
edv.setValue(new BinaryValue(rs.getDouble(1) == 1));
break;
case (DataTypes.MULTISTATE):
edv.setValue(new MultistateValue(rs.getInt(1)));
break;
case (DataTypes.ALPHANUMERIC):
edv.setValue(new AlphanumericValue(rs.getString(2)));
if (rs.wasNull())
edv.setValue(new AlphanumericValue(rs.getString(3)));
break;
case (DataTypes.IMAGE):
edv.setValue(new ImageValue(Integer.parseInt(rs.getString(2)), rs.getInt(1)));
break;
default:
edv.setValue(null);
}
edv.setTime(rs.getLong(4));
edv.setAnnotation(BaseDao.readTranslatableMessage(rs, 5));
handler.pointData(edv);
}
});
}
handler.done();
}
use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.
the class WatchListDwr method createWatchListState.
/**
* Convenience method for creating a populated view state.
*/
private WatchListState createWatchListState(HttpServletRequest request, DataPointVO pointVO, RuntimeManager rtm, Map<String, Object> model, User user) {
// Get the data point status from the data image.
DataPointRT point = rtm.getDataPoint(pointVO.getId());
WatchListState state = new WatchListState();
state.setId(Integer.toString(pointVO.getId()));
PointValueTime pointValue = prepareBasePointState(Integer.toString(pointVO.getId()), state, pointVO, point, model);
setEvents(pointVO, user, model, pointEventsLimit);
if (pointValue != null && pointValue.getValue() instanceof ImageValue) {
// Text renderers don't help here. Create a thumbnail.
setImageText(request, state, pointVO, model, pointValue);
} else
setPrettyText(state, pointVO, model, pointValue);
if (pointVO.isSettable())
setChange(pointVO, state, point, request, model, user);
if (state.getValue() != null)
setChart(pointVO, state, request, model);
setMessages(state, request, getModule().getWebPath() + "/web/snippet/watchListMessages.jsp", model);
return state;
}
use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.
the class MobileWatchListHandler method createState.
private MobileWatchListState createState(HttpServletRequest request, DataPointVO pointVO) {
MobileWatchListState state = new MobileWatchListState();
state.setId(Integer.toString(pointVO.getId()));
state.setName(pointVO.getExtendedName());
// Get the data point status from the data image.
DataPointRT pointRT = Common.runtimeManager.getDataPoint(pointVO.getId());
if (pointRT == null)
state.setDisabled(true);
else {
PointValueTime pvt = pointRT.getPointValue();
state.setTime(Functions.getTime(pvt));
if (pvt != null && pvt.getValue() instanceof ImageValue) {
// Text renderers don't help here. Create a thumbnail.
Map<String, Object> model = new HashMap<String, Object>();
model.put("point", pointVO);
model.put("pointValue", pvt);
state.setValue(BaseDwr.generateContent(request, "imageValueThumbnail.jsp", model));
} else
state.setValue(Functions.getHtmlText(pointVO, pvt));
}
return state;
}
use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-core-public by infiniteautomation.
the class ImagePointWrapper method ago.
public byte[] ago(int periodType, int periods) {
long from = DateUtils.minus(getContext().getRuntime(), periodType, periods);
PointValueTime pvt = point.getPointValueBefore(from);
if (pvt == null)
return null;
return ((ImageValue) pvt.getValue()).getData();
}
Aggregations