33import lombok .Getter ;
44import lombok .Setter ;
55import org .apache .commons .lang3 .StringUtils ;
6- import org .apache .logging .log4j .Logger ;
76import org .labkey .api .action .ApiResponse ;
87import org .labkey .api .action .ApiSimpleResponse ;
98import org .labkey .api .action .FormViewAction ;
1413import org .labkey .api .data .PropertyStore ;
1514import org .labkey .api .pipeline .PipeRoot ;
1615import org .labkey .api .pipeline .PipelineJob ;
16+ import org .labkey .api .pipeline .PipelineProvider ;
1717import org .labkey .api .pipeline .PipelineService ;
1818import org .labkey .api .pipeline .PipelineStatusUrls ;
1919import org .labkey .api .pipeline .browse .PipelinePathForm ;
3131import org .labkey .api .util .Path ;
3232import org .labkey .api .util .URLHelper ;
3333import org .labkey .api .util .element .Select ;
34- import org .labkey .api .util .logging .LogHelper ;
3534import org .labkey .api .view .HtmlView ;
3635import org .labkey .api .view .JspView ;
3736import org .labkey .api .view .NavTree ;
3837import org .labkey .api .view .UnauthorizedException ;
3938import org .labkey .api .view .ViewBackgroundInfo ;
4039import org .labkey .nextflow .pipeline .NextFlowPipelineJob ;
40+ import org .labkey .nextflow .pipeline .NextFlowProtocol ;
4141import org .springframework .validation .BindException ;
4242import org .springframework .validation .Errors ;
4343import org .springframework .web .servlet .ModelAndView ;
@@ -64,8 +64,6 @@ public class NextFlowController extends SpringActionController
6464 private static final DefaultActionResolver _actionResolver = new DefaultActionResolver (NextFlowController .class );
6565 public static final String NAME = "nextflow" ;
6666
67- private static final Logger LOG = LogHelper .getLogger (NextFlowController .class , NAME );
68-
6967 public NextFlowController ()
7068 {
7169 setActionResolver (_actionResolver );
@@ -262,24 +260,39 @@ public void validateCommand(AnalyzeForm o, Errors errors)
262260 @ Override
263261 public ModelAndView getView (AnalyzeForm o , boolean b , BindException errors )
264262 {
263+ List <File > selectedFiles = o .getValidatedFiles (getContainer (), false );
264+ if (selectedFiles .isEmpty ())
265+ {
266+ return new HtmlView (HtmlString .of ("Couldn't find input file(s)" ));
267+ }
268+ // NextFlow operates on the full directory so show the list to the user, regardless of what they selected
269+ // from the file listing
270+ File inputDir = selectedFiles .get (0 ).getParentFile ();
271+
272+ File [] inputFiles = inputDir .listFiles (new PipelineProvider .FileTypesEntryFilter (NextFlowProtocol .INPUT_TYPES ));
273+ if (inputFiles == null || inputFiles .length == 0 )
274+ {
275+ return new HtmlView (HtmlString .of ("Couldn't find input file(s)" ));
276+ }
277+
265278 NextFlowConfiguration config = NextFlowManager .get ().getConfiguration ();
266279 if (config .getNextFlowConfigFilePath () != null )
267280 {
268281 File configDir = new File (config .getNextFlowConfigFilePath ());
269282 if (configDir .isDirectory ())
270283 {
271- File [] files = configDir .listFiles ();
272- if (files != null && files .length > 0 )
284+ File [] configFiles = configDir .listFiles ();
285+ if (configFiles != null && configFiles .length > 0 )
273286 {
274- List <File > configFiles = Arrays .asList (files );
275287 return new HtmlView ("NextFlow Runner" , DIV (
276288 FORM (at (method , "POST" ),
277289 INPUT (at (hidden , true , name , "launch" , value , true )),
278290 Arrays .stream (o .getFile ()).map (f -> INPUT (at (hidden , true , name , "file" , value , f ))).toList (),
279291 "Files: " ,
280- UL (Arrays .stream (o . getFile () ).map (DOM ::LI )),
292+ UL (Arrays .stream (inputFiles ). map ( File :: getName ).map (DOM ::LI )),
281293 "Config: " ,
282- new Select .SelectBuilder ().name ("configFile" ).addOptions (configFiles .stream ().filter (f -> f .isFile () && f .getName ().toLowerCase ().endsWith (".config" )).map (File ::getName ).sorted (String .CASE_INSENSITIVE_ORDER ).toList ()).build (),
294+ new Select .SelectBuilder ().name ("configFile" ).addOptions (Arrays .stream (configFiles ).filter (f -> f .isFile () && f .getName ().toLowerCase ().endsWith (".config" )).map (File ::getName ).sorted (String .CASE_INSENSITIVE_ORDER ).toList ()).build (),
295+ DOM .BR (),
283296 new Button .ButtonBuilder ("Start NextFlow" ).submit (true ).build ())));
284297 }
285298 }
0 commit comments