Skip to content
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

FileSystemLike #219

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@
import org.labkey.api.view.template.ClientDependency;
import org.labkey.laboratory.assay.AssayHelper;
import org.labkey.laboratory.query.WorkbookModel;
import org.labkey.vfs.FileLike;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
@@ -620,8 +621,8 @@ protected File getTargetFile(String filename) throws IOException

try
{
File targetDirectory = AssayFileWriter.ensureUploadDirectory(getContainer());
return AssayFileWriter.findUniqueFileName(filename, targetDirectory);
FileLike targetDirectory = AssayFileWriter.ensureUploadDirectory(getContainer());
return AssayFileWriter.findUniqueFileName(filename, targetDirectory).toNioPathForWrite().toFile();
}
catch (ExperimentException e)
{
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@
import org.labkey.laboratory.assay.AssayHelper;
import org.labkey.laboratory.query.DefaultAssayCustomizer;
import org.labkey.laboratory.query.LaboratoryTableCustomizer;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
@@ -197,10 +198,10 @@ public Pair<ExpExperiment, ExpRun> saveAssayBatch(List<Map<String, Object>> resu

try
{
File targetDirectory = AssayFileWriter.ensureUploadDirectory(ctx.getContainer());
File file = AssayFileWriter.findUniqueFileName(basename, targetDirectory);
FileLike targetDirectory = AssayFileWriter.ensureUploadDirectory(ctx.getContainer());
FileLike file = AssayFileWriter.findUniqueFileName(basename, targetDirectory);

return this.saveAssayBatch(results, json, file, ctx, provider, protocol);
return this.saveAssayBatch(results, json, file.toNioPathForRead().toFile(), ctx, provider, protocol);
}
catch (ExperimentException e)
{
15 changes: 8 additions & 7 deletions laboratory/src/org/labkey/laboratory/assay/AssayHelper.java
Original file line number Diff line number Diff line change
@@ -58,6 +58,8 @@
import org.labkey.api.view.ViewContext;
import org.labkey.laboratory.LaboratoryController;
import org.labkey.laboratory.LaboratorySchema;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

import java.beans.Introspector;
import java.io.File;
@@ -88,9 +90,8 @@ public static AssayHelper get()
return _instance;
}

public Map<String, File> saveResultsFile(List<Map<String, Object>> results, JSONObject json, File file, AssayProvider provider, ExpProtocol protocol) throws ExperimentException, ValidationException
public Map<String, FileLike> saveResultsFile(List<Map<String, Object>> results, JSONObject json, File file, AssayProvider provider, ExpProtocol protocol) throws ExperimentException, ValidationException
{
Map<String, File> files = new HashMap<String, File>();
//TODO: consider adding as input??
//files.put("RawInput", file);

@@ -111,8 +112,8 @@ public Map<String, File> saveResultsFile(List<Map<String, Object>> results, JSON
throw new ExperimentException(e.getMessage());
}

files.put(AssayDataCollector.PRIMARY_FILE, newFile);

Map<String, FileLike> files = new HashMap<String, FileLike>();
files.put(AssayDataCollector.PRIMARY_FILE, FileSystemLike.wrapFile(newFile));
return files;
}

@@ -209,7 +210,7 @@ public Pair<ExpExperiment, ExpRun> saveAssayBatch(List<Map<String, Object>> resu
});
}

Map<String, File> uploadedFiles = saveResultsFile(results, json, file, provider, protocol);
Map<String, FileLike> uploadedFiles = saveResultsFile(results, json, file, provider, protocol);

//TODO: see AssayRunAsyncContext
AssayRunUploadContext uploadContext = new RunUploadContext<>(protocol, provider, name, comments, runProperties, batchProperties, ctx, uploadedFiles);
@@ -243,10 +244,10 @@ private File getUniqueOutputName(File input, String extension)
File parent = input.getParentFile();
String basename = FileUtil.getBaseName(input);
int suffix = 1;
File newFile = new File(parent, basename + "." + extension);
File newFile = FileUtil.appendName(parent, basename + "." + extension);
while (newFile.exists())
{
newFile = new File(parent, basename + "-" + suffix + "." + extension);
newFile = FileUtil.appendName(parent, basename + "-" + suffix + "." + extension);
suffix++;
}
return newFile;
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@
import org.labkey.api.security.User;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.ViewContext;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -53,9 +53,9 @@ public class RunUploadContext<ProviderType extends AssayProvider> implements Ass
private final ViewContext _ctx;

private TransformResult _transformResult;
private final Map<String, File> _uploadedData;
private final Map<String, FileLike> _uploadedData;

public RunUploadContext(ExpProtocol protocol, ProviderType providerType, String name, String comments, Map<String, String> runProperties, Map<String, String> batchProperties, ViewContext ctx, Map<String, File> uploadedData)
public RunUploadContext(ExpProtocol protocol, ProviderType providerType, String name, String comments, Map<String, String> runProperties, Map<String, String> batchProperties, ViewContext ctx, Map<String, FileLike> uploadedData)
{
_protocol = protocol;
_providerType = providerType;
@@ -154,7 +154,7 @@ public ActionURL getActionURL()

@Override
@NotNull
public Map<String, File> getUploadedData() throws ExperimentException
public Map<String, FileLike> getUploadedData() throws ExperimentException
{
return _uploadedData;
}