Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions experiment/src/org/labkey/experiment/DataURLRelativizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.labkey.api.security.User;
import org.labkey.api.util.FileUtil;
import org.labkey.api.view.ActionURL;
import org.labkey.experiment.api.ExperimentServiceImpl;
import org.labkey.experiment.controllers.exp.ExperimentController;

import java.io.IOException;
Expand Down Expand Up @@ -75,21 +76,16 @@ public URLRewriter createURLRewriter()
@Override
public String rewriteURL(Path path, ExpData data, String roleName, ExpRun expRun, User user, String rootFilePath) throws ExperimentException
{
try
{
if (path == null)
return null;
if (path == null)
return null;

if (expRun == null || expRun.getFilePathRoot() == null)
{
return FileUtil.pathToString(path);
}
return FileUtil.relativizeUnix(expRun.getFilePathRootPath(), path, false);
}
catch (IOException e)
if (expRun == null || expRun.getFilePathRoot() == null)
{
throw new ExperimentException(e);
return FileUtil.pathToString(path);
}

// NOTE: this will only write a relative path if the file is a direct descendant of the root.
return ExperimentServiceImpl.get().generatePathStringRelativeToRootIfUnderRoot(path, expRun.getFilePathRootPath());
}
};
}
Expand Down
4 changes: 3 additions & 1 deletion experiment/src/org/labkey/experiment/ExperimentModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
import org.labkey.experiment.lineage.ExpLineageServiceImpl;
import org.labkey.experiment.lineage.LineagePerfTest;
import org.labkey.experiment.pipeline.ExperimentPipelineProvider;
import org.labkey.experiment.pipeline.XarTestPipelineJob;
import org.labkey.experiment.samples.DataClassFolderImporter;
import org.labkey.experiment.samples.DataClassFolderWriter;
import org.labkey.experiment.samples.SampleStatusFolderImporter;
Expand Down Expand Up @@ -1079,7 +1080,8 @@ public Collection<String> getSummary(Container c)
SampleTypeServiceImpl.TestCase.class,
StorageNameGenerator.TestCase.class,
StorageProvisionerImpl.TestCase.class,
UniqueValueCounterTestCase.class
UniqueValueCounterTestCase.class,
XarTestPipelineJob.TestCase.class
);
}

Expand Down
51 changes: 26 additions & 25 deletions experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -768,33 +768,10 @@ public ExpDataImpl createData(URI uri, XarSource source) throws XarFormatExcepti
String[] parts = pathStr.split("/");
String name = FileUtil.decodeSpaces(parts[parts.length - 1]);
Path path = FileUtil.getPath(source.getXarContext().getContainer(), uri);

if (path != null)
{
try
{
path = FileUtil.stringToPath(source.getXarContext().getContainer(),
source.getCanonicalDataFileURL(FileUtil.pathToString(path)));

// Only convert to a relative path if this is a descendant of the root:
path = path.normalize();
if (URIUtil.isDescendant(source.getRootPath().toUri(), path.toUri()))
{
pathStr = FileUtil.relativizeUnix(source.getRootPath(), path, false);
}
else
{
pathStr = FileUtil.pathToString(path);
}
}
catch (IOException e)
{
pathStr = FileUtil.pathToString(path);
}
}
else
{
pathStr = FileUtil.uriToString(uri);
path = FileUtil.stringToPath(source.getXarContext().getContainer(), source.getCanonicalDataFileURL(FileUtil.pathToString(path)));
pathStr = generatePathStringRelativeToRootIfUnderRoot(path, source.getRootPath());
}

Lsid.LsidBuilder lsid = new Lsid.LsidBuilder(LsidUtils.resolveLsidFromTemplate(AutoFileLSIDReplacer.AUTO_FILE_LSID_SUBSTITUTION, source.getXarContext(), "Data", new AutoFileLSIDReplacer(pathStr, source.getXarContext().getContainer(), source)));
Expand All @@ -816,6 +793,30 @@ public ExpDataImpl createData(URI uri, XarSource source) throws XarFormatExcepti
return data;
}

public String generatePathStringRelativeToRootIfUnderRoot(@NotNull Path path, @Nullable Path pipeRootPath)
{
String pathStr;
try
{
// Only convert to a relative path if this is a descendant of the root:
path = path.normalize();
if (pipeRootPath != null && URIUtil.isDescendant(pipeRootPath.toUri(), path.toUri()))
{
pathStr = FileUtil.relativizeUnix(pipeRootPath, path, false);
}
else
{
pathStr = FileUtil.pathToString(path);
}
}
catch (IOException e)
{
pathStr = FileUtil.pathToString(path);
}

return pathStr;
}

@Override
public ExpDataImpl createData(Container container, @NotNull DataType type)
{
Expand Down
Loading