Skip to content

Commit 58ff7be

Browse files
committed
Adjust FlowSettings to at least partially use FileLike
Fix lint in FlowCompensationMatrix
1 parent e250c8b commit 58ff7be

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

flow/src/org/labkey/flow/FlowSettings.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,34 @@
2222
import org.labkey.api.data.PropertyManager;
2323
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
2424
import org.labkey.api.util.FileUtil;
25+
import org.labkey.vfs.FileLike;
26+
import org.labkey.vfs.FileSystemLike;
2527

2628
import java.io.File;
2729
import java.io.IOException;
2830
import java.util.Map;
2931

3032
public class FlowSettings
3133
{
32-
static private File _tempAnalysisDirectory;
34+
static private FileLike _tempAnalysisDirectory;
3335
static private final String PROPCAT_FLOW = "flow";
3436
static private final String PROPNAME_WORKINGDIRECTORY = "workingDirectory";
3537
static private final String PROPNAME_DELETE_FILES = "deleteFiles";
3638

37-
static private File getTempAnalysisDirectory()
39+
static private FileLike getTempAnalysisDirectory()
3840
{
3941
if (_tempAnalysisDirectory != null)
4042
return _tempAnalysisDirectory;
41-
File file;
4243
try
4344
{
44-
file = FileUtil.createTempFile("FlowAnalysis", "tmp");
45-
File ret = new File(file.getParentFile(), "FlowAnalysis");
45+
FileLike ret = FileUtil.createTempDirectoryFileLike("FlowAnalysis");
46+
FileLike file = ret.resolveChild("FlowAnalysis.tmp");
4647
if (!ret.exists())
4748
{
4849
FileUtil.mkdir(ret);
4950
}
51+
52+
// Clean-up any existing prior analysis file
5053
file.delete();
5154
_tempAnalysisDirectory = ret;
5255
return ret;
@@ -57,12 +60,21 @@ static private File getTempAnalysisDirectory()
5760
}
5861
}
5962

63+
/**
64+
* Get the flow analysis working directory.
65+
* Note: This may be outside the FileLike/FileSystemLike paradigm, it is either a temp directory or a value set by the admins
66+
*
67+
* @return File object representing the Flow analysis working directory.
68+
*/
6069
static public File getWorkingDirectory()
6170
{
71+
//Get admin provided setting if it exists
6272
String path = getWorkingDirectoryPath();
6373
if (path != null)
6474
return new File(path);
65-
return getTempAnalysisDirectory();
75+
76+
// Otherwise default to the
77+
return FileSystemLike.toFile(getTempAnalysisDirectory());
6678
}
6779

6880
static public String getWorkingDirectoryPath()
@@ -72,6 +84,12 @@ static public String getWorkingDirectoryPath()
7284
return map.get(PROPNAME_WORKINGDIRECTORY);
7385
}
7486

87+
/**
88+
* Save the Flow Analysis working directory path setting
89+
* Note: This may be outside the FileLike/FileSystemLike paradigm
90+
*
91+
* @param path string file path to the flow analysis working directory
92+
*/
7593
static public void setWorkingDirectoryPath(String path)
7694
{
7795
Container container = ContainerManager.getRoot();

flow/src/org/labkey/flow/controllers/FlowController.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.labkey.api.data.ContainerManager;
2929
import org.labkey.api.data.DataRegion;
3030
import org.labkey.api.module.Module;
31+
import org.labkey.api.pipeline.PipeRoot;
3132
import org.labkey.api.pipeline.PipelineService;
3233
import org.labkey.api.portal.ProjectUrls;
3334
import org.labkey.api.query.QueryDefinition;
@@ -301,6 +302,9 @@ public class FlowAdminAction extends FormViewAction<FlowAdminForm>
301302
@Override
302303
public void validateCommand(FlowAdminForm form, Errors errors)
303304
{
305+
PipeRoot root = PipelineService.get().findPipelineRoot(getContainer());
306+
if (root == null)
307+
errors.rejectValue("root", ERROR_MSG, "Pipeline root not found for the current container.");
304308
}
305309

306310
@Override
@@ -313,12 +317,13 @@ public ModelAndView getView(FlowAdminForm form, boolean reshow, BindException er
313317
@Override
314318
public boolean handlePost(FlowAdminForm form, BindException errors)
315319
{
316-
if (form.getWorkingDirectory() != null && PipelineService.get().findPipelineRoot(getContainer()).getRootFileLike().isDescendant(FileUtil.createUri(form.getWorkingDirectory()) ))
320+
PipeRoot root = PipelineService.get().findPipelineRoot(getContainer());
321+
322+
if (form.getWorkingDirectory() != null && root.getRootFileLike().isDescendant(FileUtil.createUri(form.getWorkingDirectory())))
317323
{
318-
FileLike dir = new FileSystemLike.Builder(FileUtil.stringToPath(getContainer(), form.getWorkingDirectory()))
319-
.readonly().root();
324+
FileLike dir = root.resolvePathToFileLike(form.getWorkingDirectory());
320325

321-
if (!dir.exists())
326+
if (dir == null || !dir.exists())
322327
{
323328
errors.rejectValue("workingDirectory", ERROR_MSG, "Path does not exist: " + form.getWorkingDirectory());
324329
return false;

flow/src/org/labkey/flow/data/FlowCompensationMatrix.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.labkey.api.query.FieldKey;
2626
import org.labkey.api.query.QueryRowReference;
2727
import org.labkey.api.security.User;
28+
import org.labkey.api.util.FileUtil;
2829
import org.labkey.api.view.ActionURL;
2930
import org.labkey.flow.FlowSettings;
3031
import org.labkey.flow.analysis.model.CompensationMatrix;
@@ -38,9 +39,7 @@
3839
import org.labkey.flow.query.FlowTableType;
3940

4041
import jakarta.servlet.http.HttpServletRequest;
41-
import java.io.File;
4242
import java.io.Serializable;
43-
import java.util.ArrayList;
4443
import java.util.HashMap;
4544
import java.util.List;
4645
import java.util.Map;
@@ -89,7 +88,7 @@ static public FlowCompensationMatrix create(User user, Container container, Stri
8988
{
9089
data = svc.createData(container, FlowDataType.CompensationMatrix, name);
9190
}
92-
data.setDataFileURI(new File(FlowSettings.getWorkingDirectory(), "compensation." + FlowDataHandler.EXT_DATA).toURI());
91+
data.setDataFileURI(FileUtil.appendName(FlowSettings.getWorkingDirectory(), "compensation." + FlowDataHandler.EXT_DATA).toURI());
9392
data.save(user);
9493
AttributeSetHelper.doSave(attrs, user, data, log);
9594
flowComp = (FlowCompensationMatrix) FlowDataObject.fromData(data);
@@ -105,8 +104,8 @@ public CompensationMatrix getCompensationMatrix()
105104

106105
static public CompensationMatrix getCompensationMatrix(String name, AttributeSet attrs)
107106
{
108-
TreeSet<String> channelNames = new TreeSet();
109-
Map<String, Double> values = new HashMap();
107+
TreeSet<String> channelNames = new TreeSet<>();
108+
Map<String, Double> values = new HashMap<>();
110109
for (Map.Entry<StatisticSpec, Double> entry : attrs.getStatistics().entrySet())
111110
{
112111
StatisticSpec spec = entry.getKey();
@@ -119,20 +118,20 @@ static public CompensationMatrix getCompensationMatrix(String name, AttributeSet
119118
channelNames.add(strChannel);
120119
values.put(spec.getParameter(), entry.getValue());
121120
}
122-
if (channelNames.size() == 0)
121+
if (channelNames.isEmpty())
123122
return null;
124123
CompensationMatrix ret = new CompensationMatrix(name);
125-
String[] arrChannelNames = channelNames.toArray(new String[channelNames.size()]);
124+
String[] arrChannelNames = channelNames.toArray(new String[0]);
126125

127-
for (int iChannel = 0; iChannel < arrChannelNames.length; iChannel ++)
126+
for (String arrChannelName : arrChannelNames)
128127
{
129-
Map<String, Double> channelValues = new TreeMap();
130-
for (int iChannelValue = 0; iChannelValue < arrChannelNames.length; iChannelValue ++)
128+
Map<String, Double> channelValues = new TreeMap<>();
129+
for (String channelName : arrChannelNames)
131130
{
132-
String key = arrChannelNames[iChannel] + ":" + arrChannelNames[iChannelValue];
133-
channelValues.put(arrChannelNames[iChannelValue], values.get(key));
131+
String key = arrChannelName + ":" + channelName;
132+
channelValues.put(channelName, values.get(key));
134133
}
135-
ret.setChannel(arrChannelNames[iChannel], channelValues);
134+
ret.setChannel(arrChannelName, channelValues);
136135
}
137136
return ret;
138137
}
@@ -195,15 +194,17 @@ static public List<FlowCompensationMatrix> getCompensationMatrices(Container con
195194
{
196195
return (List) FlowDataObject.fromDataType(container, FlowDataType.CompensationMatrix);
197196
}
198-
static public List<FlowCompensationMatrix> getUploadedCompensationMatrices(Container container)
199-
{
200-
List<FlowCompensationMatrix> all = getCompensationMatrices(container);
201-
List<FlowCompensationMatrix> ret = new ArrayList();
202-
for (FlowCompensationMatrix comp : all)
203-
{
204-
if (comp.getRun() == null)
205-
ret.add(comp);
206-
}
207-
return ret;
208-
}
197+
198+
//TODO remove?
199+
// static public List<FlowCompensationMatrix> getUploadedCompensationMatrices(Container container)
200+
// {
201+
// List<FlowCompensationMatrix> all = getCompensationMatrices(container);
202+
// List<FlowCompensationMatrix> ret = new ArrayList<>();
203+
// for (FlowCompensationMatrix comp : all)
204+
// {
205+
// if (comp.getRun() == null)
206+
// ret.add(comp);
207+
// }
208+
// return ret;
209+
// }
209210
}

0 commit comments

Comments
 (0)