diff --git a/src/main/java/edu/isi/wings/opmm/ModelUtils.java b/src/main/java/edu/isi/wings/opmm/ModelUtils.java index 5b3a931..f83f0e8 100644 --- a/src/main/java/edu/isi/wings/opmm/ModelUtils.java +++ b/src/main/java/edu/isi/wings/opmm/ModelUtils.java @@ -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; @@ -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); @@ -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 diff --git a/src/main/java/edu/isi/wings/opmm/QueriesWorkflowTemplateExport.java b/src/main/java/edu/isi/wings/opmm/QueriesWorkflowTemplateExport.java index caacdd8..3b04f94 100644 --- a/src/main/java/edu/isi/wings/opmm/QueriesWorkflowTemplateExport.java +++ b/src/main/java/edu/isi/wings/opmm/QueriesWorkflowTemplateExport.java @@ -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: " + + "CONSTRUCT {" + + "?a ?c ?d" + + "}" + + "from " + + "WHERE" + + "{ " + + " ?a ?b <" + queryTemplate + ">." + + " ?a ?c ?d" + + " filter not exists {?a a }" + + "}"; + return query; + } /** * Query to retrieve workflow template steps of a WINGS template * @return diff --git a/src/main/java/edu/isi/wings/opmm/WorkflowExecutionExport.java b/src/main/java/edu/isi/wings/opmm/WorkflowExecutionExport.java index 38cf687..706d32d 100644 --- a/src/main/java/edu/isi/wings/opmm/WorkflowExecutionExport.java +++ b/src/main/java/edu/isi/wings/opmm/WorkflowExecutionExport.java @@ -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()) { @@ -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()) { @@ -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(); @@ -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(); @@ -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(); diff --git a/src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java b/src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java index 8b5d643..5622d0c 100644 --- a/src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java +++ b/src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java @@ -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; @@ -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{