use of com.serotonin.m2m2.vo.export.ExportDataValue in project ma-core-public by infiniteautomation.
the class ChartExportServlet method exportExcel.
/**
* Do the export as Excel XLSX File
* @param response
* @param from
* @param to
* @param def
* @param user
* @throws IOException
*/
private void exportExcel(HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
// Stream the content.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
final List<PointValueEmporter> sheetEmporters = new ArrayList<PointValueEmporter>();
final AtomicInteger sheetIndex = new AtomicInteger();
sheetEmporters.add(new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get()));
final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
emporter.prepareExport(bos);
emporter.prepareSheetExport(sheetEmporters.get(0));
final ExportDataValue edv = new ExportDataValue();
MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int rowIndex) {
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
else
edv.setAnnotation(null);
sheetEmporters.get(sheetIndex.get()).exportRow(edv);
if (sheetEmporters.get(sheetIndex.get()).getRowsAdded() >= emporter.getMaxRowsPerSheet()) {
ExportPointInfo info = sheetEmporters.get(sheetIndex.get()).getPointInfo();
sheetIndex.incrementAndGet();
PointValueEmporter sheetEmporter = new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get());
sheetEmporter.setPointInfo(info);
sheetEmporters.add(sheetEmporter);
emporter.prepareSheetExport(sheetEmporters.get(sheetIndex.get()));
}
}
};
for (int pointId : def.getPointIds()) {
DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
if (Permissions.hasDataPointReadPermission(user, dp)) {
ExportPointInfo pointInfo = new ExportPointInfo();
pointInfo.setXid(dp.getXid());
pointInfo.setPointName(dp.getName());
pointInfo.setDeviceName(dp.getDeviceName());
pointInfo.setTextRenderer(dp.getTextRenderer());
sheetEmporters.get(sheetIndex.get()).setPointInfo(pointInfo);
pointValueDao.getPointValuesBetween(pointId, from, to, callback);
}
}
emporter.finishExport();
}
use of com.serotonin.m2m2.vo.export.ExportDataValue 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.vo.export.ExportDataValue 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.vo.export.ExportDataValue in project ma-core-public by infiniteautomation.
the class PointValueEmporter method exportRow.
public void exportRow(ExportDataValue edv) {
int cellNum = 0;
Cell cell;
Row row;
row = sheet.createRow(this.rowNum++);
// Set Point XID
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getXid());
// Set the Device Name
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getDeviceName());
// Set the Point Name
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getPointName());
// Time
cell = row.createCell(cellNum++);
cell.setCellValue(new DateTime(edv.getTime()).toDate());
cell.setCellStyle(dateStyle);
if (edv.getValue() != null) {
cell = row.createCell(cellNum++);
DataValue value = edv.getValue();
switch(value.getDataType()) {
case DataTypes.ALPHANUMERIC:
cell.setCellValue(value.getStringValue());
break;
case DataTypes.BINARY:
cell.setCellValue(value.getBooleanValue());
break;
case DataTypes.MULTISTATE:
cell.setCellValue(value.getIntegerValue());
break;
case DataTypes.NUMERIC:
cell.setCellValue(value.getDoubleValue());
break;
default:
}
// Set the text renderer value here
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getTextRenderer().getText(edv.getValue(), TextRenderer.HINT_FULL));
} else {
row.createCell(cellNum++);
// Do we need an empty cell?
row.createCell(cellNum++);
}
// Do we have an annotation
if (edv.getAnnotation() != null) {
cell = row.createCell(cellNum++);
cell.setCellValue(edv.getAnnotation().translate(Common.getTranslations()));
} else {
cell = row.createCell(cellNum++);
}
this.rowsAdded++;
}
use of com.serotonin.m2m2.vo.export.ExportDataValue in project ma-core-public by infiniteautomation.
the class ChartExportServlet method exportCsv.
/**
* Do the export as a CSV File
* @param response
* @param from
* @param to
* @param def
* @param user
* @throws IOException
*/
private void exportCsv(HttpServletRequest request, HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
// Stream the content.
response.setContentType("text/csv");
final Translations translations = Common.getTranslations();
final ExportCsvStreamer exportCreator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
final ExportDataValue edv = new ExportDataValue();
MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int rowIndex) {
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
else
edv.setAnnotation(null);
exportCreator.pointData(edv);
}
};
for (int pointId : def.getPointIds()) {
DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
if (Permissions.hasDataPointReadPermission(user, dp)) {
ExportPointInfo pointInfo = new ExportPointInfo();
pointInfo.setXid(dp.getXid());
pointInfo.setPointName(dp.getName());
pointInfo.setDeviceName(dp.getDeviceName());
pointInfo.setTextRenderer(dp.getTextRenderer());
pointInfo.setDataPointId(pointId);
exportCreator.startPoint(pointInfo);
pointValueDao.getPointValuesBetween(pointId, from, to, callback);
}
}
exportCreator.done();
}
Aggregations