use of com.serotonin.m2m2.rt.script.DataPointStateException in project ma-core-public by MangoAutomation.
the class CompiledMangoJavaScript method initialize.
/**
* Clear the engine scope and initialize it with an expandable context which is filled with the ScriptContextVariables and returned
*
* @throws ScriptPermissionsException - permission denied executing a command
* @throws ScriptError - Execution failure, generally will have line and column number with message
* @throws DataPointStateException - If a point is not enabled or missing (unless testRun is true, then a dummy point is created)
*/
public Map<String, IDataPointValueSource> initialize(List<ScriptContextVariable> variables) throws ScriptPermissionsException, ScriptError, DataPointStateException {
Map<String, IDataPointValueSource> context = new HashMap<>();
if (variables != null) {
for (ScriptContextVariable variable : variables) {
DataPointVO dpvo = DataPointDao.getInstance().get(variable.getDataPointId());
if (dpvo != null) {
DataPointRT dprt = Common.runtimeManager.getDataPoint(dpvo.getId());
// So we can test with points disabled
if (dprt == null) {
if (testRun) {
if (dpvo.getDefaultCacheSize() == 0) {
dpvo.setDefaultCacheSize(1);
}
// Generate some fake event detectors
DataPointWithEventDetectors dp = new DataPointWithEventDetectors(dpvo, new ArrayList<>());
DataSourceRT<? extends DataSourceVO> dataSource = DataSourceDao.getInstance().get(dpvo.getDataSourceId()).createDataSourceRT();
dprt = new DataPointRT(dp, dpvo.getPointLocator().createRuntime(), dataSource, null, pointValueDao, pointValueCache);
} else {
throw new DataPointStateException(variable.getDataPointId(), new TranslatableMessage("event.script.contextPointDisabled", variable.getVariableName(), dpvo.getXid()));
}
}
if (dprt != null)
context.put(variable.getVariableName(), dprt);
} else {
throw new DataPointStateException(variable.getDataPointId(), new TranslatableMessage("event.script.contextPointMissing", variable.getVariableName(), variable.getDataPointId()));
}
}
}
this.initialize(context);
return context;
}
Aggregations