171171import org .labkey .sequenceanalysis .util .FastqUtils ;
172172import org .labkey .sequenceanalysis .util .SequenceUtil ;
173173import org .labkey .vfs .FileLike ;
174+ import org .labkey .vfs .FileSystemLike ;
174175import org .springframework .beans .PropertyValues ;
175176import org .springframework .validation .BindException ;
176177import org .springframework .validation .Errors ;
@@ -427,80 +428,6 @@ public void addNavTrail(NavTree tree)
427428 }
428429 }
429430
430- @ RequiresPermission (ReadPermission .class )
431- @ IgnoresTermsOfUse
432- public static class DownloadTempImageAction extends ExportAction <TempImageAction >
433- {
434- @ Override
435- public void export (TempImageAction form , HttpServletResponse response , BindException errors ) throws Exception
436- {
437- File parentDir = form .getDirectory () == null ? FileUtil .getTempDirectory () : new File (FileUtil .getTempDirectory (), form .getDirectory ());
438- File targetFile = new File (parentDir , form .getFileName ());
439- targetFile = FileUtil .getAbsoluteCaseSensitiveFile (targetFile );
440-
441- if (!NetworkDrive .exists (targetFile ))
442- {
443- throw new FileNotFoundException ("Could not find file: " + targetFile .getPath ());
444- }
445-
446- if (parentDir .listFiles () == null )
447- {
448- throw new FileNotFoundException ("Unable to list the contents of folder: " + parentDir .getPath ());
449- }
450-
451- PageFlowUtil .streamFile (response , targetFile , false );
452-
453- //the file will be recreated, so delete upon running
454- FileUtils .deleteQuietly (targetFile );
455-
456- //if the folder if empty, remove it too. other simultaneous requests might have deleted this folder before we get to it
457- if (parentDir != null && parentDir .exists ())
458- {
459- File [] children = parentDir .listFiles ();
460- if (children != null && children .length == 0 && !parentDir .equals (FileUtil .getTempDirectory ()))
461- {
462- FileUtils .deleteQuietly (parentDir ); //the Images folder
463- File parent = parentDir .getParentFile ();
464- FileUtils .deleteQuietly (parent ); //the file's folder
465-
466- if (parent != null && parent .getParentFile () != null )
467- {
468- File [] children2 = parent .getParentFile ().listFiles ();
469- if (children2 != null && children2 .length == 0 )
470- FileUtils .deleteQuietly (parent .getParentFile ()); //the file's folder
471- }
472- }
473- }
474- }
475- }
476-
477- @ RequiresPermission (ReadPermission .class )
478- @ IgnoresTermsOfUse
479- public static class ConvertTextToFileAction extends ExportAction <ConvertTextToFileForm >
480- {
481- @ Override
482- public void export (ConvertTextToFileForm form , HttpServletResponse response , BindException errors ) throws Exception
483- {
484- String text = form .getText ();
485-
486- if (text == null )
487- {
488- errors .reject (ERROR_MSG , "Need to provide text" );
489- return ;
490- }
491- if (form .getFileName () == null )
492- {
493- errors .reject (ERROR_MSG , "Need to provide a filename" );
494- return ;
495- }
496-
497- Map <String , String > headers = new HashMap <>();
498-
499- PageFlowUtil .prepareResponseForFile (response , headers , form .getFileName (), true );
500- response .getOutputStream ().print (text );
501- }
502- }
503-
504431 @ RequiresPermission (ReadPermission .class )
505432 public static class FindOrphanFilesAction extends ConfirmAction <Object >
506433 {
@@ -1119,14 +1046,21 @@ public ApiResponse execute(ValidateReadsetImportForm form, BindException errors)
11191046 if (form .getFileNames () != null )
11201047 {
11211048 //TODO: consider proper container??
1122- File root = PipelineService .get ().findPipelineRoot (getContainer ()).getRootPath ();
1123- File base = root ;
1049+ PipeRoot root = PipelineService .get ().findPipelineRoot (getContainer ());
1050+
1051+ if (null == root )
1052+ {
1053+ throw new PipelineJobException ("Unable to find pipeline root for container: " + getContainer ().getPath ());
1054+ }
1055+
1056+ FileLike base = root .getRootFileLike ();
1057+
11241058 if (form .getPath () != null )
1125- base = new File ( base , form .getPath ());
1059+ base = base . resolveFile ( new Path ( form .getPath () ));
11261060
11271061 for (String fileName : form .getFileNames ())
11281062 {
1129- File f = new File (base , fileName );
1063+ File f = FileSystemLike . toFile (base . resolveChild ( fileName ) );
11301064 ExpData data = ExperimentService .get ().getExpDataByURL (f , getContainer ());
11311065 if (data != null )
11321066 {
@@ -1137,7 +1071,7 @@ public ApiResponse execute(ValidateReadsetImportForm form, BindException errors)
11371071 Map <String , Object > map = new HashMap <>();
11381072 map .put ("fileName" , fileName );
11391073 map .put ("filePath" , f .getPath ());
1140- map .put ("relPath" , FileUtil .relativePath (FileUtil .getAbsoluteCaseSensitiveFile (root ).getPath (), FileUtil .getAbsoluteCaseSensitiveFile (f ).getPath ()));
1074+ map .put ("relPath" , FileUtil .relativePath (FileUtil .getAbsoluteCaseSensitiveFile (FileSystemLike . toFile ( root . getRootFileLike ()) ).getPath (), FileUtil .getAbsoluteCaseSensitiveFile (f ).getPath ()));
11411075 map .put ("container" , getContainer ().getId ());
11421076 map .put ("containerPath" , getContainer ().getPath ());
11431077 String basename = SequenceTaskHelper .getUnzippedBaseName (fileName );
@@ -1649,58 +1583,6 @@ public void setZipFileName(String zipFileName)
16491583 }
16501584 }
16511585
1652- public static class ConvertTextToFileForm
1653- {
1654- private String _text ;
1655- private String _fileName ;
1656-
1657- public String getText ()
1658- {
1659- return _text ;
1660- }
1661-
1662- public void setText (String text )
1663- {
1664- _text = text ;
1665- }
1666-
1667- public String getFileName ()
1668- {
1669- return _fileName ;
1670- }
1671-
1672- public void setFileName (String fileName )
1673- {
1674- _fileName = fileName ;
1675- }
1676- }
1677-
1678- public static class TempImageAction
1679- {
1680- String _fileName ;
1681- String _directory ;
1682-
1683- public String getFileName ()
1684- {
1685- return _fileName ;
1686- }
1687-
1688- public void setFileName (String fileName )
1689- {
1690- _fileName = fileName ;
1691- }
1692-
1693- public String getDirectory ()
1694- {
1695- return _directory ;
1696- }
1697-
1698- public void setDirectory (String directory )
1699- {
1700- _directory = directory ;
1701- }
1702- }
1703-
17041586 public static class FastqcForm
17051587 {
17061588 private String [] _filenames ;
@@ -2320,7 +2202,15 @@ public Object execute(ImportFastaSequencesForm form, BindException errors) throw
23202202 //resolve files
23212203 List <File > files = new ArrayList <>();
23222204 PipeRoot root = PipelineService .get ().getPipelineRootSetting (getContainer ());
2323- File baseDir = StringUtils .trimToNull (form .getPath ()) == null ? root .getRootPath () : new File (root .getRootPath (), form .getPath ());
2205+
2206+ if (root == null )
2207+ {
2208+ errors .reject (ERROR_MSG , "Pipeline root not configured" );
2209+ return null ;
2210+ }
2211+
2212+ FileLike baseDir = StringUtils .trimToNull (form .getPath ()) == null ? root .getRootFileLike () : root .getRootFileLike ().resolveFile (new Path (form .getPath ()));
2213+
23242214 if (!baseDir .exists ())
23252215 {
23262216 errors .reject (ERROR_MSG , "Unable to find directory: " + baseDir .getPath ());
@@ -2335,7 +2225,7 @@ public Object execute(ImportFastaSequencesForm form, BindException errors) throw
23352225
23362226 for (String fn : form .getFileNames ())
23372227 {
2338- File f = new File (baseDir , fn );
2228+ File f = FileSystemLike . toFile (baseDir . resolveChild ( fn ) );
23392229 if (f .exists ())
23402230 {
23412231 files .add (f );
0 commit comments