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
23 changes: 12 additions & 11 deletions api/src/org/labkey/api/action/AbstractFileUploadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.labkey.api.util.URLHelper;
import org.labkey.api.view.NavTree;
import org.labkey.api.writer.PrintWriters;
import org.labkey.vfs.FileLike;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.validation.BindException;
Expand All @@ -34,8 +35,6 @@
import org.springframework.web.servlet.ModelAndView;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -196,7 +195,7 @@ private void export(FORM form, HttpServletResponse response) throws Exception
HttpServletRequest basicRequest = getViewContext().getRequest();

// Parameter name (String) -> File on disk/original file name Pair
Map<String, Pair<File, String>> savedFiles = new HashMap<>();
Map<String, Pair<FileLike, String>> savedFiles = new HashMap<>();

if (basicRequest instanceof MultipartHttpServletRequest request)
{
Expand All @@ -212,7 +211,7 @@ private void export(FORM form, HttpServletResponse response) throws Exception
{
if (!file.isEmpty())
{
File f = handleFile(filename, input, writer);
FileLike f = handleFile(filename, input, writer);
if (f == null)
{
return;
Expand All @@ -229,7 +228,7 @@ private void export(FORM form, HttpServletResponse response) throws Exception
String content = form.getFileContent()[i];
if (content != null)
{
File f = handleFile(filename, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), writer);
FileLike f = handleFile(filename, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), writer);
if (f != null)
{
savedFiles.put("FileContent" + (i == 0 ? "" : (i + 1)), new Pair<>(f, filename));
Expand All @@ -249,7 +248,7 @@ private void export(FORM form, HttpServletResponse response) throws Exception
}
}

protected File handleFile(String filename, InputStream input, Writer writer) throws IOException
protected FileLike handleFile(String filename, InputStream input, Writer writer) throws IOException
{
if (filename == null || input == null)
{
Expand All @@ -261,9 +260,9 @@ protected File handleFile(String filename, InputStream input, Writer writer) thr
String legalName = FileUtil.makeLegalName(filename);
try
{
File targetFile = getTargetFile(legalName);
FileLike targetFile = getTargetFile(legalName);

try (OutputStream output = new FileOutputStream(targetFile))
try (OutputStream output = targetFile.openOutputStream())
{
byte[] buffer = new byte[1024];
int len;
Expand Down Expand Up @@ -305,15 +304,17 @@ public int getStatusCode()
}
}

/** Figures out where to write the uploaded file */
protected abstract File getTargetFile(String filename) throws IOException;
/**
* Figures out where to write the uploaded file
*/
protected abstract FileLike getTargetFile(String filename) throws IOException;

/**
* Callback once the file has been written to the server's file system.
* @param files HTTP parameter name -> [File as saved on disk (potentially renamed to be unique, Original file name in POST]
* @return a meaningful handle that the client can use to refer to the file
*/
public abstract String getResponse(FORM form, Map<String, Pair<File, String>> files) throws UploadException;
public abstract String getResponse(FORM form, Map<String, Pair<FileLike, String>> files) throws IOException;

private void error(Writer writer, String message, int statusCode) throws IOException
{
Expand Down
14 changes: 5 additions & 9 deletions api/src/org/labkey/api/assay/AbstractAssayProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -125,7 +126,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -673,7 +673,7 @@ else if (inputDatas.size() > 1)
{
Map.Entry<String, FileLike> entry = iter.next();
// If it's not under the current pipeline root
if (pipeRoot == null || !pipeRoot.isUnderRoot(entry.getValue().toNioPathForRead()))
if (pipeRoot == null || !pipeRoot.isUnderRoot(entry.getValue()))
{
// Remove it from both collections
iter.remove();
Expand Down Expand Up @@ -798,11 +798,7 @@ public Set<Container> getAssociatedStudyContainers(ExpProtocol protocol, Collect
{
// Ignore Results domain TargetStudy for now.
// The participant resolver will find the TargetStudy on the row.
ExpObject source = switch (pair.first)
{
case Run -> run;
default -> cache.getBatch(run);
};
ExpObject source = pair.first == ExpProtocol.AssayDomainTypes.Run ? run : cache.getBatch(run);

if (source != null)
{
Expand Down Expand Up @@ -1267,7 +1263,7 @@ public Pair<ValidationException, Pair<String, String>> setValidationAndAnalysisS

for (AnalysisScript script : scripts)
{
File scriptFile = script.getScript().toNioPathForRead().toFile();
FileLike scriptFile = script.getScript();
String ext = FileUtil.getExtension(scriptFile);
if (scriptFile.isFile() && ext != null)
{
Expand All @@ -1280,7 +1276,7 @@ public Pair<ValidationException, Pair<String, String>> setValidationAndAnalysisS
String scriptText;
try
{
scriptText = Files.readString(scriptFile.toPath(), StringUtilsLabKey.DEFAULT_CHARSET);
scriptText = IOUtils.toString(scriptFile.openInputStream(), StringUtilsLabKey.DEFAULT_CHARSET);
}
catch (IOException e)
{
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/assay/AssayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.labkey.api.view.ViewContext;
import org.labkey.api.view.WebPartView;
import org.labkey.api.view.template.ClientDependency;
import org.labkey.vfs.FileLike;
import org.springframework.validation.BindException;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -144,7 +144,7 @@ static void setInstance(AssayService impl)
/**
* Creates a run, but does not persist it to the database. Creates the run only, no protocol applications, etc.
*/
ExpRun createExperimentRun(@Nullable String name, Container container, ExpProtocol protocol, @Nullable File file);
ExpRun createExperimentRun(@Nullable String name, Container container, ExpProtocol protocol, @Nullable FileLike file);

/**
* Returns the list of valid locations an assay design can be created in.
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/assay/DefaultAssayRunCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Pair<ExpExperiment, ExpRun> saveExperimentRun(
FileLike primaryFile = context.getUploadedData().get(AssayDataCollector.PRIMARY_FILE);
if (primaryFile != null)
auditEvent.addDetail(TransactionAuditProvider.TransactionDetail.ImportFileName, primaryFile.getName());
run = AssayService.get().createExperimentRun(context.getName(), context.getContainer(), protocol, null == primaryFile ? null : primaryFile.toNioPathForRead().toFile());
run = AssayService.get().createExperimentRun(context.getName(), context.getContainer(), protocol, primaryFile);
run.setComments(context.getComments());
run.setWorkflowTaskId(context.getWorkflowTaskId());

Expand Down Expand Up @@ -229,7 +229,7 @@ private ExpExperiment saveExperimentRunAsync(AssayRunUploadContext<ProviderType>
batch,
forceSaveBatchProps,
PipelineService.get().getPipelineRootSetting(context.getContainer()),
primaryFile.toNioPathForRead().toFile()
primaryFile
);

context.setPipelineJobGUID(pipelineJob.getJobGUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.URLHelper;
import org.labkey.api.view.ViewBackgroundInfo;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -51,7 +51,7 @@ public class AssayUploadPipelineJob<ProviderType extends AssayProvider> extends
private long _batchId;
private AssayRunAsyncContext<ProviderType> _context;

private File _primaryFile;
private FileLike _primaryFile;
private boolean _forceSaveBatchProps;
private ExpRun _run;

Expand All @@ -62,7 +62,7 @@ protected AssayUploadPipelineJob()
/**
* @param forceSaveBatchProps whether we need to save the batch properties, or if it's already been handled
*/
public AssayUploadPipelineJob(AssayRunAsyncContext<ProviderType> context, ViewBackgroundInfo info, @NotNull ExpExperiment batch, boolean forceSaveBatchProps, PipeRoot root, File primaryFile)
public AssayUploadPipelineJob(AssayRunAsyncContext<ProviderType> context, ViewBackgroundInfo info, @NotNull ExpExperiment batch, boolean forceSaveBatchProps, PipeRoot root, FileLike primaryFile)
{
super(context.getProvider().getName(), info, root);
String baseName = primaryFile.getName();
Expand Down Expand Up @@ -224,7 +224,7 @@ protected String getJobNotificationProvider()
return _context._jobNotificationProvider;
}

public File getPrimaryFile()
public FileLike getPrimaryFile()
{
return _primaryFile;
}
Expand Down
10 changes: 2 additions & 8 deletions api/src/org/labkey/api/assay/transform/DataTransformService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import org.labkey.api.util.Pair;
import org.labkey.api.util.UnexpectedException;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -158,13 +156,9 @@ public TransformResult transformAndValidate(
Object output = engine.eval(script);

FileLike rewrittenScriptFile;
if (bindings.get(ExternalScriptEngine.REWRITTEN_SCRIPT_FILE) instanceof File)
if (bindings.get(ExternalScriptEngine.REWRITTEN_SCRIPT_FILE) instanceof FileLike file)
{
var rewrittenScriptFileObject = bindings.get(ExternalScriptEngine.REWRITTEN_SCRIPT_FILE);
if (rewrittenScriptFileObject instanceof FileLike fo)
rewrittenScriptFile = fo;
else
rewrittenScriptFile = FileSystemLike.wrapFile((File)rewrittenScriptFileObject);
rewrittenScriptFile = file;
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/docker/DockerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.labkey.api.security.UserManager;
import org.labkey.api.services.ServiceRegistry;
import org.labkey.api.util.HeartBeat;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.io.FileFilter;
Expand Down Expand Up @@ -484,7 +485,7 @@ public DockerContainer(

boolean isUseDockerVolumes();

default void executeR(DockerImage dockerImage, File scriptFile, String localWorkingDir, String remoteWorkingDir, FileFilter inputScripts) throws IOException
default void executeR(DockerImage dockerImage, FileLike scriptFile, String localWorkingDir, String remoteWorkingDir, FileFilter inputScripts) throws IOException
{
throw new UnsupportedOperationException(NO_DOCKER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected ExpRun createRun(String name, Container container, ExpProtocol protoco
{
throw new NotFoundException("Pipeline root is not configured for folder " + container);
}
run.setFilePathRoot(pipeRoot.getRootPath());
run.setFilePathRoot(pipeRoot.getRootFileLike());

return run;
}
Expand Down
10 changes: 10 additions & 0 deletions api/src/org/labkey/api/exp/api/ExpRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.exp.Identifiable;
import org.labkey.api.security.User;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -52,7 +54,15 @@ public interface ExpRun extends ExpObject, Identifiable
List<? extends ExpData> getInputDatas(@Nullable String inputRole, @Nullable ExpProtocol.ApplicationType appType);
File getFilePathRoot();
void setFilePathRoot(File filePathRoot);
default void setFilePathRoot(FileLike f)
{
setFilePathRoot(FileSystemLike.toFile(f));
}
Path getFilePathRootPath();
default FileLike getFilePathFileLike()
{
return FileSystemLike.wrapFile(getFilePathRoot());
};
void setFilePathRootPath(Path filePathRoot);
void setProtocol(ExpProtocol protocol);
void setJobId(Long jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.module.Module;
import org.labkey.api.services.ServiceRegistry;
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.Path;
import org.labkey.api.view.ActionURL;

Expand Down Expand Up @@ -63,6 +64,6 @@ default File getFileForModuleResource(Module module, Path path)
File resources = getUpdatableResourcesRoot(module, null);
if (null == resources)
return null;
return new File(resources, path.toString("",""));
return FileUtil.appendPath(resources, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ private String getJobSuccessMsg(PipelineJob job, @NotNull ImportType importType,

return successMsg.toString();
}
else if (job instanceof AssayUploadPipelineJob)
else if (job instanceof AssayUploadPipelineJob<?> assayJob)
{
String successMsg = "Successfully imported assay run";

if (info != null)
{
String assayName = (String) info.get("assayName");

String filename = ((AssayUploadPipelineJob<?>) job).getPrimaryFile().getName();
String filename = assayJob.getPrimaryFile().getName();
if (!filename.endsWith(".tmp"))
{
successMsg += " from " + filename;
Expand All @@ -229,10 +229,10 @@ private String getJobErrorMsg(PipelineJob job, String rawErrorMsg)
"\n" +
rawErrorMsg;// resolveErrorMessage on client
}
else if (job instanceof AssayUploadPipelineJob)
else if (job instanceof AssayUploadPipelineJob<?> assayJob)
{
return "Failed to import assay run from " +
((AssayUploadPipelineJob<?>) job).getPrimaryFile().getName() +
assayJob.getPrimaryFile().getName() +
"\n" +
rawErrorMsg;
}
Expand Down
Loading