Skip to content

Commit 7a49d3a

Browse files
Adopt FileLike for more pipeline APIs (#1061)
1 parent e7ada07 commit 7a49d3a

9 files changed

Lines changed: 48 additions & 59 deletions

File tree

ehr/api-src/org/labkey/api/ehr/EHRService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import org.labkey.api.util.URLHelper;
4545
import org.labkey.api.view.ActionURL;
4646
import org.labkey.api.view.template.ClientDependency;
47+
import org.labkey.vfs.FileLike;
4748

48-
import java.io.File;
4949
import java.io.IOException;
5050
import java.util.Collection;
5151
import java.util.Date;
@@ -339,7 +339,7 @@ public EHRQCState getQCState(@NotNull Container c)
339339
* A use case is a separate pipeline server that performs the R computation on a cluster, and then triggers the main webserver to import
340340
* those results.
341341
*/
342-
abstract public void standaloneProcessKinshipAndInbreeding(Container c, User u, File pipelineDir, Logger log) throws PipelineJobException;
342+
abstract public void standaloneProcessKinshipAndInbreeding(Container c, User u, FileLike pipelineDir, Logger log) throws PipelineJobException;
343343

344344
/** Applicable for centers who use the model that projects have a reference to a protocol. Caches a protocol for a given project. **/
345345
abstract public void updateCachedProtocol(Container c, Integer project, String protocol);

ehr/resources/web/ehr/panel/ManageTreatmentsPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Ext4.define('EHR.panel.ManageTreatmentsPanel', {
276276
dataIndex: 'amountAndVolume',
277277
renderer: function(value, cellMetaData, record){
278278
if (value){
279-
return value.replace(/\n/, '<br>');
279+
return value.replace(/\n/g, '<br>');
280280
}
281281

282282
return value;

ehr/src/org/labkey/ehr/EHRServiceImpl.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
import org.labkey.ehr.security.EHRSecurityManager;
8484
import org.labkey.ehr.table.DefaultEHRCustomizer;
8585
import org.labkey.ehr.table.SNOMEDCodesDisplayColumn;
86+
import org.labkey.vfs.FileLike;
8687

87-
import java.io.File;
8888
import java.io.FileNotFoundException;
8989
import java.io.IOException;
9090
import java.io.InputStream;
@@ -923,28 +923,28 @@ public void importFolderDefinition(Container container, User user, Module m, Pat
923923
{
924924
Resource root = m.getModuleResource(sourceFolderDirPath);
925925
PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(container);
926-
java.nio.file.Path pipeRootPath = pipeRoot.getRootNioPath();
926+
FileLike pipeRootPath = pipeRoot.getRootFileLike();
927927

928-
java.nio.file.Path folderXmlPath;
928+
FileLike folderXmlPath;
929929

930-
if (root instanceof DirectoryResource && ((DirectoryResource)root).getDir().equals(pipeRootPath.toFile()))
930+
if (root instanceof DirectoryResource dir && dir.getDir().equals(pipeRootPath.toNioPathForRead().toFile()))
931931
{
932932
// The pipeline root is already pointed at the folder definition, like it might be on a dev machine.
933933
// No need to copy, especially since copying can cause infinite recursion when the paths are nested
934-
folderXmlPath = pipeRootPath.resolve("folder.xml");
934+
folderXmlPath = pipeRootPath.resolveChild("folder.xml");
935935
}
936936
else
937937
{
938-
java.nio.file.Path folderPath = pipeRootPath.resolve("moduleFolderImport");
939-
folderXmlPath = folderPath.resolve("folder.xml");
940-
if (Files.exists(folderPath))
938+
FileLike folderPath = pipeRootPath.resolveChild("moduleFolderImport");
939+
folderXmlPath = folderPath.resolveChild("folder.xml");
940+
if (folderPath.exists())
941941
{
942942
FileUtil.deleteDir(folderPath);
943943
}
944944
copyResourceToPath(root, folderPath);
945945
}
946946

947-
if (!Files.exists(folderXmlPath))
947+
if (!folderXmlPath.exists())
948948
{
949949
throw new FileNotFoundException("Couldn't find an extracted " + folderXmlPath);
950950
}
@@ -954,21 +954,21 @@ public void importFolderDefinition(Container container, User user, Module m, Pat
954954
PipelineService.get().runFolderImportJob(container, user, null, folderXmlPath, "folder.xml", pipeRoot, options);
955955
}
956956

957-
private void copyResourceToPath(Resource resource, java.nio.file.Path target) throws IOException
957+
private void copyResourceToPath(Resource resource, FileLike target) throws IOException
958958
{
959959
if (resource.isCollection())
960960
{
961-
Files.createDirectory(target);
961+
FileUtil.createDirectory(target);
962962
for (Resource child : resource.list())
963963
{
964-
java.nio.file.Path childTarget = target.resolve(child.getName());
964+
FileLike childTarget = target.resolveChild(child.getName());
965965
copyResourceToPath(child, childTarget);
966966
}
967967
}
968968
else
969969
{
970970
try (InputStream in = resource.getInputStream();
971-
OutputStream out = Files.newOutputStream(target))
971+
OutputStream out = target.openOutputStream())
972972
{
973973
FileUtil.copyData(in, out);
974974
}
@@ -1069,7 +1069,7 @@ public void appendSNOMEDCols(AbstractTableInfo ti, String displayColumnName, Str
10691069
}
10701070

10711071
@Override
1072-
public void standaloneProcessKinshipAndInbreeding(Container c, User u, File pipelineDir, Logger log) throws PipelineJobException
1072+
public void standaloneProcessKinshipAndInbreeding(Container c, User u, FileLike pipelineDir, Logger log) throws PipelineJobException
10731073
{
10741074
GeneticCalculationsImportTask.standaloneProcessKinshipAndInbreeding(c, u, pipelineDir, log);
10751075
}

ehr/src/org/labkey/ehr/pipeline/GeneticCalculationsImportTask.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.labkey.api.util.FileType;
5858
import org.labkey.api.util.PageFlowUtil;
5959
import org.labkey.ehr.EHRSchema;
60+
import org.labkey.vfs.FileLike;
6061

6162
import java.io.BufferedReader;
6263
import java.io.File;
@@ -151,8 +152,8 @@ public RecordedActionSet run() throws PipelineJobException
151152
PipelineJob job = getJob();
152153
FileAnalysisJobSupport support = (FileAnalysisJobSupport) job;
153154

154-
processInbreeding(job.getContainer(), job.getUser(), support.getAnalysisDirectoryPath().toFile(), job.getLogger());
155-
processKinship(job.getContainer(), job.getUser(), support.getAnalysisDirectoryPath().toFile(), job.getLogger(), job);
155+
processInbreeding(job.getContainer(), job.getUser(), support.getAnalysisDirectoryFileLike(), job.getLogger());
156+
processKinship(job.getContainer(), job.getUser(), support.getAnalysisDirectoryFileLike(), job.getLogger(), job);
156157

157158
if (GeneticCalculationsJob.isKinshipValidation())
158159
{
@@ -170,15 +171,15 @@ public RecordedActionSet run() throws PipelineJobException
170171
return new RecordedActionSet(actions);
171172
}
172173

173-
public static void standaloneProcessKinshipAndInbreeding(Container c, User u, File pipelineDir, Logger log) throws PipelineJobException
174+
public static void standaloneProcessKinshipAndInbreeding(Container c, User u, FileLike pipelineDir, Logger log) throws PipelineJobException
174175
{
175176
processInbreeding(c, u, pipelineDir, log);
176177
processKinship(c, u, pipelineDir, log, null);
177178
}
178179

179-
private static void processKinship(Container c, User u, File pipelineDir, Logger log, @Nullable PipelineJob job) throws PipelineJobException
180+
private static void processKinship(Container c, User u, FileLike pipelineDir, Logger log, @Nullable PipelineJob job) throws PipelineJobException
180181
{
181-
File output = new File(pipelineDir, KINSHIP_FILE);
182+
FileLike output = pipelineDir.resolveChild(KINSHIP_FILE);
182183
if (!output.exists())
183184
throw new PipelineJobException("Unable to find file: " + output.getPath());
184185

@@ -190,7 +191,7 @@ private static void processKinship(Container c, User u, File pipelineDir, Logger
190191
try
191192
{
192193
try (DbScope.Transaction transaction = ExperimentService.get().ensureTransaction();
193-
LineNumberReader lnr = new LineNumberReader(Readers.getReader(output)))
194+
LineNumberReader lnr = new LineNumberReader(Readers.getReader(output.openInputStream())))
194195
{
195196
while (lnr.readLine() != null)
196197
{
@@ -248,7 +249,7 @@ else if (kinshipTable.getSqlDialect().isPostgreSQL())
248249
}
249250

250251
try (DbScope.Transaction transaction = ExperimentService.get().ensureTransaction();
251-
BufferedReader reader = Readers.getReader(output);
252+
BufferedReader reader = Readers.getReader(output.openInputStream());
252253
PreparedStatement stmt = transaction.getConnection().prepareStatement(
253254
"INSERT INTO " + EHRSchema.EHR_SCHEMANAME + ".kinship\n" +
254255
"\t(Id, Id2, coefficient, container, created, createdby, modified, modifiedby)\n" +
@@ -619,9 +620,9 @@ private static TableInfo getRealTable(TableInfo ti)
619620
return null;
620621
}
621622

622-
private static void processInbreeding(Container c, User u, File pipelineDir, Logger log) throws PipelineJobException
623+
private static void processInbreeding(Container c, User u, FileLike pipelineDir, Logger log) throws PipelineJobException
623624
{
624-
File output = new File(pipelineDir, INBREEDING_FILE);
625+
FileLike output = pipelineDir.resolveChild(INBREEDING_FILE);
625626
if (!output.exists())
626627
throw new PipelineJobException("Unable to find file: " + output.getPath());
627628

@@ -636,12 +637,12 @@ private static void processInbreeding(Container c, User u, File pipelineDir, Log
636637
QueryUpdateService qus = ti.getUpdateService();
637638
qus.setBulkLoad(true);
638639

639-
try (BufferedReader reader = Readers.getReader(output))
640+
try (BufferedReader reader = Readers.getReader(output.openInputStream()))
640641
{
641642
try (DbScope.Transaction transaction = ExperimentService.get().ensureTransaction())
642643
{
643644
log.info("Inspecting file length: " + output.getPath());
644-
try (LineNumberReader lnr = new LineNumberReader(Readers.getReader(output)))
645+
try (LineNumberReader lnr = new LineNumberReader(Readers.getReader(output.openInputStream())))
645646
{
646647
while (lnr.readLine() != null)
647648
{

ehr/src/org/labkey/ehr/pipeline/GeneticCalculationsRunnable.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import org.labkey.api.pipeline.file.FileAnalysisTaskPipeline;
3232
import org.labkey.api.security.User;
3333
import org.labkey.api.util.ConfigurationException;
34+
import org.labkey.api.util.FileUtil;
3435
import org.labkey.api.util.StringUtilsLabKey;
3536
import org.labkey.api.util.logging.LogHelper;
3637
import org.labkey.api.view.ActionURL;
3738
import org.labkey.api.view.ViewBackgroundInfo;
3839
import org.labkey.ehr.EHRManager;
40+
import org.labkey.vfs.FileLike;
3941

4042
import java.io.File;
4143
import java.io.FileWriter;
@@ -97,11 +99,11 @@ private void startCalculation(User u, Container c, boolean allowRunningDuringDay
9799

98100
protocol.setTimestampLog(true);
99101

100-
File fileParameters = protocol.getParametersFile(root.getRootPath(), root);
102+
FileLike fileParameters = protocol.getParametersFile(root.getRootFileLike(), root);
101103
if (!fileParameters.exists())
102104
{
103-
fileParameters.getParentFile().mkdirs();
104-
fileParameters.createNewFile();
105+
fileParameters.getParent().mkdirs();
106+
FileUtil.createNewFile(fileParameters, true);
105107
}
106108
protocol.saveInstance(fileParameters, c);
107109

@@ -118,11 +120,11 @@ private void startCalculation(User u, Container c, boolean allowRunningDuringDay
118120
w.write(xml);
119121
}
120122

121-
File inputFile = new File(root.getRootPath(), "kinship.txt");
123+
FileLike inputFile = root.resolvePathToFileLike("kinship.txt");
122124
if (!inputFile.exists())
123-
inputFile.createNewFile();
125+
FileUtil.createNewFile(inputFile, true);
124126

125-
AbstractFileAnalysisJob job = protocol.createPipelineJob(bg, root, Collections.singletonList(inputFile.toPath()), fileParameters.toPath(), null);
127+
AbstractFileAnalysisJob job = protocol.createPipelineJob(bg, root, Collections.singletonList(inputFile), fileParameters, null);
126128
PipelineService.get().queueJob(job);
127129

128130
String dateFormat = "yyyy_MM_dd_hh_mm_ss";
@@ -131,7 +133,7 @@ private void startCalculation(User u, Container c, boolean allowRunningDuringDay
131133
Date now = cal.getTime();
132134
String timestamp = formatter.format(now);
133135

134-
job.setLogFile(new File(job.getLogFile().getParent() + "/kinship_" + timestamp + ".txt.log"));
136+
job.setLogFile(job.getLogFileLike().getParent().resolveChild("kinship_" + timestamp + ".txt.log"));
135137
}
136138
catch (ClassNotFoundException e)
137139
{

ehr/test/src/org/labkey/test/tests/ehr/AbstractEHRTest.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.apache.commons.lang3.StringUtils;
1919
import org.json.JSONObject;
2020
import org.junit.Assert;
21+
import org.labkey.api.util.FileUtil;
22+
import org.labkey.api.util.Path;
2123
import org.labkey.remoteapi.CommandException;
2224
import org.labkey.remoteapi.Connection;
2325
import org.labkey.remoteapi.SimplePostCommand;
@@ -59,7 +61,6 @@
5961
import java.util.List;
6062
import java.util.Map;
6163
import java.util.UUID;
62-
import java.util.regex.Pattern;
6364

6465
import static org.junit.Assert.assertNull;
6566
import static org.junit.Assert.fail;
@@ -144,7 +145,7 @@ abstract public class AbstractEHRTest extends BaseWebDriverTest implements Advan
144145
protected List<Long> _saveRowsTimes;
145146

146147
protected abstract String getModuleDirectory();
147-
protected EHRBillingHelper _billingHelper = new EHRBillingHelper(this, getProjectName(), FOLDER_NAME, getModulePath(), getContainerPath(),BILLING_FOLDER);
148+
protected EHRBillingHelper _billingHelper = new EHRBillingHelper(this, getProjectName(), BILLING_FOLDER);
148149

149150
//xpath fragment
150151
public static final String VISIBLE = "not(ancestor-or-self::*[contains(@style,'visibility: hidden') or contains(@class, 'x-hide-display')])";
@@ -203,14 +204,6 @@ public void validateQueries(boolean validateSubfolders)
203204
}
204205
}
205206

206-
protected Pattern[] getIgnoredElements()
207-
{
208-
return new Pattern[] {
209-
Pattern.compile("qcstate", Pattern.CASE_INSENSITIVE),//qcstate IDs aren't predictable
210-
Pattern.compile("stacktrace", Pattern.CASE_INSENSITIVE)
211-
};
212-
}
213-
214207
protected String getMale() {
215208
return "m";
216209
}
@@ -365,8 +358,8 @@ public void doCleanup(boolean afterTest) throws TestTimeoutException
365358

366359
protected void importFolderFromPath(int jobCount)
367360
{
368-
File path = new File(TestFileUtils.getLabKeyRoot(), getModulePath() + "/resources/referenceStudy");
369-
setPipelineRoot(path.getPath());
361+
File path = FileUtil.appendPath(TestFileUtils.getLabKeyRoot(), Path.parse(getModulePath() + "/resources/referenceStudy"));
362+
setPipelineRoot(path.getPath(), false);
370363

371364
beginAt(WebTestHelper.getBaseURL() + "/" + getContainerPath() + "/pipeline-status-begin.view");
372365
clickButton("Process and Import Data", defaultWaitForPage);

ehr/test/src/org/labkey/test/tests/ehr/ComplianceTrainingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
@BaseWebDriverTest.ClassTimeout(minutes = 5)
5151
public abstract class ComplianceTrainingTest extends BaseWebDriverTest implements AdvancedSqlTest
5252
{
53-
private final String listZIP = TestFileUtils.getLabKeyRoot() + "/server/modules/ehrModules/EHR_ComplianceDB/tools/SOP_Lists.zip";
53+
private final String listZIP = new File(TestFileUtils.getLabKeyRoot(), "server/modules/ehrModules/EHR_ComplianceDB/tools/SOP_Lists.zip").getPath();
5454

5555
@Override
5656
protected String getProjectName()

ehr/test/src/org/labkey/test/tests/ehr/EHRBillingHelper.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public class EHRBillingHelper
4545
{
4646
private final BaseWebDriverTest _test;
4747
private final String _projectName;
48-
private String _folderName;
49-
private String _modulePath;
50-
private String _containerPath;
5148
private String _billingFolder;
5249
public Ext4Helper _ext4Helper;
5350

@@ -58,12 +55,9 @@ public EHRBillingHelper(BaseWebDriverTest test, String projectName)
5855
_ext4Helper = new Ext4Helper(_test);
5956
}
6057

61-
public EHRBillingHelper(BaseWebDriverTest test, String projectName, String folderName, String modulePath, String containerPath, String billingFolder)
58+
public EHRBillingHelper(BaseWebDriverTest test, String projectName, String billingFolder)
6259
{
6360
this(test, projectName);
64-
_folderName = folderName;
65-
_modulePath = modulePath;
66-
_containerPath = containerPath;
6761
_billingFolder = billingFolder;
6862
}
6963

@@ -88,7 +82,7 @@ public void performBillingRun(String startDate, String endDate, String comment,
8882

8983
public void checkMessageWindow(String title, @Nullable String bodyText, String buttonText)
9084
{
91-
Window msgWindow = new Window.WindowFinder(_test.getDriver()).withTitle(title).waitFor();
85+
Window<?> msgWindow = new Window.WindowFinder(_test.getDriver()).withTitle(title).waitFor();
9286
assertEquals("Message window Title mismatch", title, msgWindow.getTitle());
9387

9488
if (null != bodyText)
@@ -149,7 +143,7 @@ public void verifyBillingInvoicedItemsUsingAPI(String InvoicedId, List<InvoicedI
149143
int sumQuantity = 0;
150144
for (Map<String, Object> row : resp.getRows())
151145
if (row.get("quantity") != null)
152-
sumQuantity += (double) row.get("quantity");
146+
sumQuantity += ((Number) row.get("quantity")).intValue();
153147

154148
assertEquals("Total quantity is not as expected", String.valueOf(sumQuantity), item.getTotalQuantity());
155149
}

ehr_billing/src/org/labkey/ehr_billing/pipeline/BillingTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ public List<String> getProtocolActionNames()
111111
}
112112

113113
@Override
114-
public PipelineJob.Task createTask(PipelineJob job)
114+
public BillingTask createTask(PipelineJob job)
115115
{
116-
117116
return new BillingTask(this, job);
118117
}
119118

0 commit comments

Comments
 (0)