@@ -50,6 +50,15 @@ public RDFService(@Value("${sparql.endpoint}") String rdfService) {
50
50
this .rdfService = rdfService ;
51
51
}
52
52
53
+ /**
54
+ * Add to ontologies in the triple store
55
+ * @param model The model to be stored
56
+ */
57
+ public void addToOntologies (Model model ) {
58
+ DatasetAccessor accessor = DatasetAccessorFactory .createHTTP (rdfService );
59
+ accessor .putModel ("ontologies" , model );
60
+ }
61
+
53
62
/**
54
63
* Store a model with triples in the triple store
55
64
* @param graphName The name of the graph to store the model in
@@ -75,39 +84,77 @@ public boolean graphExists(String graphName) {
75
84
}
76
85
}
77
86
87
+ /**
88
+ * Check if a property of the ontology exists within the triple store
89
+ * @param ontUri The URI of the property
90
+ * @return Whether the graph exists
91
+ */
92
+ public boolean ontPropertyExists (String ontUri ) {
93
+ ParameterizedSparqlString graphQuery = new ParameterizedSparqlString ();
94
+ graphQuery .setCommandText ("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
95
+ "ASK WHERE { GRAPH ?graphName { ?ont rdfs:label ?label } }" );
96
+ graphQuery .setIri ("ont" , ontUri );
97
+ graphQuery .setIri ("graphName" , rdfService + "ontologies" );
98
+ Query query = QueryFactory .create (graphQuery .toString ());
99
+ try (QueryExecution qexec = QueryExecutionFactory .createServiceRequest (rdfService , query )) {
100
+ return qexec .execAsk ();
101
+ }
102
+ }
103
+
78
104
/**
79
105
* Get the label and doc strings for a workflow resource
80
- * @param graphName The graph containing the model
81
106
* @param workflowURI The URI of the workflow
82
107
* @return Result set with label and doc strings
83
108
*/
84
- public ResultSet getLabelAndDoc (String graphName , String workflowURI ) {
109
+ public ResultSet getLabelAndDoc (String workflowURI ) {
85
110
ParameterizedSparqlString labelQuery = new ParameterizedSparqlString ();
86
111
labelQuery .setCommandText (queryCtx +
87
112
"SELECT ?label ?doc\n " +
88
113
"WHERE {\n " +
89
- " GRAPH ?graphName {" +
114
+ " GRAPH ?wf {" +
90
115
" OPTIONAL { ?wf sld:label|rdfs:label ?label }\n " +
91
116
" OPTIONAL { ?wf sld:doc|rdfs:comment ?doc }\n " +
92
117
" }" +
93
118
"}" );
94
119
labelQuery .setIri ("wf" , workflowURI );
95
- labelQuery .setIri ("graphName" , rdfService + graphName );
96
120
return runQuery (labelQuery );
97
121
}
98
122
123
+ /**
124
+ * Get the label for an ontology URL
125
+ * TODO: can be merged with getLabelAndDoc when cwltool namespace bug is resolved
126
+ * @param ontologyURI The format URI for the ontology
127
+ * @return Result set with label and doc strings
128
+ */
129
+ public String getOntLabel (String ontologyURI ) {
130
+ ParameterizedSparqlString labelQuery = new ParameterizedSparqlString ();
131
+ labelQuery .setCommandText ("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
132
+ "SELECT ?label\n " +
133
+ "WHERE {\n " +
134
+ " GRAPH ?graphName {\n " +
135
+ " ?ont rdfs:label ?label\n " +
136
+ " }\n " +
137
+ "}\n " );
138
+ labelQuery .setIri ("ont" , ontologyURI );
139
+ labelQuery .setIri ("graphName" , rdfService + "ontologies" );
140
+ ResultSet result = runQuery (labelQuery );
141
+ if (result .hasNext ()) {
142
+ return result .next ().get ("label" ).toString ();
143
+ }
144
+ return null ;
145
+ }
146
+
99
147
/**
100
148
* Get the inputs for the workflow in the model
101
- * @param graphName The graph containing the model
102
149
* @param workflowURI URI of the workflow
103
150
* @return The result set of inputs
104
151
*/
105
- public ResultSet getInputs (String graphName , String workflowURI ) {
152
+ public ResultSet getInputs (String workflowURI ) {
106
153
ParameterizedSparqlString inputsQuery = new ParameterizedSparqlString ();
107
154
inputsQuery .setCommandText (queryCtx +
108
155
"SELECT ?name ?type ?format ?label ?doc\n " +
109
156
"WHERE {\n " +
110
- " GRAPH ?graphName {" +
157
+ " GRAPH ?wf {" +
111
158
" ?wf rdf:type cwl:Workflow .\n " +
112
159
" ?wf cwl:inputs ?name .\n " +
113
160
" OPTIONAL { ?name sld:type ?type }\n " +
@@ -117,22 +164,20 @@ public ResultSet getInputs(String graphName, String workflowURI) {
117
164
" }" +
118
165
"}" );
119
166
inputsQuery .setIri ("wf" , workflowURI );
120
- inputsQuery .setIri ("graphName" , rdfService + graphName );
121
167
return runQuery (inputsQuery );
122
168
}
123
169
124
170
/**
125
171
* Get the outputs for the workflow in the model
126
- * @param graphName The graph containing the model
127
172
* @param workflowURI URI of the workflow
128
173
* @return The result set of outputs
129
174
*/
130
- public ResultSet getOutputs (String graphName , String workflowURI ) {
175
+ public ResultSet getOutputs (String workflowURI ) {
131
176
ParameterizedSparqlString outputsQuery = new ParameterizedSparqlString ();
132
177
outputsQuery .setCommandText (queryCtx +
133
178
"SELECT ?name ?type ?format ?label ?doc\n " +
134
179
"WHERE {\n " +
135
- " GRAPH ?graphName {" +
180
+ " GRAPH ?wf {" +
136
181
" ?wf rdf:type cwl:Workflow .\n " +
137
182
" ?wf cwl:outputs ?name .\n " +
138
183
" OPTIONAL { ?name sld:type ?type }\n " +
@@ -142,17 +187,15 @@ public ResultSet getOutputs(String graphName, String workflowURI) {
142
187
" }" +
143
188
"}" );
144
189
outputsQuery .setIri ("wf" , workflowURI );
145
- outputsQuery .setIri ("graphName" , rdfService + graphName );
146
190
return runQuery (outputsQuery );
147
191
}
148
192
149
193
/**
150
194
* Get the steps for the workflow in the model
151
- * @param graphName The graph containing the model
152
195
* @param workflowURI URI of the workflow
153
196
* @return The result set of steps
154
197
*/
155
- public ResultSet getSteps (String graphName , String workflowURI ) {
198
+ public ResultSet getSteps (String workflowURI ) {
156
199
ParameterizedSparqlString stepQuery = new ParameterizedSparqlString ();
157
200
stepQuery .setCommandText (queryCtx +
158
201
"SELECT ?step ?run ?runtype ?label ?doc ?stepinput ?default ?src\n " +
@@ -170,74 +213,67 @@ public ResultSet getSteps(String graphName, String workflowURI) {
170
213
" }" +
171
214
"}" );
172
215
stepQuery .setIri ("wf" , workflowURI );
173
- stepQuery .setIri ("graphName" , rdfService + graphName );
174
216
return runQuery (stepQuery );
175
217
}
176
218
177
219
/**
178
220
* Get links between steps for the workflow in the model
179
- * @param graphName The graph containing the model
180
221
* @param workflowURI URI of the workflow
181
222
* @return The result set of step links
182
223
*/
183
- public ResultSet getStepLinks (String graphName , String workflowURI ) {
224
+ public ResultSet getStepLinks (String workflowURI ) {
184
225
ParameterizedSparqlString linkQuery = new ParameterizedSparqlString ();
185
226
linkQuery .setCommandText (queryCtx +
186
227
"SELECT ?src ?dest ?default\n " +
187
228
"WHERE {\n " +
188
- " GRAPH ?graphName {" +
229
+ " GRAPH ?wf {" +
189
230
" ?wf Workflow:steps ?step .\n " +
190
231
" ?step cwl:in ?dest .\n " +
191
232
" { ?dest cwl:source ?src } UNION { ?dest cwl:default ?default }\n " +
192
233
" }" +
193
234
"}" );
194
235
linkQuery .setIri ("wf" , workflowURI );
195
- linkQuery .setIri ("graphName" , rdfService + graphName );
196
236
return runQuery (linkQuery );
197
237
}
198
238
199
239
/**
200
240
* Get links between steps and outputs for the workflow in the model
201
- * @param graphName The graph containing the model
202
241
* @param workflowURI URI of the workflow
203
242
* @return The result set of steps
204
243
*/
205
- public ResultSet getOutputLinks (String graphName , String workflowURI ) {
244
+ public ResultSet getOutputLinks (String workflowURI ) {
206
245
ParameterizedSparqlString linkQuery = new ParameterizedSparqlString ();
207
246
linkQuery .setCommandText (queryCtx +
208
247
"SELECT ?src ?dest\n " +
209
248
"WHERE {\n " +
210
- " GRAPH ?graphName {" +
249
+ " GRAPH ?wf {" +
211
250
" ?wf rdf:type cwl:Workflow .\n " +
212
251
" ?wf cwl:outputs ?dest .\n " +
213
252
" ?dest cwl:outputSource ?src\n " +
214
253
" }" +
215
254
"}" );
216
255
linkQuery .setIri ("wf" , workflowURI );
217
- linkQuery .setIri ("graphName" , rdfService + graphName );
218
256
return runQuery (linkQuery );
219
257
}
220
258
221
259
/**
222
260
* Gets the docker requirement and pull link for a workflow
223
- * @param graphName The graph containing the model
224
261
* @param workflowURI URI of the workflow
225
262
* @return Result set of docker hint and pull link
226
263
*/
227
- public ResultSet getDockerLink (String graphName , String workflowURI ) {
264
+ public ResultSet getDockerLink (String workflowURI ) {
228
265
ParameterizedSparqlString dockerQuery = new ParameterizedSparqlString ();
229
266
dockerQuery .setCommandText (queryCtx +
230
267
"SELECT ?docker ?pull\n " +
231
268
"WHERE {\n " +
232
- " GRAPH ?graphName {" +
269
+ " GRAPH ?wf {" +
233
270
" ?wf rdf:type cwl:Workflow .\n " +
234
271
" { ?wf cwl:requirements ?docker } UNION { ?wf cwl:hints ?docker} .\n " +
235
272
" ?docker rdf:type cwl:DockerRequirement\n " +
236
273
" OPTIONAL { ?docker DockerRequirement:dockerPull ?pull }\n " +
237
274
" }" +
238
275
"}" );
239
276
dockerQuery .setIri ("wf" , workflowURI );
240
- dockerQuery .setIri ("graphName" , rdfService + graphName );
241
277
return runQuery (dockerQuery );
242
278
}
243
279
0 commit comments