use of com.serotonin.m2m2.vo.export.ExportCsvStreamer in project ma-modules-public by infiniteautomation.
the class ReportExportBase method execute.
protected void execute(HttpServletRequest request, HttpServletResponse response, int content) throws IOException {
// Get the report instance id
int instanceId = Integer.parseInt(request.getParameter("instanceId"));
// Get the report instance
ReportDao reportDao = ReportDao.instance;
ReportInstance instance = reportDao.getReportInstance(instanceId);
// Ensure the user is allowed access.
ReportCommon.ensureReportInstancePermission(Common.getUser(request), instance);
// Stream the content.
response.setContentType("text/csv");
Translations translations = Common.getTranslations();
if (content == CONTENT_REPORT) {
ExportCsvStreamer creator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
if (Common.databaseProxy.getNoSQLProxy() == null)
reportDao.reportInstanceDataSQL(instanceId, creator);
else
reportDao.reportInstanceDataNoSQL(instanceId, creator);
} else if (content == CONTENT_EVENTS)
new EventCsvStreamer(response.getWriter(), reportDao.getReportInstanceEvents(instanceId), translations);
else if (content == CONTENT_COMMENTS)
new UserCommentCsvStreamer(response.getWriter(), reportDao.getReportInstanceUserComments(instanceId), translations);
}
use of com.serotonin.m2m2.vo.export.ExportCsvStreamer 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