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
30 changes: 24 additions & 6 deletions flow/src/org/labkey/flow/FlowSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,34 @@
import org.labkey.api.data.PropertyManager;
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
import org.labkey.api.util.FileUtil;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

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

public class FlowSettings
{
static private File _tempAnalysisDirectory;
static private FileLike _tempAnalysisDirectory;
static private final String PROPCAT_FLOW = "flow";
static private final String PROPNAME_WORKINGDIRECTORY = "workingDirectory";
static private final String PROPNAME_DELETE_FILES = "deleteFiles";

static private File getTempAnalysisDirectory()
static private FileLike getTempAnalysisDirectory()
{
if (_tempAnalysisDirectory != null)
return _tempAnalysisDirectory;
File file;
try
{
file = FileUtil.createTempFile("FlowAnalysis", "tmp");
File ret = new File(file.getParentFile(), "FlowAnalysis");
FileLike ret = FileUtil.createTempDirectoryFileLike("FlowAnalysis");
FileLike file = ret.resolveChild("FlowAnalysis.tmp");
if (!ret.exists())
{
FileUtil.mkdir(ret);
}

// Clean-up any existing prior analysis file
file.delete();
_tempAnalysisDirectory = ret;
return ret;
Expand All @@ -57,12 +60,21 @@ static private File getTempAnalysisDirectory()
}
}

/**
* Get the flow analysis working directory.
* Note: This may be outside the FileLike/FileSystemLike paradigm, it is either a temp directory or a value set by the admins
*
* @return File object representing the Flow analysis working directory.
*/
static public File getWorkingDirectory()
{
//Get admin provided setting if it exists
String path = getWorkingDirectoryPath();
if (path != null)
return new File(path);
return getTempAnalysisDirectory();

// Otherwise default to the
return FileSystemLike.toFile(getTempAnalysisDirectory());
}

static public String getWorkingDirectoryPath()
Expand All @@ -72,6 +84,12 @@ static public String getWorkingDirectoryPath()
return map.get(PROPNAME_WORKINGDIRECTORY);
}

/**
* Save the Flow Analysis working directory path setting
* Note: This may be outside the FileLike/FileSystemLike paradigm
*
* @param path string file path to the flow analysis working directory
*/
static public void setWorkingDirectoryPath(String path)
{
Container container = ContainerManager.getRoot();
Expand Down
18 changes: 14 additions & 4 deletions flow/src/org/labkey/flow/controllers/FlowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.DataRegion;
import org.labkey.api.module.Module;
import org.labkey.api.pipeline.PipeRoot;
import org.labkey.api.pipeline.PipelineService;
import org.labkey.api.portal.ProjectUrls;
import org.labkey.api.query.QueryDefinition;
import org.labkey.api.query.QueryParseException;
Expand All @@ -41,6 +43,7 @@
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.settings.AdminConsole;
import org.labkey.api.settings.AdminConsole.SettingsLinkType;
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.JobRunner;
import org.labkey.api.util.TestContext;
import org.labkey.api.view.ActionURL;
Expand All @@ -64,11 +67,12 @@
import org.labkey.flow.query.FlowSchema;
import org.labkey.flow.webparts.FlowFolderType;
import org.labkey.flow.webparts.OverviewWebPart;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.net.URI;

@Marshal(Marshaller.Jackson)
Expand Down Expand Up @@ -298,6 +302,9 @@ public class FlowAdminAction extends FormViewAction<FlowAdminForm>
@Override
public void validateCommand(FlowAdminForm form, Errors errors)
{
PipeRoot root = PipelineService.get().findPipelineRoot(getContainer());
if (root == null)
errors.rejectValue("root", ERROR_MSG, "Pipeline root not found for the current container.");
}

@Override
Expand All @@ -310,10 +317,13 @@ public ModelAndView getView(FlowAdminForm form, boolean reshow, BindException er
@Override
public boolean handlePost(FlowAdminForm form, BindException errors)
{
if (form.getWorkingDirectory() != null)
PipeRoot root = PipelineService.get().findPipelineRoot(getContainer());

if (form.getWorkingDirectory() != null && root.getRootFileLike().isDescendant(FileUtil.createUri(form.getWorkingDirectory())))
{
File dir = new File(form.getWorkingDirectory());
if (!dir.exists())
FileLike dir = root.resolvePathToFileLike(form.getWorkingDirectory());

if (dir == null || !dir.exists())
{
errors.rejectValue("workingDirectory", ERROR_MSG, "Path does not exist: " + form.getWorkingDirectory());
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.labkey.flow.script.WorkspaceJob;
import org.labkey.flow.util.SampleUtil;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -910,7 +911,6 @@ private RunType hasExistingRuns(File workspaceFile)
return rt;
}


private void stepSelectAnalysis(ImportAnalysisForm form, BindException errors)
{
WorkspaceData workspaceData = form.getWorkspace();
Expand All @@ -922,18 +922,14 @@ private void stepSelectAnalysis(ImportAnalysisForm form, BindException errors)
return;
}

PipeRoot root = null;
PipeRoot root = getPipeRoot();
String path = workspaceData.getPath();
File workspaceFile = null;
if (path != null)
{
root = getPipeRoot();
workspaceFile = root.resolvePath(path);
}
FileLike workspaceFL = path != null ? root.resolvePathToFileLike(path) : null;

RunType rt = RunType.None;
if (workspaceFile != null && form.getSelectFCSFilesOption() == null && form.getKeywordDir() == null)
if (workspaceFL != null && form.getSelectFCSFilesOption() == null && form.getKeywordDir() == null)
{
File workspaceFile = FileSystemLike.toFile(workspaceFL);
rt = hasExistingRuns(workspaceFile);
if (rt != RunType.None)
{
Expand All @@ -945,9 +941,10 @@ private void stepSelectAnalysis(ImportAnalysisForm form, BindException errors)
{
// Next, guess the FCS files are in the same directory as the workspace, but not analyzed yet.
File keywordDir = null;
File sampleDir = workspaceFile.getParentFile();
for (ISampleInfo sampleInfo : samples)
{
File sampleFile = FileUtil.appendName(new File(workspaceFile.getParent()),sampleInfo.getLabel());
File sampleFile = FileUtil.appendName(sampleDir, sampleInfo.getLabel());
if (sampleFile.exists())
{
keywordDir = workspaceFile.getParentFile();
Expand Down
49 changes: 25 additions & 24 deletions flow/src/org/labkey/flow/data/FlowCompensationMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.QueryRowReference;
import org.labkey.api.security.User;
import org.labkey.api.util.FileUtil;
import org.labkey.api.view.ActionURL;
import org.labkey.flow.FlowSettings;
import org.labkey.flow.analysis.model.CompensationMatrix;
Expand All @@ -38,9 +39,7 @@
import org.labkey.flow.query.FlowTableType;

import jakarta.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,7 +88,7 @@ static public FlowCompensationMatrix create(User user, Container container, Stri
{
data = svc.createData(container, FlowDataType.CompensationMatrix, name);
}
data.setDataFileURI(new File(FlowSettings.getWorkingDirectory(), "compensation." + FlowDataHandler.EXT_DATA).toURI());
data.setDataFileURI(FileUtil.appendName(FlowSettings.getWorkingDirectory(), "compensation." + FlowDataHandler.EXT_DATA).toURI());
data.save(user);
AttributeSetHelper.doSave(attrs, user, data, log);
flowComp = (FlowCompensationMatrix) FlowDataObject.fromData(data);
Expand All @@ -105,8 +104,8 @@ public CompensationMatrix getCompensationMatrix()

static public CompensationMatrix getCompensationMatrix(String name, AttributeSet attrs)
{
TreeSet<String> channelNames = new TreeSet();
Map<String, Double> values = new HashMap();
TreeSet<String> channelNames = new TreeSet<>();
Map<String, Double> values = new HashMap<>();
for (Map.Entry<StatisticSpec, Double> entry : attrs.getStatistics().entrySet())
{
StatisticSpec spec = entry.getKey();
Expand All @@ -119,20 +118,20 @@ static public CompensationMatrix getCompensationMatrix(String name, AttributeSet
channelNames.add(strChannel);
values.put(spec.getParameter(), entry.getValue());
}
if (channelNames.size() == 0)
if (channelNames.isEmpty())
return null;
CompensationMatrix ret = new CompensationMatrix(name);
String[] arrChannelNames = channelNames.toArray(new String[channelNames.size()]);
String[] arrChannelNames = channelNames.toArray(new String[0]);

for (int iChannel = 0; iChannel < arrChannelNames.length; iChannel ++)
for (String arrChannelName : arrChannelNames)
{
Map<String, Double> channelValues = new TreeMap();
for (int iChannelValue = 0; iChannelValue < arrChannelNames.length; iChannelValue ++)
Map<String, Double> channelValues = new TreeMap<>();
for (String channelName : arrChannelNames)
{
String key = arrChannelNames[iChannel] + ":" + arrChannelNames[iChannelValue];
channelValues.put(arrChannelNames[iChannelValue], values.get(key));
String key = arrChannelName + ":" + channelName;
channelValues.put(channelName, values.get(key));
}
ret.setChannel(arrChannelNames[iChannel], channelValues);
ret.setChannel(arrChannelName, channelValues);
}
return ret;
}
Expand Down Expand Up @@ -195,15 +194,17 @@ static public List<FlowCompensationMatrix> getCompensationMatrices(Container con
{
return (List) FlowDataObject.fromDataType(container, FlowDataType.CompensationMatrix);
}
static public List<FlowCompensationMatrix> getUploadedCompensationMatrices(Container container)
{
List<FlowCompensationMatrix> all = getCompensationMatrices(container);
List<FlowCompensationMatrix> ret = new ArrayList();
for (FlowCompensationMatrix comp : all)
{
if (comp.getRun() == null)
ret.add(comp);
}
return ret;
}

//TODO remove?
// static public List<FlowCompensationMatrix> getUploadedCompensationMatrices(Container container)
// {
// List<FlowCompensationMatrix> all = getCompensationMatrices(container);
// List<FlowCompensationMatrix> ret = new ArrayList<>();
// for (FlowCompensationMatrix comp : all)
// {
// if (comp.getRun() == null)
// ret.add(comp);
// }
// return ret;
// }
}