/** Sets the given module's input values to those in the given map. */ private void assignInputs(final Module module, final Map<String, Object> inputMap) { if (inputMap == null) return; // no inputs to assign for (final String name : inputMap.keySet()) { final ModuleItem<?> input = module.getInfo().getInput(name); final Object value = inputMap.get(name); final Object converted; if (input == null) { // inputs whose name starts with a dot are implicitly known by convention if (!name.startsWith(".")) { log.warn("Unmatched input: " + name); } converted = value; } else { final Class<?> type = input.getType(); converted = convertService.convert(value, type); if (value != null && converted == null) { log.error("For input " + name + ": incompatible object " + value.getClass().getName() + " for type " + type.getName()); continue; } } module.setInput(name, converted); module.resolveInput(name); } }
/** Sets the given module's input values to those in the given map. */ private void assignInputs(final Module module, final Map<String, Object> inputMap) { if (inputMap == null) return; // no inputs to assign for (final String name : inputMap.keySet()) { final ModuleItem<?> input = module.getInfo().getInput(name); final Object value = inputMap.get(name); final Object converted; if (input == null) { // inputs whose name starts with a dot are implicitly known by convention if (!name.startsWith(".")) { log.warn("Unmatched input: " + name); } converted = value; } else { final Class<?> type = input.getType(); converted = convertService.convert(value, type); if (value != null && converted == null) { log.error("For input " + name + ": incompatible object " + value.getClass().getName() + " for type " + type.getName()); continue; } } module.setInput(name, converted); module.resolveInput(name); } }
@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 }
@Test public void testGetSingleInput() throws ModuleException { final ModuleInfo info = new FooModuleInfo(); final Module module = info.createModule(); // verify single string input is detected final ModuleItem<String> singleString = moduleService.getSingleInput(module, String.class); assertSame(info.getInput("string"), singleString); // check that non-autofilled inputs are not detected final ModuleItem<Float> singleFloat = moduleService.getSingleInput(module, Float.class); assertNull(singleFloat); // verify that multiple inputs of the same type are not detected final ModuleItem<Integer> singleInteger = moduleService.getSingleInput(module, Integer.class); assertNull(singleInteger); // verify that single input is detected if there are // non-autofilled inputs of the same kind too final ModuleItem<Double> singleDouble = moduleService.getSingleInput(module, Double.class); assertSame(info.getInput("double2"), singleDouble); }