Skip to content

Commit

Permalink
Add: queryRetrieveAbstractTemplateElements
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Jul 12, 2019
1 parent eaa50b2 commit 422e891
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
18 changes: 14 additions & 4 deletions src/main/java/edu/isi/wings/opmm/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.util.FileManager;
Expand Down Expand Up @@ -76,14 +77,13 @@ public static ResultSet queryLocalRepository(String queryIn, OntModel repository
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, repository);
ResultSet rs = qe.execSelect();
System.out.println(queryIn);
return rs;
}
/**
* Query an online repository
* @param queryIn query to specify
* @param endpointURI URI of the repository
* @return
* @return
*/
public static QuerySolution queryOnlineRepository(String queryIn, String endpointURI){
Query query = QueryFactory.create(queryIn);
Expand All @@ -92,11 +92,21 @@ public static QuerySolution queryOnlineRepository(String queryIn, String endpoin
ResultSet rs = qe.execSelect();
QuerySolution solution = null;
if(rs.hasNext())
solution = rs.next();
solution = rs.next();
qe.close();
return solution;
}


public static Model constructOnlineRepository(String queryIn, String endpointURI){
Query query = QueryFactory.create(queryIn);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, query);
Model rs = qe.execConstruct();
qe.close();
return rs;
}


/**
* Function that initializes a model. If the model exists, it empties it.
* If it doesn't exist (null) it returns a new instance of a model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ public static String queryWINGSTemplateMetadata(){
+ "OPTIONAL{?m <"+Constants.WINGS_DATA_PROP_LAST_UPDATED_TIME+"> ?time.}}";
return query;
}


/**
* Query for retrieving the elements of an abstract template from the remote repository
*/
public static String queryRetrieveAbstractTemplateElements(String queryTemplate){
String query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"CONSTRUCT {" +
"?a ?c ?d" +
"}" +
"from <urn:x-arq:UnionGraph>" +
"WHERE" +
"{ " +
" ?a ?b <" + queryTemplate + ">." +
" ?a ?c ?d" +
" filter not exists {?a a <https://www.opmw.org/ontology/WorkflowTemplate>}" +
"}";
return query;
}
/**
* Query to retrieve workflow template steps of a WINGS template
* @return
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/edu/isi/wings/opmm/WorkflowExecutionExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private String convertExecutionToOPMW(Individual wingsExecution) {
weInstance.addProperty(opmwModel.createProperty(Constants.OPMW_DATA_PROP_HAS_ORIGINAL_EXECUTION_FILE), wingsExecution.getURI());
//hasTime, endTime and execution status.
String queryExecutionMetadata = QueriesWorkflowExecutionExport.getWINGSExecutionMetadata(wingsExecution.getURI());
System.out.println("Queries queryExecutionMetadata");
ResultSet rs = ModelUtils.queryLocalRepository(queryExecutionMetadata, wingsExecutionModel);
//there is only 1 execution per file
if (rs.hasNext()) {
Expand Down Expand Up @@ -174,7 +173,6 @@ private String convertExecutionToOPMW(Individual wingsExecution) {

//get expanded template loaded in local model (for parameter linking)
String queryExpandedTemplate = QueriesWorkflowExecutionExport.getWINGSExpandedTemplate();
System.out.println("Queries queryExpandedTemplate");
rs = ModelUtils.queryLocalRepository(queryExpandedTemplate, wingsExecutionModel);
String expandedTemplateURI = null;
if (rs.hasNext()) {
Expand All @@ -190,7 +188,6 @@ private String convertExecutionToOPMW(Individual wingsExecution) {

//transform all steps and data dependencies (params are in expanded template)
String queryExecutionStepMetadata = QueriesWorkflowExecutionExport.getWINGSExecutionStepsAndMetadata();
System.out.println("Queries queryExecutionStepMedata");
rs = ModelUtils.queryLocalRepository(queryExecutionStepMetadata, wingsExecutionModel);
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Expand Down Expand Up @@ -245,7 +242,6 @@ private String convertExecutionToOPMW(Individual wingsExecution) {

//for each step get its i/o (plan)
String stepVariables = QueriesWorkflowExecutionExport.getWINGSExecutionStepI_O(wingsStep.getURI());
System.out.println("Queries step variables");
ResultSet rsVar = ModelUtils.queryLocalRepository(stepVariables, wingsExecutionModel);
while (rsVar.hasNext()) {
QuerySolution qsVar = rsVar.next();
Expand Down Expand Up @@ -286,7 +282,6 @@ private String convertExecutionToOPMW(Individual wingsExecution) {
//Parameters are specified in the expanded template. The current step is specified with the expanded template URI, same process id.
String wingsExpandedTempProcessURI = expandedTemplateURI + wingsStep.getLocalName();
String queryParams = QueriesWorkflowExecutionExport.getWINGSParametersForStep(wingsExpandedTempProcessURI);
System.out.println("Queries params variables");
ResultSet params = ModelUtils.queryLocalRepository(queryParams, concreteTemplateExport.getWingsTemplateModel());
while (params.hasNext()) {
QuerySolution nextP = params.next();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;

import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntClass;
Expand Down Expand Up @@ -114,6 +115,10 @@ public void transform(){
System.out.println("Template " +wingsTemplateName+" has already been published as "+foundTemplateURI.getURI());
//no export is necessary
transformedTemplate = opmwModel.createClass(Constants.OPMW_WORKFLOW_TEMPLATE).createIndividual(foundTemplateURI.getURI());
// String queryExec = QueriesWorkflowExecutionExport.getOPMWExecutionsWithRunID(wingsExecution.getLocalName());
// QuerySolution solution = ModelUtils.queryOnlineRepository(queryExec, endpointURI);
String queryTemplate = QueriesWorkflowTemplateExport.queryRetrieveAbstractTemplateElements(foundTemplateURI.getURI());
opmwModel.add(ModelUtils.constructOnlineRepository(queryTemplate, endpointURI));
isTemplatePublished = true;
return;
}else{
Expand Down

0 comments on commit 422e891

Please sign in to comment.