Search in sources :

Example 16 with AnnotatedPointValueTime

use of com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime in project ma-core-public by infiniteautomation.

the class DataPointDetailsDwr method getHistoryTableData.

@DwrPermission(user = true)
public ProcessResult getHistoryTableData(int limit, boolean useCache) {
    DataPointVO pointVO = Common.getUser().getEditPoint();
    PointValueFacade facade = new PointValueFacade(pointVO.getId(), useCache);
    List<PointValueTime> rawData = facade.getLatestPointValues(limit);
    List<RenderedPointValueTime> renderedData = new ArrayList<RenderedPointValueTime>(rawData.size());
    for (PointValueTime pvt : rawData) {
        RenderedPointValueTime rpvt = new RenderedPointValueTime();
        rpvt.setValue(Functions.getHtmlText(pointVO, pvt));
        rpvt.setTime(Functions.getTime(pvt));
        if (pvt.isAnnotated()) {
            AnnotatedPointValueTime apvt = (AnnotatedPointValueTime) pvt;
            rpvt.setAnnotation(apvt.getAnnotation(getTranslations()));
        }
        renderedData.add(rpvt);
    }
    ProcessResult response = new ProcessResult();
    response.addData("history", renderedData);
    addAsof(response);
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) RenderedPointValueTime(com.serotonin.m2m2.web.dwr.beans.RenderedPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) RenderedPointValueTime(com.serotonin.m2m2.web.dwr.beans.RenderedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 17 with AnnotatedPointValueTime

use of com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime 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

AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)15 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)6 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)5 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)3 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)3 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)3 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)3 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)3 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)3 RecentPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel)3 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)2