示例#1
0
  @Override
  public StepExecutionResult executeImplementation(StepExecutionContext context)
      throws MuseExecutionError {
    StepConfiguration config = getConfiguration();
    HashMap<String, Object> values = new HashMap<>();
    for (String name : config.getSourceNames()) {
      MuseValueSource source = getValueSource(config, name, false, context.getProject());
      values.put(name, getValue(source, context, true, Object.class));
    }

    try {
      JavascriptRunner runner = new JavascriptStepRunner();
      runner.evalScript(_origin);

      Object result = runner.invokeFunction(EXECUTE_FUNCTION, context, values);
      if (result instanceof StepExecutionResult) return (StepExecutionResult) result;
      else
        context.raiseEvent(
            new ScriptFailureEvent(
                "Script did not return a StepExecutionResult. Instead, it returned: " + result,
                null)); // TODO do something better than n/a
    } catch (Throwable t) {
      LOG.error("unable to execute script: ", t);
      context.raiseEvent(
          new ScriptFailureEvent(
              "Script threw an exception: " + t.getMessage(),
              t)); // TODO do something better than n/a
    }
    return new BasicStepExecutionResult(StepExecutionStatus.FAILURE);
  }
 private List<String> getNodeNames(StepExecutionContext executionContext) {
   List<INodeEntry> orderedNodes =
       INodeEntryComparator.rankOrderedNodes(
           executionContext.getNodes(),
           executionContext.getNodeRankAttribute(),
           executionContext.isNodeRankOrderAscending());
   List<String> names = new ArrayList<String>();
   for (INodeEntry orderedNode : orderedNodes) {
     names.add(orderedNode.getNodename());
   }
   return names;
 }