Search in sources :

Example 66 with PointValueTime

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

the class AsciiFileDataSourceRT method fileEvent.

private void fileEvent(List<DataPointRT> dataPoints) {
    // Should never happen
    if (this.file == null) {
        raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailedFileNotSetup"));
        return;
    }
    if (restrictedPath) {
        raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("dsEdit.file.pathRestrictedBy", vo.getFilePath()));
        return;
    }
    // The file is modified or we've just started, so read it.
    try {
        BufferedReader reader = new BufferedReader(new FileReader(this.file));
        String msg;
        if (!dataPoints.isEmpty()) {
            // TODO optimize to be better than numLines*numPoints
            while ((msg = reader.readLine()) != null) {
                // Give all points the chance to find their data
                for (final DataPointRT dp : dataPoints) {
                    AsciiFilePointLocatorRT pl = dp.getPointLocator();
                    final AsciiFilePointLocatorVO plVo = pl.getVo();
                    MatchCallback callback = new MatchCallback() {

                        @Override
                        public void onMatch(String pointIdentifier, PointValueTime value) {
                            if (!plVo.getHasTimestamp())
                                dp.updatePointValue(value);
                            else
                                dp.savePointValueDirectToCache(value, null, true, true);
                        }

                        @Override
                        public void pointPatternMismatch(String message, String pointValueRegex) {
                        // N/A
                        }

                        @Override
                        public void messagePatternMismatch(String message, String messageRegex) {
                        // N/A
                        }

                        @Override
                        public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
                            raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), false, new TranslatableMessage("file.event.insufficientGroups", dp.getVO().getExtendedName()));
                        }

                        @Override
                        public void matchGeneralFailure(Exception e) {
                            if (e instanceof ParseException)
                                raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.dateParseFailed", e.getMessage()));
                            else if (e instanceof NumberFormatException) {
                                raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
                            } else
                                raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
                        }
                    };
                    matchPointValueTime(msg, pl.getValuePattern(), plVo.getPointIdentifier(), plVo.getPointIdentifierIndex(), plVo.getDataTypeId(), plVo.getValueIndex(), plVo.getHasTimestamp(), plVo.getTimestampIndex(), plVo.getTimestampFormat(), callback);
                }
            }
            reader.close();
            returnToNormal(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis());
        }
    } catch (FileNotFoundException e) {
        raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound", e.getMessage()));
    } catch (IOException e) {
        raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
    } catch (NumberFormatException e) {
        raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MatchCallback(com.infiniteautomation.mango.regex.MatchCallback) IOException(java.io.IOException) AsciiFilePointLocatorVO(com.infiniteautomation.asciifile.vo.AsciiFilePointLocatorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) BufferedReader(java.io.BufferedReader) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) FileReader(java.io.FileReader) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ParseException(java.text.ParseException)

Example 67 with PointValueTime

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

the class GraphicalViewDwr method preparePointComponentState.

/**
 * Shared convenience method for creating a populated view component state.
 */
private ViewComponentState preparePointComponentState(PointComponent pointComponent, boolean update, User user, DataPointRT point, Map<String, Object> model, HttpServletRequest request) {
    ViewComponentState state = new ViewComponentState();
    state.setId(pointComponent.getId());
    PointValueTime pointValue = prepareBasePointState(pointComponent.getId(), state, pointComponent.tgetDataPoint(), point, model);
    model.put("pointComponent", pointComponent);
    if (pointComponent.isValid()) {
        if (!update && pointComponent.getCachedContent(MODEL_ATTR_EVENTS) != null)
            model.put(MODEL_ATTR_EVENTS, pointComponent.getCachedContent(MODEL_ATTR_EVENTS));
        else {
            setEvents(pointComponent.tgetDataPoint(), user, model, pointEventsLimit);
            pointComponent.putCachedContent(MODEL_ATTR_EVENTS, model.get(MODEL_ATTR_EVENTS));
        }
    }
    pointComponent.addDataToModel(model, pointValue);
    if (!pointComponent.isValid())
        model.put("invalid", "true");
    else {
        // Add the rendered text as a convenience to the snippets.
        model.put("text", pointComponent.tgetDataPoint().getTextRenderer().getText(pointValue, TextRenderer.HINT_FULL));
        state.setContent(generateViewContent(pointComponent, update, request, pointComponent.snippetName() + ".jsp", model));
        pointComponent.tgetDataPoint().updateLastValue(pointValue);
    }
    state.setInfo(generateViewContent(pointComponent, update, request, "infoContent.jsp", model));
    // TODO Cache this
    setMessages(state, request, getFullSnippetName("warningContent.jsp"), model);
    return state;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 68 with PointValueTime

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

the class InternalDataSourceRT method doPoll.

@Override
public void doPoll(long time) {
    if (createsPoints) {
        for (ValueMonitor<?> m : Common.MONITORED_VALUES.getMonitors()) {
            if (createPointsPattern.matcher(m.getId()).matches() && !monitorMap.containsKey(m.getId()))
                createMonitorPoint(m);
        }
    }
    for (DataPointRT dataPoint : dataPoints) {
        InternalPointLocatorRT locator = dataPoint.getPointLocator();
        ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
        if (m != null) {
            if (m instanceof IntegerMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), time));
            else if (m instanceof LongMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), time));
            else if (m instanceof DoubleMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), time));
            else if (m instanceof AtomicIntegerMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), time));
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) LongMonitor(com.infiniteautomation.mango.monitor.LongMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) DoubleMonitor(com.infiniteautomation.mango.monitor.DoubleMonitor)

Example 69 with PointValueTime

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

the class ScriptComponent method addDataToModel.

@Override
public void addDataToModel(Map<String, Object> model, PointValueTime value) {
    String result;
    if (value == null)
        result = "--";
    else {
        // Create the script engine.
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        DataPointVO point = tgetDataPoint();
        // Put the values into the engine scope.
        engine.put("value", value.getValue().getObjectValue());
        engine.put("htmlText", Functions.getHtmlText(point, value));
        engine.put("renderedText", Functions.getRenderedText(point, value));
        engine.put("time", value.getTime());
        engine.put("pointComponent", this);
        engine.put("point", point);
        // Copy properties from the model into the engine scope.
        engine.put(BaseDwr.MODEL_ATTR_EVENTS, model.get(BaseDwr.MODEL_ATTR_EVENTS));
        engine.put(BaseDwr.MODEL_ATTR_HAS_UNACKED_EVENT, model.get(BaseDwr.MODEL_ATTR_HAS_UNACKED_EVENT));
        engine.put(BaseDwr.MODEL_ATTR_TRANSLATIONS, model.get(BaseDwr.MODEL_ATTR_TRANSLATIONS));
        // Create the script.
        String evalScript = SCRIPT_PREFIX + script + SCRIPT_SUFFIX;
        // Execute.
        try {
            Object o = engine.eval(evalScript);
            if (o == null)
                result = null;
            else
                result = o.toString();
        } catch (ScriptException e) {
            e = ScriptExecutor.prettyScriptMessage(e);
            result = e.getMessage();
        }
    }
    model.put("scriptContent", result);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ScriptException(javax.script.ScriptException) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 70 with PointValueTime

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

the class SimpleImageComponent method addDataToModel.

@Override
public void addDataToModel(Map<String, Object> model, PointValueTime pointValue) {
    if (pointValue == null || pointValue.getValue() == null) {
        model.put("error", "common.noData");
        return;
    }
    if (!(pointValue.getValue() instanceof ImageValue)) {
        model.put("error", "common.thumb.invalidValue");
        return;
    }
    ImageValue imageValue = (ImageValue) pointValue.getValue();
    model.put("imageType", imageValue.getTypeExtension());
}
Also used : ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

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