File tree Expand file tree Collapse file tree 5 files changed +154
-1
lines changed
main/java/org/scijava/batch
test/java/org/scijava/batch Expand file tree Collapse file tree 5 files changed +154
-1
lines changed Original file line number Diff line number Diff line change 88 <parent >
99 <groupId >org.scijava</groupId >
1010 <artifactId >pom-scijava</artifactId >
11- <version >17.1.1 </version >
11+ <version >18.0.0 </version >
1212 <relativePath />
1313 </parent >
1414
100100 <artifactId >scijava-common</artifactId >
101101 </dependency >
102102 <dependency >
103+ <!-- TODO: remove this dependency when table support moved to SciJava -->
103104 <groupId >net.imagej</groupId >
104105 <artifactId >imagej</artifactId >
105106 </dependency >
106107 <dependency >
107108 <groupId >org.scijava</groupId >
108109 <artifactId >scijava-ui-swing</artifactId >
109110 </dependency >
111+ <dependency >
112+ <groupId >org.scijava</groupId >
113+ <artifactId >scijava-search</artifactId >
114+ </dependency >
110115 <dependency >
111116 <groupId >commons-io</groupId >
112117 <artifactId >commons-io</artifactId >
113118 <version >2.4</version >
114119 </dependency >
120+ <dependency >
121+ <groupId >junit</groupId >
122+ <artifactId >junit</artifactId >
123+ <scope >test</scope >
124+ </dependency >
115125 </dependencies >
116126</project >
Original file line number Diff line number Diff line change 1+ package org .scijava .batch ;
2+
3+ import org .scijava .plugin .Parameter ;
4+ import org .scijava .plugin .Plugin ;
5+ import org .scijava .search .DefaultSearchAction ;
6+ import org .scijava .search .SearchAction ;
7+ import org .scijava .search .SearchActionFactory ;
8+ import org .scijava .search .SearchResult ;
9+ import org .scijava .search .module .ModuleSearchResult ;
10+
11+ /**
12+ * Search action for executing a SciJava module in batch mode.
13+ *
14+ * @author Jan Eglinger
15+ */
16+ @ Plugin (type = SearchActionFactory .class )
17+ public class BatchModuleSearchActionFactory implements SearchActionFactory {
18+
19+ @ Parameter
20+ private BatchService batchService ;
21+
22+ @ Override
23+ public boolean supports (final SearchResult result ) {
24+ return (result instanceof ModuleSearchResult )
25+ && batchService .supports (((ModuleSearchResult ) result ).info ());
26+ }
27+
28+ @ Override
29+ public SearchAction create (final SearchResult result ) {
30+ return new DefaultSearchAction ("Batch" , true , () -> {
31+ batchService .run (((ModuleSearchResult ) result ).info ());
32+ });
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package org .scijava .batch ;
2+
3+ import java .util .List ;
4+ import java .util .stream .Collectors ;
5+ import java .util .stream .StreamSupport ;
6+
7+ import org .scijava .module .ModuleInfo ;
8+ import org .scijava .module .ModuleItem ;
9+ import org .scijava .service .SciJavaService ;
10+
11+ public interface BatchService extends SciJavaService {
12+ /**
13+ * Returns true if {@code moduleInfo} has at least one input item whose type
14+ * is supported by this service
15+ */
16+ default public boolean supports (ModuleInfo moduleInfo ) {
17+ for (ModuleItem <?> input : moduleInfo .inputs ()) {
18+ if (supports (input .getType ()))
19+ return true ;
20+ }
21+ return false ;
22+ }
23+
24+ /**
25+ * Returns true if {@code type} can be populated with batch inputs provided
26+ * by this service
27+ */
28+ public boolean supports (Class <?> type );
29+
30+ /**
31+ * Run the module described by {@link ModuleInfo} in batch.
32+ */
33+ public void run (ModuleInfo moduleInfo );
34+
35+ /**
36+ * A collection of input {@link ModuleItem}s of the given {@link ModuleInfo}
37+ * that are supported (i.e. can be batch-processed) by this service
38+ */
39+ default public List <ModuleItem <?>> batchableInputs (ModuleInfo moduleInfo ) {
40+ return StreamSupport .stream (moduleInfo .inputs ().spliterator (), false )
41+ .filter (item -> supports (item .getType ()))
42+ .collect (Collectors .toList ());
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ package org .scijava .batch ;
2+
3+ import java .io .File ;
4+ import java .util .HashMap ;
5+
6+ import org .scijava .Priority ;
7+ import org .scijava .command .CommandService ;
8+ import org .scijava .module .ModuleInfo ;
9+ import org .scijava .plugin .Parameter ;
10+ import org .scijava .plugin .Plugin ;
11+ import org .scijava .service .AbstractService ;
12+ import org .scijava .service .Service ;
13+
14+ @ Plugin (type = Service .class , priority = Priority .LOW )
15+ public final class FileBatchService extends AbstractService implements
16+ BatchService {
17+
18+ @ Parameter
19+ private CommandService commandService ;
20+
21+ /**
22+ * Returns true if {@code type} is a {@link File}.
23+ */
24+ @ Override
25+ public boolean supports (Class <?> type ) {
26+ return type .isAssignableFrom (File .class );
27+ }
28+
29+ @ Override
30+ public void run (ModuleInfo moduleInfo ) {
31+ // Call ModuleBatchProcessor with input moduleInfo
32+ HashMap <String , Object > inputMap = new HashMap <>();
33+ inputMap .put ("moduleInfo" , moduleInfo );
34+ commandService .run (ModuleBatchProcessor .class , true , inputMap );
35+ }
36+
37+ }
Original file line number Diff line number Diff line change 1+ package org .scijava .batch ;
2+
3+ import static org .junit .Assert .assertNotNull ;
4+
5+ import org .junit .After ;
6+ import org .junit .Test ;
7+ import org .scijava .Context ;
8+
9+ public class BatchServiceTest {
10+
11+ private Context context ;
12+
13+ @ After
14+ public void disposeContext () {
15+ if (context != null ) {
16+ context .dispose ();
17+ context = null ;
18+ }
19+ }
20+
21+ @ Test
22+ public void testContext () {
23+ context = new Context (BatchService .class );
24+ final BatchService batchService =
25+ context .getService (BatchService .class );
26+ assertNotNull (batchService );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments