Skip to content

Commit a0f8bd3

Browse files
committed
ModuleBatchProcessor: use BatchService to retrieve compatible inputs
1 parent c5075b9 commit a0f8bd3

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/main/java/org/scijava/batch/ModuleBatchProcessor.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Map.Entry;
88
import java.util.concurrent.ExecutionException;
99
import java.util.concurrent.Future;
10+
import java.util.stream.Collectors;
1011

1112
import net.imagej.table.Column;
1213
import net.imagej.table.DefaultGenericTable;
@@ -15,8 +16,7 @@
1516
import org.scijava.ItemIO;
1617
import org.scijava.command.Command;
1718
import org.scijava.command.DynamicCommand;
18-
import org.scijava.convert.ConvertService;
19-
import org.scijava.log.LogService;
19+
import org.scijava.log.Logger;
2020
import org.scijava.module.Module;
2121
import org.scijava.module.ModuleInfo;
2222
import org.scijava.module.ModuleItem;
@@ -29,17 +29,17 @@
2929
@Plugin(type = Command.class, label = "Choose batch processing parameters", initializer = "initInputChoice")
3030
public class ModuleBatchProcessor extends DynamicCommand {
3131
@Parameter
32-
private ModuleService modules;
32+
private ModuleService moduleService;
3333

3434
@Parameter
35-
private ConvertService convert;
36-
35+
private BatchService batchService;
36+
3737
@Parameter
38-
private LogService log;
39-
38+
private Logger log;
39+
4040
@Parameter
4141
private ModuleInfo moduleInfo; // to be provided at runtime!
42-
42+
4343
@Parameter(label = "Which input parameter to batch?", persist = false)
4444
private String inputChoice;
4545

@@ -57,23 +57,15 @@ public class ModuleBatchProcessor extends DynamicCommand {
5757

5858
protected void initInputChoice() {
5959
MutableModuleItem<String> choiceInput = getInfo().getMutableInput("inputChoice", String.class);
60-
// get compatible inputs from module
61-
ArrayList<String> compatibleInputs = new ArrayList<>();
62-
for (ModuleItem<?> input : moduleInfo.inputs()) {
63-
// TODO consider replacing by isAssignableFrom
64-
if (convert.supports(new File(""), input.getType())) {
65-
// if we can convert a File to the given input,
66-
// add it to the list of compatible inputs
67-
compatibleInputs.add(input.getName());
68-
}
69-
}
70-
// if only single input left, fill module input and resolve 'inputChoice'
60+
// Get compatible inputs for moduleInfo
61+
List<ModuleItem<?>> compatibleInputs = batchService
62+
.batchableInputs(moduleInfo);
7163
if (compatibleInputs.size() == 1) {
72-
choiceInput.setValue(this, compatibleInputs.get(0));
64+
choiceInput.setValue(this, compatibleInputs.get(0).getName());
7365
resolveInput("inputChoice");
74-
}
75-
else if (compatibleInputs.size() > 1) {
76-
choiceInput.setChoices(compatibleInputs);
66+
} else if (compatibleInputs.size() > 1) {
67+
choiceInput.setChoices(compatibleInputs.stream()
68+
.map(ModuleItem::getName).collect(Collectors.toList()));
7769
}
7870
}
7971

@@ -84,7 +76,7 @@ public void run() {
8476
// mark inputChoice as resolved, then harvest script parameters (i.e. run)
8577
ModuleItem<File> fileInput = moduleInfo.getInput(inputChoice, File.class);
8678
// TODO check if conversion needed?
87-
Module scriptModule = modules.createModule(moduleInfo);
79+
Module scriptModule = moduleService.createModule(moduleInfo);
8880
scriptModule.resolveInput(inputChoice);
8981

9082
/* Create output Table and mark all outputs as resolved */
@@ -117,7 +109,7 @@ private boolean processFile(Module module, ModuleItem<File> fileInput, File file
117109
fileInput.setValue(module, file);
118110
outputTable.appendRow(file.getName());
119111

120-
Future<Module> instance = modules.run(module, true);
112+
Future<Module> instance = moduleService.run(module, true);
121113
try {
122114
// run the script
123115
Map<String, Object> outputs = instance.get().getOutputs();

0 commit comments

Comments
 (0)