Ejemplo n.º 1
0
 protected static String defaultProperty(String name, String def) {
   String value = System.getProperty(name);
   if (value == null || value.equals("") || value.equals("${" + name + "}")) {
     value = def;
   }
   Framework.getProperties().setProperty(name, value);
   return value;
 }
  @Test
  public void testPipeConnection() throws Exception {
    Framework.getProperties()
        .load(new FileInputStream(tc.getResource("jodPipe.properties").getFile()));
    ods = Framework.getLocalService(OOoManagerService.class);
    assertNotNull(ods);

    ods.startOOoManager();
    OfficeDocumentConverter converter = ods.getDocumentConverter();
    assertNotNull(converter);
  }
  @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);
  }
 @AfterClass
 public static void afterClass() {
   // Cleanup keys
   Properties props = Framework.getProperties();
   PARAMETERS.forEach(props::remove);
 }