Search in sources :

Example 1 with ExportCsvStreamer

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);
}
Also used : UserCommentCsvStreamer(com.serotonin.m2m2.reports.web.UserCommentCsvStreamer) EventCsvStreamer(com.serotonin.m2m2.vo.export.EventCsvStreamer) ExportCsvStreamer(com.serotonin.m2m2.vo.export.ExportCsvStreamer) ReportDao(com.serotonin.m2m2.reports.ReportDao) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance) Translations(com.serotonin.m2m2.i18n.Translations)

Example 2 with ExportCsvStreamer

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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) MappedRowCallback(com.serotonin.db.MappedRowCallback) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportCsvStreamer(com.serotonin.m2m2.vo.export.ExportCsvStreamer) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) Translations(com.serotonin.m2m2.i18n.Translations)

Aggregations

Translations (com.serotonin.m2m2.i18n.Translations)2 ExportCsvStreamer (com.serotonin.m2m2.vo.export.ExportCsvStreamer)2 MappedRowCallback (com.serotonin.db.MappedRowCallback)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 ReportDao (com.serotonin.m2m2.reports.ReportDao)1 ReportInstance (com.serotonin.m2m2.reports.vo.ReportInstance)1 UserCommentCsvStreamer (com.serotonin.m2m2.reports.web.UserCommentCsvStreamer)1 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 EventCsvStreamer (com.serotonin.m2m2.vo.export.EventCsvStreamer)1 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)1 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)1