Skip to content
Open
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
17 changes: 8 additions & 9 deletions api/src/org/labkey/api/admin/FolderImportContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import org.labkey.api.util.XmlValidationException;
import org.labkey.api.writer.VirtualFile;
import org.labkey.folder.xml.FolderDocument;
import org.labkey.vfs.FileLike;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -47,7 +46,7 @@
*/
public class FolderImportContext extends AbstractFolderContext
{
private Path _folderXml;
private FileLike _folderXml;

private String _xarJobId;

Expand All @@ -66,7 +65,7 @@ public FolderImportContext()
super(null, null, null, null, null, null);
}

public FolderImportContext(User user, Container c, Path folderXml, Set<String> dataTypes, LoggerGetter logger, VirtualFile root)
public FolderImportContext(User user, Container c, FileLike folderXml, Set<String> dataTypes, LoggerGetter logger, VirtualFile root)
{
super(user, c, null, dataTypes, logger, root);
_folderXml = folderXml;
Expand Down Expand Up @@ -112,17 +111,17 @@ public synchronized FolderDocument getDocument() throws ImportException
return folderDoc;
}

private FolderDocument readFolderDocument(Path folderXml) throws ImportException, IOException
private FolderDocument readFolderDocument(FileLike folderXml) throws ImportException, IOException
{
if (!Files.exists(folderXml))
throw new ImportException(folderXml.getFileName() + " file does not exist.");
if (!folderXml.exists())
throw new ImportException(folderXml.getName() + " file does not exist.");

FolderDocument folderDoc;

try (InputStream inputStream = Files.newInputStream(folderXml))
try (InputStream inputStream = folderXml.openInputStream())
{
folderDoc = FolderDocument.Factory.parse(inputStream, XmlBeansUtil.getDefaultParseOptions());
XmlBeansUtil.validateXmlDocument(folderDoc, folderXml.getFileName().toString());
XmlBeansUtil.validateXmlDocument(folderDoc, folderXml.getName());
}
catch (XmlException | XmlValidationException e)
{
Expand Down
7 changes: 4 additions & 3 deletions api/src/org/labkey/api/admin/ImportOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.labkey.api.data.Activity;
import org.labkey.api.security.User;
import org.labkey.api.security.UserManager;
import org.labkey.vfs.FileLike;

import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -42,7 +43,7 @@ public class ImportOptions
private final Collection<String> _messages = new LinkedList<>();
private Set<String> _dataTypes;
private Activity _activity;
private Path _analysisDir;
private FileLike _analysisDir;
private String _folderArchiveSourceName = null;

private boolean _isNewFolderImport; // if we know the target folder is empty, can skip certain merge logic
Expand Down Expand Up @@ -153,12 +154,12 @@ public void setActivity(Activity activity)
_activity = activity;
}

public Path getAnalysisDir()
public FileLike getAnalysisDir()
{
return _analysisDir;
}

public void setAnalysisDir(Path analysisDir)
public void setAnalysisDir(FileLike analysisDir)
{
_analysisDir = analysisDir;
}
Expand Down
17 changes: 4 additions & 13 deletions api/src/org/labkey/api/admin/InvalidFileException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
import org.apache.xmlbeans.XmlException;
import org.labkey.api.util.XmlValidationException;
import org.labkey.api.writer.VirtualFile;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.nio.file.Path;

public class InvalidFileException extends ImportException
{
@Deprecated // prefer the Path version
public InvalidFileException(File root, File file, Throwable t)
public InvalidFileException(FileLike root, FileLike file, Throwable t)
{
this(root.toPath(), file.toPath(), t);
this(root.toNioPathForRead(), file.toNioPathForRead(), t);
}

@Deprecated // prefer the FileLike version
public InvalidFileException(Path root, Path file, Throwable t)
{
super(getErrorString(root, file, t.getMessage()));
Expand All @@ -42,21 +43,11 @@ public InvalidFileException(VirtualFile root, File file, Throwable t)
super(getErrorString(root.getRelativePath(file.getName()), t.getMessage()));
}

public InvalidFileException(File root, File file, XmlException e)
{
super(getErrorString(root, file, e));
}

public InvalidFileException(VirtualFile root, File file, XmlException e)
{
super(getErrorString(root, file, e));
}

public InvalidFileException(File root, File file, XmlValidationException e)
{
super(getErrorString(root, file, (String)null), e);
}

public InvalidFileException(VirtualFile root, File file, XmlValidationException e)
{
super(getErrorString(root.getRelativePath(file.getName()), null), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface CloudArchiveImporterSupport
default void downloadCloudArchive(@NotNull PipelineJob job, @NotNull Path studyXml, BindException errors) throws UnsupportedOperationException
{
//check if cloud based pipeline root, and study xml hasn't been downloaded already
if (!studyXml.startsWith(job.getPipeRoot().getImportDirectory().toPath().toAbsolutePath()))
if (!studyXml.startsWith(job.getPipeRoot().getImportDirectory().toNioPathForRead().toAbsolutePath()))
{
if (CloudStoreService.get() != null) //proxy of is Cloud Module enabled for the current job/container
{
Expand Down
7 changes: 7 additions & 0 deletions api/src/org/labkey/api/cloud/CloudStoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.labkey.api.services.ServiceRegistry;
import org.labkey.api.util.Pair;
import org.labkey.api.webdav.WebdavResource;
import org.labkey.vfs.FileLike;

import java.nio.file.Path;
import java.util.Collection;
Expand Down Expand Up @@ -141,6 +142,12 @@ default Collection<String> getEnabledCloudStores(Container container, boolean ex
@Nullable
Path getPath(Container container, String storeName, org.labkey.api.util.Path path);

/**
* Return nio.Path to cloud file/directory
*/
@Nullable
FileLike getFileLike(Container container, String storeName, org.labkey.api.util.Path path);

/**
* Return path relative to cloud store
*/
Expand Down
15 changes: 7 additions & 8 deletions api/src/org/labkey/api/data/TSVGridWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.ResultSetRowMapFactory;
import org.labkey.api.query.FieldKey;
import org.labkey.api.util.FileUtil;
import org.labkey.api.view.HttpView;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -198,7 +197,7 @@ private int writeBody(Results results)
* @return List of the output Files.
*/
@NotNull
public List<File> writeBatchFiles(@NotNull File outputDir, @NotNull String baseName, @Nullable String extension, int batchSize, @Nullable FieldKey batchColumn)
public List<FileLike> writeBatchFiles(@NotNull FileLike outputDir, @NotNull String baseName, @Nullable String extension, int batchSize, @Nullable FieldKey batchColumn)
{
extension = StringUtils.trimToEmpty(extension);
String ext = "".equals(extension) || extension.startsWith(".") ? extension : "." + extension;
Expand All @@ -211,13 +210,13 @@ public List<File> writeBatchFiles(@NotNull File outputDir, @NotNull String baseN
}

@NotNull
private List<File> writeResultSetBatches(Results results, File outputDir, String baseName, String extension, int batchSize, @Nullable FieldKey batchColumn) throws IOException
private List<FileLike> writeResultSetBatches(Results results, FileLike outputDir, String baseName, String extension, int batchSize, @Nullable FieldKey batchColumn) throws IOException
{
int currentBatchSize = 0;
int totalBatches = 1;
Object previousBatchColumnValue = null;
Object newBatchColumnValue;
List<File> outputFiles = new ArrayList<>();
List<FileLike> outputFiles = new ArrayList<>();
outputFiles.add(startBatchFile(outputDir, baseName, extension, batchSize, totalBatches));
RenderContext ctx = getRenderContext();
ctx.setResults(results);
Expand Down Expand Up @@ -264,11 +263,11 @@ private List<File> writeResultSetBatches(Results results, File outputDir, String
}

@NotNull
private File startBatchFile(File outputDir, String baseName, String extension, int batchSize, int totalBatches) throws IOException
private FileLike startBatchFile(FileLike outputDir, String baseName, String extension, int batchSize, int totalBatches) throws IOException
{
String batchId = batchSize == 0 ? "" : "-" + totalBatches;
File file = FileUtil.appendName(outputDir, baseName + batchId + extension);
prepare(file);
FileLike file = outputDir.resolveChild(baseName + batchId + extension);
prepare(file.openOutputStream());
writeFileHeader();
if (isHeaderRowVisible())
writeColumnHeaders();
Expand Down
23 changes: 11 additions & 12 deletions api/src/org/labkey/api/exp/AbstractFileXarSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.NetworkDrive;
import org.labkey.api.util.XmlBeansUtil;
import org.labkey.vfs.FileLike;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -42,9 +43,9 @@
*/
public abstract class AbstractFileXarSource extends XarSource
{
protected Path _xmlFile;
protected FileLike _xmlFile;

protected Path getXmlFile()
protected FileLike getXmlFile()
{
return _xmlFile;
}
Expand Down Expand Up @@ -77,7 +78,7 @@ public ExperimentArchiveDocument getDocument() throws XmlException, IOException
try
{
NetworkDrive.exists(getXmlFile());
fIn = Files.newInputStream(getXmlFile());
fIn = getXmlFile().openInputStream();
return ExperimentArchiveDocument.Factory.parse(fIn, XmlBeansUtil.getDefaultParseOptions());
}
finally
Expand All @@ -88,9 +89,7 @@ public ExperimentArchiveDocument getDocument() throws XmlException, IOException
{
fIn.close();
}
catch (IOException e)
{
}
catch (IOException ignored) {}
}
}
}
Expand All @@ -99,7 +98,7 @@ public ExperimentArchiveDocument getDocument() throws XmlException, IOException
@Nullable
public Path getRootPath()
{
return null != getXmlFile()? getXmlFile().getParent(): null;
return null != getXmlFile()? getXmlFile().toNioPathForRead().getParent(): null;
}

@Override
Expand Down Expand Up @@ -137,15 +136,15 @@ public String canonicalizeDataFileURL(String dataFileURL)
}
}

public static Path getLogFileFor(Path f) throws IOException
public static FileLike getLogFileFor(FileLike f) throws IOException
{
Path xarDirectory = f.getParent();
if (!Files.exists(xarDirectory))
FileLike xarDirectory = f.getParent();
if (!xarDirectory.exists())
{
throw new IOException("Xar file parent directory does not exist");
}

String xarShortName = f.getFileName().toString();
String xarShortName = f.getName();
int index = xarShortName.toLowerCase().lastIndexOf(".xml");
if (index == -1)
{
Expand All @@ -157,6 +156,6 @@ public static Path getLogFileFor(Path f) throws IOException
xarShortName = xarShortName.substring(0, index);
}

return xarDirectory.resolve(xarShortName + LOG_FILE_NAME_SUFFIX);
return xarDirectory.resolveChild(xarShortName + LOG_FILE_NAME_SUFFIX);
}
}
11 changes: 6 additions & 5 deletions api/src/org/labkey/api/exp/FileXarSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.pipeline.PipelineJob;
import org.labkey.vfs.FileLike;

import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -30,25 +31,25 @@
*/
public class FileXarSource extends AbstractFileXarSource
{
public FileXarSource(Path file, PipelineJob job)
public FileXarSource(FileLike file, PipelineJob job)
{
super(job);
_xmlFile = file.normalize();
_xmlFile = file;
}

public FileXarSource(Path file, PipelineJob job, Container targetContainer, @Nullable Map<String, String> substitutions)
public FileXarSource(FileLike file, PipelineJob job, Container targetContainer, @Nullable Map<String, String> substitutions)
{
super(job.getDescription(), targetContainer, job.getUser(), job, substitutions);
_xmlFile = file;
}

public FileXarSource(Path file, PipelineJob job, Container targetContainer)
public FileXarSource(FileLike file, PipelineJob job, Container targetContainer)
{
this(file, job, targetContainer, null);
}

@Override
public Path getLogFilePath() throws IOException
public FileLike getLogFilePath() throws IOException
{
return getLogFileFor(_xmlFile);
}
Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/exp/XarContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.labkey.api.settings.AppProps;
import org.labkey.api.util.GUID;
import org.labkey.api.util.NetworkDrive;
import org.labkey.api.util.Path;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.net.URI;
Expand Down
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/exp/XarSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.labkey.api.pipeline.PipelineJob;
import org.labkey.api.security.User;
import org.labkey.api.util.FileUtil;
import org.labkey.vfs.FileLike;

import java.io.IOException;
import java.io.Serializable;
Expand Down Expand Up @@ -122,7 +123,7 @@ public final String getCanonicalDataFileURL(String dataFileURL) throws XarFormat

protected abstract String canonicalizeDataFileURL(String dataFileURL) throws XarFormatException;

public abstract Path getLogFilePath() throws IOException;
public abstract FileLike getLogFilePath() throws IOException;

/**
* Called before trying to import this XAR to let the source set up any resources that are required
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/exp/api/ExperimentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ List<? extends ExpProtocol> getExpProtocolsWithParameterValue(
*
* @return the job responsible for doing the work
*/
PipelineJob importXarAsync(ViewBackgroundInfo info, File file, String description, PipeRoot root) throws IOException;
PipelineJob importXarAsync(ViewBackgroundInfo info, FileLike file, String description, PipeRoot root) throws IOException;

/**
* Loads the xar synchronously, in the context of the pipelineJob
Expand Down
4 changes: 4 additions & 0 deletions api/src/org/labkey/api/files/FileContentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.labkey.api.services.ServiceRegistry;
import org.labkey.api.util.FileUtil;
import org.labkey.api.webdav.WebdavResource;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -340,6 +341,9 @@ enum PathType { full, serverRelative, folderRelative }
@Nullable
URI getWebDavUrl(@NotNull Path path, @NotNull Container container, @NotNull PathType type);

@Nullable
URI getWebDavUrl(@NotNull FileLike path, @NotNull Container container, @NotNull PathType type);

/**
* Ensure an entry in the exp.data table exists for all files in the container's file root.
*/
Expand Down
Loading