Skip to content

Commit ed3bc4f

Browse files
authored
Merge pull request #121 from common-workflow-language/ontology-info
Ontology Information for File format fields
2 parents 2dc0329 + 4a867f1 commit ed3bc4f

File tree

9 files changed

+147
-63
lines changed

9 files changed

+147
-63
lines changed

Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,4 @@ WORKDIR /tmp
4545

4646
EXPOSE 8080
4747

48-
# Expects mongodb on port 27017
49-
ENV SPRING_DATA_MONGODB_HOST=mongo
50-
ENV SPRING_DATA_MONGODB_PORT=27017
51-
52-
# Expects a sparql server endpoint
53-
ENV SPARQL_ENDPOINT=http://sparql:3030/all/
54-
5548
CMD ["/usr/bin/java", "-jar", "/usr/lib/cwlviewer.jar"]

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@
9393
<artifactId>jackson-core</artifactId>
9494
<version>2.9.0.pr4</version>
9595
</dependency>
96+
<dependency>
97+
<groupId>org.apache.jena</groupId>
98+
<artifactId>jena-core</artifactId>
99+
<version>3.3.0</version>
100+
</dependency>
96101
</dependencies>
97102

98-
<build>
103+
<build>
99104
<plugins>
100105
<plugin>
101106
<groupId>org.springframework.boot</groupId>

src/main/java/org/commonwl/view/cwl/CWLElement.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CWLElement {
3333
private String label;
3434
private String doc;
3535
private String type;
36+
private String format;
3637
private List<String> sourceID;
3738
private String defaultVal;
3839

@@ -64,6 +65,22 @@ public void setType(String type) {
6465
this.type = type;
6566
}
6667

68+
public String getFormat() {
69+
return format;
70+
}
71+
72+
public void setFormat(String format) {
73+
this.format = format;
74+
}
75+
76+
public List<String> getSourceID() {
77+
return sourceID;
78+
}
79+
80+
public void setSourceID(List<String> sourceID) {
81+
this.sourceID = sourceID;
82+
}
83+
6784
public List<String> getSourceIDs() {
6885
return sourceID;
6986
}

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
import com.fasterxml.jackson.databind.node.TextNode;
2727
import org.apache.commons.io.FileUtils;
2828
import org.apache.commons.io.FilenameUtils;
29+
import org.apache.jena.ontology.OntModelSpec;
2930
import org.apache.jena.query.QuerySolution;
3031
import org.apache.jena.query.ResultSet;
3132
import org.apache.jena.rdf.model.Model;
3233
import org.apache.jena.rdf.model.ModelFactory;
3334
import org.apache.jena.rdf.model.Statement;
3435
import org.apache.jena.rdf.model.StmtIterator;
36+
import org.apache.jena.riot.RiotException;
3537
import org.commonwl.view.docker.DockerService;
3638
import org.commonwl.view.github.GitHubService;
3739
import org.commonwl.view.github.GithubDetails;
@@ -187,9 +189,6 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
187189
String packedWorkflowID) throws CWLValidationException {
188190

189191
// Get RDF representation from cwltool
190-
String graphName = String.format("github.com/%s/%s/%s/%s", githubInfo.getOwner(),
191-
githubInfo.getRepoName(), latestCommit, githubInfo.getPath());
192-
193192
String url = String.format("https://cdn.rawgit.com/%s/%s/%s/%s", githubInfo.getOwner(),
194193
githubInfo.getRepoName(), latestCommit, githubInfo.getPath());
195194
if (packedWorkflowID != null) {
@@ -199,21 +198,21 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
199198
url += packedWorkflowID;
200199
}
201200

202-
if (!rdfService.graphExists(graphName)) {
201+
if (!rdfService.graphExists(url)) {
203202
String rdf = cwlTool.getRDF(url);
204203

205204
// Create a workflow model from RDF representation
206205
Model model = ModelFactory.createDefaultModel();
207206
model.read(new ByteArrayInputStream(rdf.getBytes()), null, "TURTLE");
208207

209208
// Store the model
210-
rdfService.storeModel(graphName, model);
209+
rdfService.storeModel(url, model);
211210
}
212211

213212
// Base workflow details
214213
String label = FilenameUtils.getName(githubInfo.getPath());
215214
String doc = null;
216-
ResultSet labelAndDoc = rdfService.getLabelAndDoc(graphName, url);
215+
ResultSet labelAndDoc = rdfService.getLabelAndDoc(url);
217216
if (labelAndDoc.hasNext()) {
218217
QuerySolution labelAndDocSoln = labelAndDoc.nextSolution();
219218
if (labelAndDocSoln.contains("label")) {
@@ -226,7 +225,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
226225

227226
// Inputs
228227
Map<String, CWLElement> wfInputs = new HashMap<>();
229-
ResultSet inputs = rdfService.getInputs(graphName, url);
228+
ResultSet inputs = rdfService.getInputs(url);
230229
while (inputs.hasNext()) {
231230
QuerySolution input = inputs.nextSolution();
232231
String inputName = rdfService.stepNameFromURI(url, input.get("name").toString());
@@ -268,6 +267,10 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
268267
}
269268
}
270269

270+
if (input.contains("format")) {
271+
String format = input.get("format").toString();
272+
setFormat(wfInput, format);
273+
}
271274
if (input.contains("label")) {
272275
wfInput.setLabel(input.get("label").toString());
273276
}
@@ -279,7 +282,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
279282

280283
// Outputs
281284
Map<String, CWLElement> wfOutputs = new HashMap<>();
282-
ResultSet outputs = rdfService.getOutputs(graphName, url);
285+
ResultSet outputs = rdfService.getOutputs(url);
283286
while (outputs.hasNext()) {
284287
QuerySolution output = outputs.nextSolution();
285288
CWLElement wfOutput = new CWLElement();
@@ -326,6 +329,10 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
326329
wfOutput.addSourceID(rdfService.stepNameFromURI(url,
327330
output.get("src").toString()));
328331
}
332+
if (output.contains("format")) {
333+
String format = output.get("format").toString();
334+
setFormat(wfOutput, format);
335+
}
329336
if (output.contains("label")) {
330337
wfOutput.setLabel(output.get("label").toString());
331338
}
@@ -338,7 +345,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
338345

339346
// Steps
340347
Map<String, CWLStep> wfSteps = new HashMap<>();
341-
ResultSet steps = rdfService.getSteps(graphName, url);
348+
ResultSet steps = rdfService.getSteps(url);
342349
while (steps.hasNext()) {
343350
QuerySolution step = steps.nextSolution();
344351
String uri = rdfService.stepNameFromURI(url, step.get("step").toString());
@@ -390,7 +397,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
390397
}
391398

392399
// Docker link
393-
ResultSet dockerResult = rdfService.getDockerLink(graphName, url);
400+
ResultSet dockerResult = rdfService.getDockerLink(url);
394401
String dockerLink = null;
395402
if (dockerResult.hasNext()) {
396403
QuerySolution docker = dockerResult.nextSolution();
@@ -407,7 +414,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
407414

408415
// Generate DOT graph
409416
StringWriter graphWriter = new StringWriter();
410-
RDFDotWriter RDFDotWriter = new RDFDotWriter(graphWriter, rdfService, graphName);
417+
RDFDotWriter RDFDotWriter = new RDFDotWriter(graphWriter, rdfService);
411418
try {
412419
RDFDotWriter.writeGraph(url);
413420
workflowModel.setVisualisationDot(graphWriter.toString());
@@ -470,6 +477,26 @@ public WorkflowOverview getWorkflowOverview(GithubDetails githubInfo) throws IOE
470477

471478
}
472479

480+
/**
481+
* Set the format for an input or output, handling ontologies
482+
* @param inputOutput The input or output CWL Element
483+
* @param format The format URI
484+
*/
485+
private void setFormat(CWLElement inputOutput, String format) {
486+
inputOutput.setFormat(format);
487+
try {
488+
if (!rdfService.ontPropertyExists(format)) {
489+
Model ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
490+
ontModel.read(format, null, "RDF/XML");
491+
rdfService.addToOntologies(ontModel);
492+
}
493+
String formatLabel = rdfService.getOntLabel(format);
494+
inputOutput.setType(inputOutput.getType() + " (" + formatLabel + " format)");
495+
} catch (RiotException ex) {
496+
inputOutput.setType(inputOutput.getType() + " (format)");
497+
}
498+
}
499+
473500
/**
474501
* Convert RDF URI for a type to a name
475502
* @param uri The URI for the type

0 commit comments

Comments
 (0)