5252import java .io .File ;
5353import java .io .IOException ;
5454import java .io .StringWriter ;
55+ import java .nio .file .Files ;
56+ import java .nio .file .Path ;
5557import java .util .*;
5658
5759import static org .apache .commons .io .FileUtils .readFileToString ;
@@ -161,14 +163,14 @@ public List<WorkflowOverview> getWorkflowOverviewsFromPacked(File packedFile) th
161163 * @param packedWorkflowId The ID of the workflow object if the file is packed
162164 * @return The constructed workflow object
163165 */
164- public Workflow parseWorkflowNative (File workflowFile , String packedWorkflowId ) throws IOException {
166+ public Workflow parseWorkflowNative (Path workflowFile , String packedWorkflowId ) throws IOException {
165167
166168 // Check file size limit before parsing
167- long fileSizeBytes = workflowFile . length ( );
169+ long fileSizeBytes = Files . size ( workflowFile );
168170 if (fileSizeBytes <= singleFileSizeLimit ) {
169171
170172 // Parse file as yaml
171- JsonNode cwlFile = yamlStringToJson (readFileToString (workflowFile ));
173+ JsonNode cwlFile = yamlStringToJson (readFileToString (workflowFile . toFile () ));
172174
173175 // Check packed workflow occurs
174176 if (packedWorkflowId != null ) {
@@ -199,7 +201,7 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
199201 // Use filename for label if there is no defined one
200202 String label = extractLabel (cwlFile );
201203 if (label == null ) {
202- label = FilenameUtils . getName ( workflowFile .getPath () );
204+ label = workflowFile .getFileName (). toString ( );
203205 }
204206
205207 // Construct the rest of the workflow model
@@ -221,7 +223,7 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
221223 return workflowModel ;
222224
223225 } else {
224- throw new IOException ("File '" + workflowFile .getName () + "' is over singleFileSizeLimit - " +
226+ throw new IOException ("File '" + workflowFile .getFileName () + "' is over singleFileSizeLimit - " +
225227 FileUtils .byteCountToDisplaySize (fileSizeBytes ) + "/" +
226228 FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
227229 }
@@ -235,29 +237,32 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
235237 * @return The constructed workflow object
236238 */
237239 public Workflow parseWorkflowWithCwltool (Workflow basicModel ,
238- File workflowFile ) throws CWLValidationException {
240+ Path workflowFile ,
241+ Path workTree ) throws CWLValidationException {
239242 GitDetails gitDetails = basicModel .getRetrievedFrom ();
240243 String latestCommit = basicModel .getLastCommit ();
241244 String packedWorkflowID = gitDetails .getPackedId ();
242245
243246 // 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 ();
246249 String gitPath = gitDetails .getPath ();
247250 if (packedWorkflowID != null ) {
248251 if (packedWorkflowID .charAt (0 ) != '#' ) {
249252 localPath += "#" ;
250- url += "#" ;
251253 gitPath += "#" ;
252254 }
253255 localPath += packedWorkflowID ;
254- url += packedWorkflowID ;
255256 gitPath += packedWorkflowID ;
256257 }
257258
258259 // Get RDF representation from cwltool
259260 if (!rdfService .graphExists (url )) {
260261 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#>" );
261266
262267 // Create a workflow model from RDF representation
263268 Model model = ModelFactory .createDefaultModel ();
@@ -270,7 +275,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
270275 // Base workflow details
271276 String label = FilenameUtils .getName (url );
272277 String doc = null ;
273- ResultSet labelAndDoc = rdfService .getLabelAndDoc (gitPath , url );
278+ ResultSet labelAndDoc = rdfService .getLabelAndDoc (url );
274279 if (labelAndDoc .hasNext ()) {
275280 QuerySolution labelAndDocSoln = labelAndDoc .nextSolution ();
276281 if (labelAndDocSoln .contains ("label" )) {
@@ -283,7 +288,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
283288
284289 // Inputs
285290 Map <String , CWLElement > wfInputs = new HashMap <>();
286- ResultSet inputs = rdfService .getInputs (gitPath , url );
291+ ResultSet inputs = rdfService .getInputs (url );
287292 while (inputs .hasNext ()) {
288293 QuerySolution input = inputs .nextSolution ();
289294 String inputName = rdfService .stepNameFromURI (gitPath , input .get ("name" ).toString ());
@@ -316,7 +321,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
316321
317322 // Outputs
318323 Map <String , CWLElement > wfOutputs = new HashMap <>();
319- ResultSet outputs = rdfService .getOutputs (gitPath , url );
324+ ResultSet outputs = rdfService .getOutputs (url );
320325 while (outputs .hasNext ()) {
321326 QuerySolution output = outputs .nextSolution ();
322327 CWLElement wfOutput = new CWLElement ();
@@ -355,7 +360,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
355360
356361 // Steps
357362 Map <String , CWLStep > wfSteps = new HashMap <>();
358- ResultSet steps = rdfService .getSteps (gitPath , url );
363+ ResultSet steps = rdfService .getSteps (url );
359364 while (steps .hasNext ()) {
360365 QuerySolution step = steps .nextSolution ();
361366 String uri = rdfService .stepNameFromURI (gitPath , step .get ("step" ).toString ());
@@ -376,9 +381,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
376381 // Add new step
377382 CWLStep wfStep = new CWLStep ();
378383
379- IRI wfStepUri = iriFactory .construct (step .get ("wf" ).asResource ().getURI ());
380- IRI workflowPath = wfStepUri .resolve ("./" );
381-
384+ IRI workflowPath = iriFactory .construct (url ).resolve ("./" );
382385 IRI runPath = iriFactory .construct (step .get ("run" ).asResource ().getURI ());
383386 wfStep .setRun (workflowPath .relativize (runPath ).toString ());
384387 wfStep .setRunType (rdfService .strToRuntype (step .get ("runtype" ).toString ()));
@@ -409,7 +412,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
409412 }
410413
411414 // Docker link
412- ResultSet dockerResult = rdfService .getDockerLink (gitPath , url );
415+ ResultSet dockerResult = rdfService .getDockerLink (url );
413416 String dockerLink = null ;
414417 if (dockerResult .hasNext ()) {
415418 QuerySolution docker = dockerResult .nextSolution ();
0 commit comments