@Override
  public void run(String script, CoreSession session) throws ScriptException, OperationException {
    ScriptEngine engine = engines.get();
    engine.setContext(new SimpleScriptContext());
    engine.eval(getJSWrapper());

    // Initialize Operation Context
    if (operationContext == null) {
      operationContext = operationContexts.get();
      operationContext.setCoreSession(session);
    }

    // Injecting Automation Mapper 'automation'
    AutomationMapper automationMapper = new AutomationMapper(session, operationContext);
    engine.put(AutomationScriptingConstants.AUTOMATION_MAPPER_KEY, automationMapper);

    // Inject operation context vars in 'Context'
    engine.put(AutomationScriptingConstants.AUTOMATION_CTX_KEY, automationMapper.ctx.getVars());
    // Session injection
    engine.put("Session", automationMapper.ctx.getCoreSession());
    // User injection
    PrincipalWrapper principalWrapper =
        new PrincipalWrapper((NuxeoPrincipal) automationMapper.ctx.getPrincipal());
    engine.put("CurrentUser", principalWrapper);
    engine.put("currentUser", principalWrapper);
    // Env Properties injection
    engine.put("Env", Framework.getProperties());
    // DateWrapper injection
    engine.put("CurrentDate", new DateWrapper());
    // Workflow variables injection
    if (automationMapper.ctx.get(Constants.VAR_WORKFLOW) != null) {
      engine.put(Constants.VAR_WORKFLOW, automationMapper.ctx.get(Constants.VAR_WORKFLOW));
    }
    if (automationMapper.ctx.get(Constants.VAR_WORKFLOW_NODE) != null) {
      engine.put(
          Constants.VAR_WORKFLOW_NODE, automationMapper.ctx.get(Constants.VAR_WORKFLOW_NODE));
    }

    // Helpers injection
    ContextService contextService = Framework.getService(ContextService.class);
    Map<String, ContextHelper> helperFunctions = contextService.getHelperFunctions();
    for (String helperFunctionsId : helperFunctions.keySet()) {
      engine.put(helperFunctionsId, helperFunctions.get(helperFunctionsId));
    }
    engine.eval(script);
  }
 protected ScriptOperationContext wrapContext(ScriptOperationContext ctx) {
   for (String entryId : ctx.keySet()) {
     Object entry = ctx.get(entryId);
     if (entry instanceof DocumentModel) {
       ctx.put(entryId, new DocumentWrapper(ctx.getCoreSession(), (DocumentModel) entry));
     }
     if (entry instanceof DocumentModelList) {
       List<DocumentWrapper> docs = new ArrayList<>();
       for (DocumentModel doc : (DocumentModelList) entry) {
         docs.add(new DocumentWrapper(ctx.getCoreSession(), doc));
       }
       ctx.put(entryId, docs);
     }
   }
   return ctx;
 }