52
52
import java .io .File ;
53
53
import java .io .IOException ;
54
54
import java .io .StringWriter ;
55
+ import java .nio .file .Files ;
56
+ import java .nio .file .Path ;
55
57
import java .util .*;
56
58
57
59
import static org .apache .commons .io .FileUtils .readFileToString ;
@@ -161,14 +163,14 @@ public List<WorkflowOverview> getWorkflowOverviewsFromPacked(File packedFile) th
161
163
* @param packedWorkflowId The ID of the workflow object if the file is packed
162
164
* @return The constructed workflow object
163
165
*/
164
- public Workflow parseWorkflowNative (File workflowFile , String packedWorkflowId ) throws IOException {
166
+ public Workflow parseWorkflowNative (Path workflowFile , String packedWorkflowId ) throws IOException {
165
167
166
168
// Check file size limit before parsing
167
- long fileSizeBytes = workflowFile . length ( );
169
+ long fileSizeBytes = Files . size ( workflowFile );
168
170
if (fileSizeBytes <= singleFileSizeLimit ) {
169
171
170
172
// Parse file as yaml
171
- JsonNode cwlFile = yamlStringToJson (readFileToString (workflowFile ));
173
+ JsonNode cwlFile = yamlStringToJson (readFileToString (workflowFile . toFile () ));
172
174
173
175
// Check packed workflow occurs
174
176
if (packedWorkflowId != null ) {
@@ -199,7 +201,7 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
199
201
// Use filename for label if there is no defined one
200
202
String label = extractLabel (cwlFile );
201
203
if (label == null ) {
202
- label = FilenameUtils . getName ( workflowFile .getPath () );
204
+ label = workflowFile .getFileName (). toString ( );
203
205
}
204
206
205
207
// Construct the rest of the workflow model
@@ -221,7 +223,7 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
221
223
return workflowModel ;
222
224
223
225
} else {
224
- throw new IOException ("File '" + workflowFile .getName () + "' is over singleFileSizeLimit - " +
226
+ throw new IOException ("File '" + workflowFile .getFileName () + "' is over singleFileSizeLimit - " +
225
227
FileUtils .byteCountToDisplaySize (fileSizeBytes ) + "/" +
226
228
FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
227
229
}
@@ -235,29 +237,32 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
235
237
* @return The constructed workflow object
236
238
*/
237
239
public Workflow parseWorkflowWithCwltool (Workflow basicModel ,
238
- File workflowFile ) throws CWLValidationException {
240
+ Path workflowFile ,
241
+ Path workTree ) throws CWLValidationException {
239
242
GitDetails gitDetails = basicModel .getRetrievedFrom ();
240
243
String latestCommit = basicModel .getLastCommit ();
241
244
String packedWorkflowID = gitDetails .getPackedId ();
242
245
243
246
// Get paths to workflow
244
- String url = gitDetails . getUrl ( latestCommit ). replace ( "https://" , "" );
245
- String localPath = workflowFile .toPath (). toAbsolutePath ().toString ();
247
+ String url = basicModel . getPermalink ( );
248
+ String localPath = workflowFile .toAbsolutePath ().toString ();
246
249
String gitPath = gitDetails .getPath ();
247
250
if (packedWorkflowID != null ) {
248
251
if (packedWorkflowID .charAt (0 ) != '#' ) {
249
252
localPath += "#" ;
250
- url += "#" ;
251
253
gitPath += "#" ;
252
254
}
253
255
localPath += packedWorkflowID ;
254
- url += packedWorkflowID ;
255
256
gitPath += packedWorkflowID ;
256
257
}
257
258
258
259
// Get RDF representation from cwltool
259
260
if (!rdfService .graphExists (url )) {
260
261
String rdf = cwlTool .getRDF (localPath );
262
+ rdf = rdf .replace ("file://" + workTree .toAbsolutePath ().toString (),
263
+ "https://w3id.org/cwl/view/git/" + latestCommit );
264
+ // Workaround for common-workflow-language/cwltool#427
265
+ rdf = rdf .replace ("<rdfs:>" , "<http://www.w3.org/2000/01/rdf-schema#>" );
261
266
262
267
// Create a workflow model from RDF representation
263
268
Model model = ModelFactory .createDefaultModel ();
@@ -270,7 +275,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
270
275
// Base workflow details
271
276
String label = FilenameUtils .getName (url );
272
277
String doc = null ;
273
- ResultSet labelAndDoc = rdfService .getLabelAndDoc (gitPath , url );
278
+ ResultSet labelAndDoc = rdfService .getLabelAndDoc (url );
274
279
if (labelAndDoc .hasNext ()) {
275
280
QuerySolution labelAndDocSoln = labelAndDoc .nextSolution ();
276
281
if (labelAndDocSoln .contains ("label" )) {
@@ -283,7 +288,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
283
288
284
289
// Inputs
285
290
Map <String , CWLElement > wfInputs = new HashMap <>();
286
- ResultSet inputs = rdfService .getInputs (gitPath , url );
291
+ ResultSet inputs = rdfService .getInputs (url );
287
292
while (inputs .hasNext ()) {
288
293
QuerySolution input = inputs .nextSolution ();
289
294
String inputName = rdfService .stepNameFromURI (gitPath , input .get ("name" ).toString ());
@@ -316,7 +321,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
316
321
317
322
// Outputs
318
323
Map <String , CWLElement > wfOutputs = new HashMap <>();
319
- ResultSet outputs = rdfService .getOutputs (gitPath , url );
324
+ ResultSet outputs = rdfService .getOutputs (url );
320
325
while (outputs .hasNext ()) {
321
326
QuerySolution output = outputs .nextSolution ();
322
327
CWLElement wfOutput = new CWLElement ();
@@ -355,7 +360,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
355
360
356
361
// Steps
357
362
Map <String , CWLStep > wfSteps = new HashMap <>();
358
- ResultSet steps = rdfService .getSteps (gitPath , url );
363
+ ResultSet steps = rdfService .getSteps (url );
359
364
while (steps .hasNext ()) {
360
365
QuerySolution step = steps .nextSolution ();
361
366
String uri = rdfService .stepNameFromURI (gitPath , step .get ("step" ).toString ());
@@ -376,9 +381,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
376
381
// Add new step
377
382
CWLStep wfStep = new CWLStep ();
378
383
379
- IRI wfStepUri = iriFactory .construct (step .get ("wf" ).asResource ().getURI ());
380
- IRI workflowPath = wfStepUri .resolve ("./" );
381
-
384
+ IRI workflowPath = iriFactory .construct (url ).resolve ("./" );
382
385
IRI runPath = iriFactory .construct (step .get ("run" ).asResource ().getURI ());
383
386
wfStep .setRun (workflowPath .relativize (runPath ).toString ());
384
387
wfStep .setRunType (rdfService .strToRuntype (step .get ("runtype" ).toString ()));
@@ -409,7 +412,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
409
412
}
410
413
411
414
// Docker link
412
- ResultSet dockerResult = rdfService .getDockerLink (gitPath , url );
415
+ ResultSet dockerResult = rdfService .getDockerLink (url );
413
416
String dockerLink = null ;
414
417
if (dockerResult .hasNext ()) {
415
418
QuerySolution docker = dockerResult .nextSolution ();
0 commit comments