Skip to content

Commit 79a318e

Browse files
committed
Claude code review
1 parent 8c359bb commit 79a318e

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

signalData/src/org/labkey/signaldata/pipeline/SignalDataImportTask.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import org.labkey.vfs.FileLike;
3737
import org.labkey.vfs.FileSystemLike;
3838

39-
import java.io.File;
4039
import java.io.IOException;
4140
import java.io.InputStream;
4241
import java.net.URI;
4342
import java.net.URLDecoder;
43+
import java.nio.charset.StandardCharsets;
4444
import java.nio.file.Path;
4545
import java.time.LocalDateTime;
4646
import java.time.format.DateTimeFormatter;
@@ -95,7 +95,11 @@ public RecordedActionSet run()
9595
}
9696

9797
// guaranteed to only have a single file
98-
assert support.getInputFiles().size() == 1;
98+
if (support.getInputFiles().size() != 1)
99+
{
100+
log.error("Expecting a single input file but received {}", support.getInputFiles().size());
101+
return new RecordedActionSet();
102+
}
99103
FileLike dataFile = support.getInputFiles().getFirst();
100104

101105
try
@@ -131,7 +135,14 @@ public RecordedActionSet run()
131135
}
132136
else
133137
{
134-
sourceFile = FileSystemLike.wrapFile(new File(dataFilePath));
138+
Path resolvedPath = Path.of(dataFilePath).toAbsolutePath().normalize();
139+
if (!isUnderAnyPipelineRoot(resolvedPath))
140+
{
141+
log.error("DataFile '{}' is not under a server-managed pipeline root", dataFilePath);
142+
row.remove(INPUT_DATA_FILE);
143+
continue;
144+
}
145+
sourceFile = FileSystemLike.wrapFile(resolvedPath.toFile());
135146
}
136147

137148
if (!sourceFile.exists())
@@ -169,22 +180,19 @@ public RecordedActionSet run()
169180
FileLike d = FileUtil.getAbsoluteCaseSensitiveFile(destFile);
170181
String url = d.toURI().toURL().toString();
171182

172-
if (url != null)
173-
{
174-
dataInput.put(ExpDataTable.Column.Name.name(), data.getName());
175-
dataInput.put(ExpDataTable.Column.DataFileUrl.name(), data.getDataFileUrl());
183+
dataInput.put(ExpDataTable.Column.Name.name(), data.getName());
184+
dataInput.put(ExpDataTable.Column.DataFileUrl.name(), data.getDataFileUrl());
176185

177-
// file data type for this run data field
178-
String dataFileUrl = URLDecoder.decode(url, "UTF-8");
179-
row.replace(INPUT_DATA_FILE, dataFileUrl.replace("file:", ""));
180-
}
186+
// file data type for this run data field, adjust the URL to be compatible
187+
String dataFileUrl = URLDecoder.decode(url, StandardCharsets.UTF_8);
188+
row.replace(INPUT_DATA_FILE, dataFileUrl.replace("file:", ""));
181189
}
182190
}
183191
}
184192

185193
// create and save the run
186194
AssayProvider provider = AssayService.get().getProvider(protocol);
187-
if (provider != null)
195+
if (provider != null && !dataRows.isEmpty())
188196
{
189197
AssayRunUploadContext.Factory<?,?> runFactory = provider.createRunUploadFactory(protocol, job.getUser(), container);
190198

@@ -275,6 +283,12 @@ private FileLike getTargetFolder(Container container, Logger log) throws IOExcep
275283
return null;
276284
}
277285

286+
private boolean isUnderAnyPipelineRoot(Path resolvedPath)
287+
{
288+
return PipelineService.get().getAllPipelineRoots().values().stream()
289+
.anyMatch(pipeRoot -> pipeRoot.isUnderRoot(resolvedPath));
290+
}
291+
278292
public static class Factory extends AbstractTaskFactory<AbstractTaskFactorySettings, Factory>
279293
{
280294
public Factory()

0 commit comments

Comments
 (0)