|
8 | 8 | import org.labkey.api.assay.AssayRunUploadContext; |
9 | 9 | import org.labkey.api.assay.AssayService; |
10 | 10 | import org.labkey.api.assay.DefaultAssayRunCreator; |
| 11 | +import org.labkey.api.assay.transform.DataTransformService; |
11 | 12 | import org.labkey.api.collections.CaseInsensitiveHashMap; |
12 | 13 | import org.labkey.api.data.Container; |
| 14 | +import org.labkey.api.data.ContainerManager; |
13 | 15 | import org.labkey.api.dataiterator.MapDataIterator; |
14 | 16 | import org.labkey.api.exp.ExperimentException; |
15 | 17 | import org.labkey.api.exp.api.ExpData; |
|
36 | 38 | import org.labkey.vfs.FileLike; |
37 | 39 | import org.labkey.vfs.FileSystemLike; |
38 | 40 |
|
| 41 | +import java.io.File; |
39 | 42 | import java.io.IOException; |
40 | 43 | import java.io.InputStream; |
41 | 44 | import java.net.URI; |
@@ -128,24 +131,41 @@ public RecordedActionSet run() |
128 | 131 | // If the value is just a filename (no directory separators), resolve it relative to |
129 | 132 | // the metadata file's directory; otherwise treat it as a full server-side path |
130 | 133 | String dataFileName = FileUtil.getFileName(Path.of(dataFilePath)); |
131 | | - FileLike sourceFile; |
| 134 | + FileLike sourceFile = null; |
132 | 135 | if (dataFilePath.equals(dataFileName)) |
133 | 136 | { |
134 | | - sourceFile = dataFile.getParent().resolveChild(dataFilePath); |
| 137 | + String sourcePath = support.getParameters().get(DataTransformService.ORIGINAL_SOURCE_PATH); |
| 138 | + if (StringUtils.isNotBlank(sourcePath)) |
| 139 | + { |
| 140 | + FileLike originalSource = FileSystemLike.wrapFile(new File(sourcePath)); |
| 141 | + sourceFile = originalSource.getParent().resolveChild(dataFilePath); |
| 142 | + } |
135 | 143 | } |
136 | 144 | else |
137 | 145 | { |
138 | | - Path resolvedPath = Path.of(dataFilePath).toAbsolutePath().normalize(); |
139 | | - if (!isUnderAnyPipelineRoot(resolvedPath)) |
| 146 | + // check to see if it's a webdav url |
| 147 | + WebdavResource resource = WebdavService.get().lookup(dataFilePath); |
| 148 | + if (resource != null) |
| 149 | + { |
| 150 | + sourceFile = FileSystemLike.wrapFile(resource.getFile()); |
| 151 | + } |
| 152 | + |
| 153 | + // check to see if it's a server-side path |
| 154 | + if (sourceFile == null) |
140 | 155 | { |
141 | | - log.error("DataFile '{}' is not under a server-managed pipeline root", dataFilePath); |
142 | | - row.remove(INPUT_DATA_FILE); |
143 | | - continue; |
| 156 | + Path resolvedPath = Path.of(dataFilePath).toAbsolutePath().normalize(); |
| 157 | + |
| 158 | + if (!isUnderAnyPipelineRoot(resolvedPath)) |
| 159 | + { |
| 160 | + log.error("DataFile '{}' is not under a server-managed pipeline root", dataFilePath); |
| 161 | + row.remove(INPUT_DATA_FILE); |
| 162 | + continue; |
| 163 | + } |
| 164 | + sourceFile = FileSystemLike.wrapFile(resolvedPath.toFile()); |
144 | 165 | } |
145 | | - sourceFile = FileSystemLike.wrapFile(resolvedPath.toFile()); |
146 | 166 | } |
147 | 167 |
|
148 | | - if (!sourceFile.exists()) |
| 168 | + if (sourceFile != null && !sourceFile.exists()) |
149 | 169 | { |
150 | 170 | log.info("Data file not found: {}", sourceFile.getPath()); |
151 | 171 | row.remove(INPUT_DATA_FILE); |
@@ -283,10 +303,35 @@ private FileLike getTargetFolder(Container container, Logger log) throws IOExcep |
283 | 303 | return null; |
284 | 304 | } |
285 | 305 |
|
| 306 | + /** |
| 307 | + * Determine whether the given path falls under a pipeline root for some container, using the same semantics as |
| 308 | + * {@link PipelineService#findPipelineRoot(Container)} (which includes the default file-root fallback, not just |
| 309 | + * explicitly configured pipeline roots). First try to resolve the path directly to its owning container(s); if |
| 310 | + * that comes up empty (e.g. a container with a custom, non-default file root that the path-resolution logic does |
| 311 | + * not yet handle), fall back to scanning every container's pipeline root. |
| 312 | + */ |
286 | 313 | private boolean isUnderAnyPipelineRoot(Path resolvedPath) |
287 | 314 | { |
288 | | - return PipelineService.get().getAllPipelineRoots().values().stream() |
289 | | - .anyMatch(pipeRoot -> pipeRoot.isUnderRoot(resolvedPath)); |
| 315 | + for (Container c : FileContentService.get().getContainersForFilePath(resolvedPath)) |
| 316 | + { |
| 317 | + if (isUnderPipelineRoot(c, resolvedPath)) |
| 318 | + return true; |
| 319 | + } |
| 320 | + |
| 321 | + // Path could not be resolved to a container directly; fall back to scanning all containers |
| 322 | + for (Container c : ContainerManager.getAllChildren(ContainerManager.getRoot())) |
| 323 | + { |
| 324 | + if (isUnderPipelineRoot(c, resolvedPath)) |
| 325 | + return true; |
| 326 | + } |
| 327 | + |
| 328 | + return false; |
| 329 | + } |
| 330 | + |
| 331 | + private boolean isUnderPipelineRoot(Container container, Path resolvedPath) |
| 332 | + { |
| 333 | + PipeRoot root = PipelineService.get().findPipelineRoot(container); |
| 334 | + return root != null && root.isUnderRoot(resolvedPath); |
290 | 335 | } |
291 | 336 |
|
292 | 337 | public static class Factory extends AbstractTaskFactory<AbstractTaskFactorySettings, Factory> |
|
0 commit comments