1818
1919import jakarta .servlet .http .HttpServletResponse ;
2020import org .apache .commons .io .IOUtils ;
21- import org .apache .logging .log4j .LogManager ;
2221import org .apache .logging .log4j .Logger ;
2322import org .jetbrains .annotations .NotNull ;
2423import org .jetbrains .annotations .Nullable ;
8685import org .labkey .api .security .permissions .ReadPermission ;
8786import org .labkey .api .security .permissions .UpdatePermission ;
8887import org .labkey .api .util .DateUtil ;
88+ import org .labkey .api .util .FileUtil ;
8989import org .labkey .api .util .MinorConfigurationException ;
9090import org .labkey .api .util .PageFlowUtil ;
9191import org .labkey .api .util .Pair ;
9292import org .labkey .api .util .URLHelper ;
93+ import org .labkey .api .util .logging .LogHelper ;
9394import org .labkey .api .view .ActionURL ;
9495import org .labkey .api .view .DataView ;
9596import org .labkey .api .view .DetailsView ;
110111import org .labkey .genotyping .sequences .FastqGenerator ;
111112import org .labkey .genotyping .sequences .FastqWriter ;
112113import org .labkey .genotyping .sequences .SequenceManager ;
114+ import org .labkey .vfs .FileLike ;
115+ import org .labkey .vfs .FileSystemLike ;
113116import org .springframework .validation .BindException ;
114117import org .springframework .validation .Errors ;
115118import org .springframework .web .servlet .ModelAndView ;
122125import java .math .BigInteger ;
123126import java .net .MalformedURLException ;
124127import java .net .URL ;
128+ import java .nio .file .Path ;
129+ import java .nio .file .Paths ;
125130import java .sql .ResultSet ;
126131import java .sql .SQLException ;
127132import java .util .Collection ;
139144
140145public class GenotypingController extends SpringActionController
141146{
142- private static final Logger LOG = LogManager .getLogger (GenotypingController .class );
147+ private static final Logger LOG = LogHelper .getLogger (GenotypingController .class , "Logger for Genotyping Controller" );
143148 @ SuppressWarnings ({"unchecked" })
144149 private static final DefaultActionResolver _actionResolver = new DefaultActionResolver (GenotypingController .class );
145150
@@ -1005,9 +1010,13 @@ private String importReads(ImportReadsForm form) throws Exception
10051010 if (null == form .getPlatform ())
10061011 return "You must specify a sequence platform" ;
10071012
1013+ PipeRoot root = PipelineService .get ().getPipelineRootSetting (getContainer ());
1014+ if (!root .getRootFileLike ().isDescendant (FileUtil .createUri (form .getReadsPath ())))
1015+ return "File must be a descendant of a pipeline" ;
1016+
10081017 try
10091018 {
1010- File readsFile = new File ( form .getReadsPath ());
1019+ FileLike readsFile = root . resolvePathToFileLike ( root . relativePath ( Paths . get ( form .getReadsPath ()) ));
10111020 GenotypingRun run ;
10121021
10131022 try
@@ -1023,7 +1032,6 @@ private String importReads(ImportReadsForm form) throws Exception
10231032 }
10241033
10251034 ViewBackgroundInfo vbi = new ViewBackgroundInfo (getContainer (), getUser (), getViewContext ().getActionURL ());
1026- PipeRoot root = PipelineService .get ().findPipelineRoot (getContainer ());
10271035 ImportReadsForm .Platforms platform = ImportReadsForm .Platforms .valueOf (form .getPlatform ());
10281036
10291037 platform .prepareAndQueueRunJob (vbi , root , new File (form .getReadsPath ()), run , form .getPrefix ());
@@ -1178,10 +1186,17 @@ private ColumnInfo getColumnInfo(Map<FieldKey, ColumnInfo> fieldMap, String colu
11781186 public boolean handlePost (AnalyzeForm form , BindException errors ) throws Exception
11791187 {
11801188 GenotypingRun run = GenotypingManager .get ().getRun (getContainer (), form .getRun ());
1181- File readsPath = new File (run .getPath (), run .getFileName ());
1182- ViewBackgroundInfo vbi = new ViewBackgroundInfo (getContainer (), getUser (), getViewContext ().getActionURL ());
1189+ if (run == null )
1190+ {
1191+ errors .rejectValue ("run" , ERROR_MSG , "No run found" );
1192+ return false ;
1193+ }
1194+
11831195 PipeRoot root = PipelineService .get ().findPipelineRoot (getContainer ());
11841196
1197+ FileLike readsFile = run .getWorkingDir ().resolveChild (run .getFileName ());
1198+ ViewBackgroundInfo vbi = new ViewBackgroundInfo (getContainer (), getUser (), getViewContext ().getActionURL ());
1199+
11851200 String sequencesViewName = form .getSequencesView ();
11861201 String description = form .getDescription ();
11871202 String sequencesView = DEFAULT_VIEW_PLACEHOLDER .equals (sequencesViewName ) ? null : sequencesViewName ;
@@ -1202,7 +1217,7 @@ public boolean handlePost(AnalyzeForm form, BindException errors) throws Excepti
12021217 GenotypingAnalysis analysis = GenotypingManager .get ().createAnalysis (getContainer (), getUser (), run , description , sequencesView );
12031218 try
12041219 {
1205- PipelineJob analysisJob = new SubmitAnalysisJob (vbi , root , readsPath , analysis , sampleKeys );
1220+ PipelineJob analysisJob = new SubmitAnalysisJob (vbi , root , readsFile , analysis , sampleKeys );
12061221 PipelineService .get ().queueJob (analysisJob );
12071222 }
12081223 catch (MinorConfigurationException e )
@@ -1292,10 +1307,10 @@ public Object execute(ImportAnalysisForm form, BindException errors) throws Exce
12921307
12931308 try
12941309 {
1310+ FileLike analysisDir = FileSystemLike .getVerifiedFileLike (getContainer (), form .getPath ());
12951311 int analysisId = form .getAnalysis ();
1296- File analysisDir = new File (form .getPath ());
1297- User user = getUser ();
12981312
1313+ User user = getUser ();
12991314 if (user .isGuest ())
13001315 {
13011316 Properties props = GenotypingManager .get ().readProperties (analysisDir );
@@ -1378,16 +1393,26 @@ public void validateCommand(PipelinePathForm target, Errors errors)
13781393 @ Override
13791394 public boolean handlePost (PipelinePathForm form , BindException errors ) throws IOException , PipelineValidationException
13801395 {
1396+ Container container = getContainer ();
13811397 // Manual upload of genotyping analysis; pipeline provider posts to this action with matches file.
1382- File matches = form .getValidatedSingleFile (getContainer ());
1383- File analysisDir = matches .getParentFile ();
1398+ Path singleFile = form .getValidatedSinglePath (container );
1399+
1400+ if (form .getPipeRoot (container ).getRootFileLike ().isDescendant (singleFile .toUri ()))
1401+ {
13841402
1385- // Load properties to determine the run.
1386- Properties props = GenotypingManager .get ().readProperties (analysisDir );
1387- int analysisId = Integer .parseInt ((String )props .get ("analysis" ));
1388- importAnalysis (analysisId , analysisDir , getUser ());
1403+ FileLike matches = form .getPipeRoot (container ).resolvePathToFileLike (singleFile .toString ());
1404+ FileLike analysisDir = matches .getParent ();
13891405
1390- return true ;
1406+ // Load properties to determine the run.
1407+ Properties props = GenotypingManager .get ().readProperties (analysisDir );
1408+ int analysisId = Integer .parseInt ((String ) props .get ("analysis" ));
1409+ importAnalysis (analysisId , analysisDir , getUser ());
1410+
1411+ return true ;
1412+ }
1413+
1414+ errors .reject (ERROR_MSG , "File was not found under the pipeline root" );
1415+ return false ;
13911416 }
13921417
13931418 @ Override
@@ -1398,13 +1423,13 @@ public URLHelper getSuccessURL(PipelinePathForm pipelinePathForm)
13981423 }
13991424
14001425
1401- private void importAnalysis (int analysisId , File pipelineDir , User user ) throws IOException , PipelineValidationException
1426+ private void importAnalysis (int analysisId , FileLike pipelineDir , User user ) throws IOException , PipelineValidationException
14021427 {
14031428 GenotypingAnalysis analysis = GenotypingManager .get ().getAnalysis (getContainer (), analysisId );
1404- File analysisDir = new File ( analysis .getPath ());
1429+ FileLike analysisDir = new FileSystemLike . Builder ( Paths . get ( analysis .getPath ())). readwrite (). root ( );
14051430
1406- String pipelinePath = pipelineDir .getCanonicalPath ();
1407- String analysisPath = analysisDir .getCanonicalPath ();
1431+ String pipelinePath = FileUtil . getAbsoluteCaseSensitiveFile ( pipelineDir .toNioPathForRead (). toFile ()). getAbsolutePath ();
1432+ String analysisPath = FileUtil . getAbsoluteCaseSensitiveFile ( analysisDir .toNioPathForRead (). toFile ()). getAbsolutePath ();
14081433
14091434 if (!pipelinePath .equals (analysisPath ))
14101435 throw new FileNotFoundException ("Analysis path (\" " + analysisPath +
0 commit comments