Skip to content

Commit

Permalink
Merge pull request #219 from LabKey/fb_filesystemlike
Browse files Browse the repository at this point in the history
FileSystemLike
  • Loading branch information
labkey-matthewb authored Oct 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents d19bff6 + cb0d18f commit 18c629c
Showing 4 changed files with 23 additions and 17 deletions.
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)
{
16 changes: 9 additions & 7 deletions laboratory/src/org/labkey/laboratory/assay/AssayHelper.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.labkey.api.assay.AssayService;
import org.labkey.api.cache.CacheManager;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.CollectionUtils;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.RuntimeSQLException;
@@ -58,6 +59,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 +91,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 +113,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 = CollectionUtils.enforceValueClass(new HashMap<>(),FileLike.class);
files.put(AssayDataCollector.PRIMARY_FILE, FileSystemLike.wrapFile(newFile));
return files;
}

@@ -209,7 +211,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 +245,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;
12 changes: 7 additions & 5 deletions laboratory/src/org/labkey/laboratory/assay/RunUploadContext.java
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.labkey.api.assay.AssayRunUploadContext;
import org.labkey.api.assay.AssayService;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.CollectionUtils;
import org.labkey.api.data.Container;
import org.labkey.api.exp.ExperimentException;
import org.labkey.api.exp.api.ExpProtocol;
@@ -32,8 +33,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 +54,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;
@@ -64,7 +65,8 @@ public RunUploadContext(ExpProtocol protocol, ProviderType providerType, String
_runProperties = new CaseInsensitiveHashMap<>(runProperties);
_batchProperties = new CaseInsensitiveHashMap<>(batchProperties);
_ctx = ctx;
_uploadedData = uploadedData;
_uploadedData = CollectionUtils.checkValueClass(uploadedData, FileLike.class);
CollectionUtils.checkValueClass(_uploadedData, FileLike.class);
}

@Override
@@ -154,7 +156,7 @@ public ActionURL getActionURL()

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

0 comments on commit 18c629c

Please sign in to comment.