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()));
}
}
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;
}
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));
}
}
}
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);
}
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());
}
Aggregations