public <C extends Command> Module executeCommand(final Class<C> cmdClass, final Map<String, Object> inputs) { final Module module = moduleService.createModule(cmdService.getCommand(cmdClass)); try { module.initialize(); } catch (final MethodCallException ex) { ex.printStackTrace(); } if (inputs != null) { inputs.forEach((k, v) -> { module.setInput(k, v); module.resolveInput(k); }); } cmdService.run(cmdClass, true, inputs); module.run(); final Future<Module> run = moduleService.run(module, true, inputs); try { run.get(); } catch (final InterruptedException ex) { ex.printStackTrace(); } catch (final ExecutionException ex) { ex.printStackTrace(); } return module; }
@Override public void run() { // mark inputChoice as resolved, then harvest script parameters (i.e. run) ModuleItem<?> inputModuleItem = moduleInfo.getInput(inputChoice); // TODO check if conversion needed? Module scriptModule = moduleService.createModule(moduleInfo); scriptModule.resolveInput(inputChoice); /* Create output Table and mark all outputs as resolved */ outputTable = new DefaultGenericTable(); @SuppressWarnings("rawtypes") List<Column> columns = new ArrayList<>(); for (String outputKey : scriptModule.getOutputs().keySet()) { columns.add(outputTable.appendColumn(outputKey)); scriptModule.resolveOutput(outputKey); } for (File file : inputFileList) { if(!processFile(scriptModule, inputModuleItem, file)) { log.warn("Terminating batch process."); break; // end for loop } } // case File // feed files into input // case Image (not needed if conversion works // open each file as image (warn on errors) and feed image into input }
/** Helper method of {@link #match(OpCandidate, Object[])}. */ private Module createModule(final OpCandidate candidate, final Object... args) { // create the module final Module module = moduleService.createModule(candidate.cInfo()); // unwrap the created op final Op op = OpUtils.unwrap(module, candidate.getRef()); // inject the op execution environment op.setEnvironment(candidate.ops()); // populate the inputs and return the module return assignInputs(module, args); }