Search in sources :

Example 91 with PointValueTime

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

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

the class DataPointDetailsDwr method getFlipbookData.

@DwrPermission(user = true)
public ProcessResult getFlipbookData(int limit) {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    DataPointVO vo = Common.getUser(request).getEditPoint();
    PointValueFacade facade = new PointValueFacade(vo.getId());
    List<PointValueTime> values = facade.getLatestPointValues(limit);
    Collections.reverse(values);
    List<ImageValueBean> result = new ArrayList<ImageValueBean>();
    for (PointValueTime pvt : values) {
        ImageValue imageValue = (ImageValue) pvt.getValue();
        String uri = ImageValueServlet.servletPath + ImageValueServlet.historyPrefix + pvt.getTime() + "_" + vo.getId() + "." + imageValue.getTypeExtension();
        result.add(new ImageValueBean(Functions.getTime(pvt), uri));
    }
    ProcessResult response = new ProcessResult();
    response.addData("images", result);
    addAsof(response);
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) 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) ImageValueBean(com.serotonin.m2m2.vo.bean.ImageValueBean) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 93 with PointValueTime

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

the class DataPointDwr method getMostRecentValue.

/**
 * Helper to get the most recent value for a point
 *
 * @param id
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getMostRecentValue(int id) {
    ProcessResult result = new ProcessResult();
    if (Common.runtimeManager.isDataPointRunning(id)) {
        DataPointRT rt = Common.runtimeManager.getDataPoint(id);
        // Check to see if the data source is running
        if (Common.runtimeManager.isDataSourceRunning(rt.getDataSourceId())) {
            PointValueFacade facade = new PointValueFacade(rt.getVO().getId());
            PointValueTime value = facade.getPointValue();
            if (value != null) {
                RenderedPointValueTime rpvt = new RenderedPointValueTime();
                rpvt.setValue(Functions.getHtmlText(rt.getVO(), value));
                rpvt.setTime(Functions.getTime(value));
                // Could return time and value?
                result.getData().put("pointValue", rpvt.getValue());
            } else
                result.getData().put("pointValue", translate("event.setPoint.activePointValue"));
        } else {
            result.getData().put("pointValue", translate("common.pointWarning"));
        }
    } else {
        result.getData().put("pointValue", translate("common.pointWarning"));
    }
    return result;
}
Also used : PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) RenderedPointValueTime(com.serotonin.m2m2.web.dwr.beans.RenderedPointValueTime) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) RenderedPointValueTime(com.serotonin.m2m2.web.dwr.beans.RenderedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 94 with PointValueTime

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

the class RuntimeManagerImpl method startDataPointStartup.

/**
 * Only to be used at startup as synchronization has been reduced for performance
 * @param vo
 * @param latestValue
 */
private void startDataPointStartup(DataPointVO vo, List<PointValueTime> initialCache) {
    Assert.isTrue(vo.isEnabled(), "Data point not enabled");
    // Only add the data point if its data source is enabled.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(vo.getDataSourceId());
    if (ds != null) {
        // Change the VO into a data point implementation.
        DataPointRT dataPoint = new DataPointRT(vo, vo.getPointLocator().createRuntime(), ds.getVo(), initialCache);
        // Add/update it in the data image.
        synchronized (dataPoints) {
            dataPoints.compute(dataPoint.getId(), (k, rt) -> {
                if (rt != null) {
                    try {
                        getRunningDataSource(rt.getDataSourceId()).removeDataPoint(rt);
                    } catch (Exception e) {
                        LOG.error("Failed to stop point RT with ID: " + vo.getId() + " stopping point.", e);
                    }
                    DataPointListener l = getDataPointListeners(vo.getId());
                    if (l != null)
                        l.pointTerminated();
                    rt.terminate();
                }
                return dataPoint;
            });
        }
        // Initialize it.
        dataPoint.initialize();
        // If we are a polling data source then we need to wait to start our interval logging
        // until the first poll due to quantization
        boolean isPolling = ds instanceof PollingDataSource;
        // If we are not polling go ahead and start the interval logging, otherwise we will let the data source do it on the first poll
        if (!isPolling)
            dataPoint.initializeIntervalLogging(0l, false);
        DataPointListener l = getDataPointListeners(vo.getId());
        if (l != null)
            l.pointInitialized();
        // Add/update it in the data source.
        try {
            ds.addDataPoint(dataPoint);
        } catch (Exception e) {
            // This can happen if there is a corrupt DB with a point for a different
            // data source type linked to this data source...
            LOG.error("Failed to start point with xid: " + dataPoint.getVO().getXid() + " disabling point.", e);
            // TODO Fire Alarm to warn user.
            dataPoint.getVO().setEnabled(false);
            // Stop it
            saveDataPoint(dataPoint.getVO());
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource)

Example 95 with PointValueTime

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

the class RuntimeManagerImpl method setDataPointValue.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#setDataPointValue(int, com.serotonin.m2m2.rt.dataImage.PointValueTime, com.serotonin.m2m2.rt.dataImage.SetPointSource)
     */
@Override
public void setDataPointValue(int dataPointId, PointValueTime valueTime, SetPointSource source) {
    DataPointRT dataPoint = dataPoints.get(dataPointId);
    if (dataPoint == null)
        throw new RTException("Point is not enabled");
    if (!dataPoint.getPointLocator().isSettable())
        throw new RTException("Point is not settable");
    // Tell the data source to set the value of the point.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(dataPoint.getDataSourceId());
    // The data source may have been disabled. Just make sure.
    if (ds != null)
        ds.setPointValue(dataPoint, valueTime, source);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)104 ArrayList (java.util.ArrayList)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)24 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)23 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)23 IOException (java.io.IOException)18 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)17 HashMap (java.util.HashMap)17 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)15 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)12 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)11 ScriptException (javax.script.ScriptException)10 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)9 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)9 LogStopWatch (com.serotonin.log.LogStopWatch)8 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8