Search in sources :

Example 1 with ExportPointInfo

use of com.serotonin.m2m2.vo.export.ExportPointInfo 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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ArrayList(java.util.ArrayList) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MappedRowCallback(com.serotonin.db.MappedRowCallback) PointValueEmporter(com.serotonin.m2m2.rt.dataImage.PointValueEmporter) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with ExportPointInfo

use of com.serotonin.m2m2.vo.export.ExportPointInfo 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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) NoSQLQueryCallback(com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback) NoSQLDao(com.serotonin.m2m2.db.dao.nosql.NoSQLDao) ResultSet(java.sql.ResultSet) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ITime(com.serotonin.m2m2.view.stats.ITime) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 3 with ExportPointInfo

use of com.serotonin.m2m2.vo.export.ExportPointInfo 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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 4 with ExportPointInfo

use of com.serotonin.m2m2.vo.export.ExportPointInfo in project ma-modules-public by infiniteautomation.

the class ReportDao method deleteReportInstance.

/**
 * Delete the instance from the system
 * @param id
 * @param userId
 */
public void deleteReportInstance(int id, int userId) {
    if (Common.databaseProxy.getNoSQLProxy() != null) {
        // Delete the NoSQL Data
        final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
        List<ExportPointInfo> points = this.getReportInstancePoints(id);
        // Drop the series for these
        for (ExportPointInfo point : points) {
            dao.deleteStore(id + "_" + point.getReportPointId());
        }
    }
    int deleted = ejt.update("delete from reportInstances where id=? and userId=?", new Object[] { id, userId });
    instanceCountMonitor.addValue(-deleted);
}
Also used : ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) NoSQLDao(com.serotonin.m2m2.db.dao.nosql.NoSQLDao)

Example 5 with ExportPointInfo

use of com.serotonin.m2m2.vo.export.ExportPointInfo in project ma-modules-public by infiniteautomation.

the class ReportDao method purgeReportsBefore.

public int purgeReportsBefore(final long time) {
    // Check to see if we are using NoSQL
    if (Common.databaseProxy.getNoSQLProxy() == null) {
        return ejt.update("delete from reportInstances where runStartTime<? and preventPurge=?", new Object[] { time, boolToChar(false) });
    } else {
        // We need to get the report instances to delete first
        List<ReportInstance> instances = query(REPORT_INSTANCE_SELECT + "where runStartTime<? and preventPurge=?", new Object[] { time, boolToChar(false) }, new ReportInstanceRowMapper());
        final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
        for (ReportInstance instance : instances) {
            List<ExportPointInfo> points = this.getReportInstancePoints(instance.getId());
            // Drop the series for these
            for (ExportPointInfo point : points) {
                dao.deleteStore(instance.getId() + "_" + point.getReportPointId());
            }
        }
        int deleted = ejt.update("delete from reportInstances where runStartTime<? and preventPurge=?", new Object[] { time, boolToChar(false) });
        instanceCountMonitor.addValue(-deleted);
        return deleted;
    }
}
Also used : ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance) NoSQLDao(com.serotonin.m2m2.db.dao.nosql.NoSQLDao)

Aggregations

ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)4 NoSQLDao (com.serotonin.m2m2.db.dao.nosql.NoSQLDao)3 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 MappedRowCallback (com.serotonin.db.MappedRowCallback)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 NoSQLQueryCallback (com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback)1 Translations (com.serotonin.m2m2.i18n.Translations)1 ReportInstance (com.serotonin.m2m2.reports.vo.ReportInstance)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 PointValueEmporter (com.serotonin.m2m2.rt.dataImage.PointValueEmporter)1 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)1 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)1 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)1