Search in sources :

Example 1 with ScriptEventHandlerVO

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());
    }
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 2 with ScriptEventHandlerVO

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);
}
Also used : ScriptEventHandlerRT(com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT) InputStreamReader(java.io.InputStreamReader) EvalContext(com.infiniteautomation.mango.spring.script.EvalContext) BufferedReader(java.io.BufferedReader) EventHandlerInterface(com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface) OutputStreamWriter(java.io.OutputStreamWriter) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) BufferedWriter(java.io.BufferedWriter)

Example 3 with ScriptEventHandlerVO

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;
}
Also used : ScriptEventHandlerVO(com.serotonin.m2m2.vo.event.ScriptEventHandlerVO)

Example 4 with ScriptEventHandlerVO

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);
}
Also used : ScriptEventHandlerRT(com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT) InputStreamReader(java.io.InputStreamReader) EvalContext(com.infiniteautomation.mango.spring.script.EvalContext) BufferedReader(java.io.BufferedReader) EventHandlerInterface(com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface) OutputStreamWriter(java.io.OutputStreamWriter) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) BufferedWriter(java.io.BufferedWriter)

Example 5 with ScriptEventHandlerVO

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);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) Role(com.serotonin.m2m2.vo.role.Role) Common(com.serotonin.m2m2.Common) ScriptEventHandlerVO(com.serotonin.m2m2.vo.event.ScriptEventHandlerVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) Set(java.util.Set) ApiModel(io.swagger.annotations.ApiModel) ScriptEventHandlerDefinition(com.serotonin.m2m2.module.definitions.event.handlers.ScriptEventHandlerDefinition) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) RoleService(com.infiniteautomation.mango.spring.service.RoleService) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) RoleService(com.infiniteautomation.mango.spring.service.RoleService) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)4 Role (com.serotonin.m2m2.vo.role.Role)3 EvalContext (com.infiniteautomation.mango.spring.script.EvalContext)2 EventHandlerInterface (com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface)2 ScriptEventHandlerRT (com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT)2 ScriptEventHandlerVO (com.serotonin.m2m2.vo.event.ScriptEventHandlerVO)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)1 RoleService (com.infiniteautomation.mango.spring.service.RoleService)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 Common (com.serotonin.m2m2.Common)1 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)1 ScriptEventHandlerDefinition (com.serotonin.m2m2.module.definitions.event.handlers.ScriptEventHandlerDefinition)1 ApiModel (io.swagger.annotations.ApiModel)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1