use of com.serotonin.m2m2.vo.event.ScriptEventHandlerVO in project ma-core-public by MangoAutomation.
the class ScriptEventHandlerDefinition method validate.
@Override
public void validate(ProcessResult response, ScriptEventHandlerVO existing, ScriptEventHandlerVO vo) {
commonValidation(response, vo);
if (vo.getScriptRoles() == null) {
response.addContextualMessage("scriptRoles", "validate.permission.null");
} else {
PermissionHolder user = Common.getUser();
Set<Role> roles = existing.getScriptRoles() == null ? null : existing.getScriptRoles();
permissionService.validatePermissionHolderRoles(response, "scriptRoles", user, vo.getScriptRoles());
}
}
use of com.serotonin.m2m2.vo.event.ScriptEventHandlerVO in project ma-core-public by MangoAutomation.
the class ScriptEventHandlerDefinition method createRuntimeInternal.
private ScriptEventHandlerRT createRuntimeInternal(ScriptEventHandlerVO vo) {
Map<String, Object> bindings = Collections.singletonMap(ScriptEventHandlerRT.EVENT_HANDLER_KEY, vo);
EvalContext context = new EvalContext(bindings);
PermissionHolder user = Common.getUser();
if (permissionService.hasPermission(user, standardStreamsPermission.getPermission())) {
context.setWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
context.setErrorWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
context.setReader(new BufferedReader(new InputStreamReader(System.in)));
}
EventHandlerInterface scriptHandlerDelegate = scriptService.getInterface(vo.toMangoScript(), EventHandlerInterface.class, context);
return new ScriptEventHandlerRT(vo, scriptHandlerDelegate);
}
use of com.serotonin.m2m2.vo.event.ScriptEventHandlerVO in project ma-modules-public by infiniteautomation.
the class ScriptEventHandlerModel method newVO.
@Override
protected ScriptEventHandlerVO newVO() {
ScriptEventHandlerVO handler = new ScriptEventHandlerVO();
handler.setDefinition(ModuleRegistry.getEventHandlerDefinition(ScriptEventHandlerDefinition.TYPE_NAME));
return handler;
}
use of com.serotonin.m2m2.vo.event.ScriptEventHandlerVO in project ma-core-public by infiniteautomation.
the class ScriptEventHandlerDefinition method createRuntimeInternal.
private ScriptEventHandlerRT createRuntimeInternal(ScriptEventHandlerVO vo) {
Map<String, Object> bindings = Collections.singletonMap(ScriptEventHandlerRT.EVENT_HANDLER_KEY, vo);
EvalContext context = new EvalContext(bindings);
PermissionHolder user = Common.getUser();
if (permissionService.hasPermission(user, standardStreamsPermission.getPermission())) {
context.setWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
context.setErrorWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
context.setReader(new BufferedReader(new InputStreamReader(System.in)));
}
EventHandlerInterface scriptHandlerDelegate = scriptService.getInterface(vo.toMangoScript(), EventHandlerInterface.class, context);
return new ScriptEventHandlerRT(vo, scriptHandlerDelegate);
}
use of com.serotonin.m2m2.vo.event.ScriptEventHandlerVO in project ma-modules-public by infiniteautomation.
the class ScriptEventHandlerModel method readInto.
@Override
public void readInto(ScriptEventHandlerVO vo) {
super.readInto(vo);
vo.setScript(this.script);
vo.setEngineName(this.engineName);
RoleService roleService = Common.getBean(RoleService.class);
Set<Role> roleXids = scriptRoles.stream().map(xid -> {
try {
return roleService.get(xid).getRole();
} catch (NotFoundException e) {
return null;
}
}).filter(r -> r != null).collect(Collectors.toSet());
vo.setScriptRoles(roleXids);
}
Aggregations