forked from BimberLab/DiscvrLabKeyModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Convert ValidateReadsetFilesAction and ImportReferenceSequencesAction to use FileLike #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd196e3
Update ValidateReadsetFilesAction and ImportReferenceSequencesAction …
labkey-bpatel 21e947e
Update 'DownloadTempImageAction' to use FileLike.
labkey-bpatel 0bbf7ea
Use getPath() in the error message.
labkey-bpatel f06440b
Use resolveFile()
labkey-bpatel e219ea4
Remove DownloadTempImageAction and ConvertTextToFileAction and its as…
labkey-bpatel ce11f9a
Adjust error, use resolveFile()
labkey-bpatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,7 @@ | |
| import org.labkey.sequenceanalysis.util.FastqUtils; | ||
| import org.labkey.sequenceanalysis.util.SequenceUtil; | ||
| import org.labkey.vfs.FileLike; | ||
| import org.labkey.vfs.FileSystemLike; | ||
| import org.springframework.beans.PropertyValues; | ||
| import org.springframework.validation.BindException; | ||
| import org.springframework.validation.Errors; | ||
|
|
@@ -434,8 +435,21 @@ public static class DownloadTempImageAction extends ExportAction<TempImageAction | |
| @Override | ||
| public void export(TempImageAction form, HttpServletResponse response, BindException errors) throws Exception | ||
| { | ||
| File parentDir = form.getDirectory() == null ? FileUtil.getTempDirectory() : new File(FileUtil.getTempDirectory(), form.getDirectory()); | ||
| File targetFile = new File(parentDir, form.getFileName()); | ||
| File targetFile; | ||
| FileLike tempDirRoot = new FileSystemLike.Builder(FileUtil.getTempDirectory()).root(); | ||
| if (!(tempDirRoot.getFileSystem().isDescendant(tempDirRoot, new File(form.getDirectory()).toURI()))) | ||
| { | ||
| throw new FileNotFoundException("Directory '" + form.getDirectory() + "' is not the descendant of '" + tempDirRoot.getPath() + "'"); | ||
| } | ||
| FileLike parentDirFileLike = form.getDirectory() == null ? tempDirRoot : tempDirRoot.resolveFile(new Path(form.getDirectory())); | ||
| File parentDir = FileSystemLike.toFile(parentDirFileLike); | ||
|
|
||
| if (!(parentDirFileLike.getFileSystem().isDescendant(parentDirFileLike, new File(form.getFileName()).toURI()))) | ||
| { | ||
| throw new FileNotFoundException("File '" + form.getFileName() + "' is not the descendant of '" + parentDirFileLike.getPath() + "'"); | ||
| } | ||
|
|
||
| targetFile = FileSystemLike.toFile(parentDirFileLike.resolveChild(form.getFileName())); | ||
| targetFile = FileUtil.getAbsoluteCaseSensitiveFile(targetFile); | ||
|
|
||
| if (!NetworkDrive.exists(targetFile)) | ||
|
|
@@ -1119,14 +1133,21 @@ public ApiResponse execute(ValidateReadsetImportForm form, BindException errors) | |
| if (form.getFileNames() != null) | ||
| { | ||
| //TODO: consider proper container?? | ||
| File root = PipelineService.get().findPipelineRoot(getContainer()).getRootPath(); | ||
| File base = root; | ||
| PipeRoot root = PipelineService.get().findPipelineRoot(getContainer()); | ||
|
|
||
| if (null == root) | ||
| { | ||
| throw new PipelineJobException("Unable to find pipeline root for container: " + getContainer().getPath()); | ||
| } | ||
|
|
||
| FileLike base = root.getRootFileLike(); | ||
|
|
||
| if (form.getPath() != null) | ||
| base = new File(base, form.getPath()); | ||
| base = base.resolveChild(form.getPath()); | ||
|
|
||
| for (String fileName : form.getFileNames()) | ||
| { | ||
| File f = new File(base, fileName); | ||
| File f = FileSystemLike.toFile(base.resolveChild(fileName)); | ||
| ExpData data = ExperimentService.get().getExpDataByURL(f, getContainer()); | ||
| if (data != null) | ||
| { | ||
|
|
@@ -1137,7 +1158,7 @@ public ApiResponse execute(ValidateReadsetImportForm form, BindException errors) | |
| Map<String, Object> map = new HashMap<>(); | ||
| map.put("fileName", fileName); | ||
| map.put("filePath", f.getPath()); | ||
| map.put("relPath", FileUtil.relativePath(FileUtil.getAbsoluteCaseSensitiveFile(root).getPath(), FileUtil.getAbsoluteCaseSensitiveFile(f).getPath())); | ||
| map.put("relPath", FileUtil.relativePath(FileUtil.getAbsoluteCaseSensitiveFile(FileSystemLike.toFile(root.getRootFileLike())).getPath(), FileUtil.getAbsoluteCaseSensitiveFile(f).getPath())); | ||
| map.put("container", getContainer().getId()); | ||
| map.put("containerPath", getContainer().getPath()); | ||
| String basename = SequenceTaskHelper.getUnzippedBaseName(fileName); | ||
|
|
@@ -2320,7 +2341,12 @@ public Object execute(ImportFastaSequencesForm form, BindException errors) throw | |
| //resolve files | ||
| List<File> files = new ArrayList<>(); | ||
| PipeRoot root = PipelineService.get().getPipelineRootSetting(getContainer()); | ||
| File baseDir = StringUtils.trimToNull(form.getPath()) == null ? root.getRootPath() : new File(root.getRootPath(), form.getPath()); | ||
| FileLike baseDir = null != root ? root.getRootFileLike() : null; | ||
| if (baseDir == null) | ||
| { | ||
| errors.reject(ERROR_MSG, "Pipeline root not configured"); | ||
| return null; | ||
| } | ||
| if (!baseDir.exists()) | ||
| { | ||
| errors.reject(ERROR_MSG, "Unable to find directory: " + baseDir.getPath()); | ||
|
|
@@ -2335,7 +2361,7 @@ public Object execute(ImportFastaSequencesForm form, BindException errors) throw | |
|
|
||
| for (String fn : form.getFileNames()) | ||
| { | ||
| File f = new File(baseDir, fn); | ||
| File f = FileSystemLike.toFile(baseDir.resolveChild(fn)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to convert back to File here. FileLike.exists() should work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind I see that this gets passed to the job. That's a future story. |
||
| if (f.exists()) | ||
| { | ||
| files.add(f); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbimber - Can you please provide a usage scenario for this action. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you asking for a way to test it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I believe both DownloadTempImageAction and ConvertTextToFileAction are really old code that I dont see used anywhere. Rather than refactor them, those classes and the associated form classes could be removed. Let me know if you want to do this or have me do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well was wondering how that action gets called and how the values for directory and filename gets set.
But sounds good, if they are not being used, then I can remove them as part of this PR.