From f45eafa3f425471a308f2dd4b0c65b7837965e87 Mon Sep 17 00:00:00 2001 From: bjl23 Date: Fri, 14 Jan 2011 16:11:10 +0000 Subject: [PATCH] NIHVIVO-1585 Gerhard's improvements to workflow processing --- .../jena/JenaIngestWorkflowProcessor.java | 59 +++++++++++++------ .../webapp/utils/jena/WorkflowOntology.java | 2 + 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestWorkflowProcessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestWorkflowProcessor.java index a18fddcc3..f907e2859 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestWorkflowProcessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestWorkflowProcessor.java @@ -67,7 +67,7 @@ public class JenaIngestWorkflowProcessor { public void run(Individual startingWorkflowStep) { for (Individual step : getWorkflowSteps(startingWorkflowStep)) { Individual action = getAction(step); - System.out.println("Executing action "+action.getURI()); + log.debug("Executing workflow action "+action.getURI()); for (ActionHandler handler : actionHandlerList) { ActionResult result = handler.handleAction(action); if (result != null) { @@ -81,7 +81,7 @@ public class JenaIngestWorkflowProcessor { * returns the Action related to the supplied WorkflowStep */ private Individual getAction(Individual stepInd) { - System.out.println("Workflow step: "+stepInd.getURI()); + log.debug("Workflow step: "+stepInd.getURI()); RDFNode actionNode = stepInd.getPropertyValue(WorkflowOntology.action); if (actionNode != null && actionNode.canAs(Individual.class)) { return (Individual) actionNode.as(Individual.class); @@ -146,9 +146,11 @@ public class JenaIngestWorkflowProcessor { * returns the model represented by the given Node, which is expected to be an Individual of type Model */ private Model getModel(RDFNode modelNode) { + if (modelNode == null) { + return null; + } Individual modelInd = (Individual) modelNode.as(Individual.class); String modelNameStr = ((Literal)modelInd.getPropertyValue(WorkflowOntology.modelName).as(Literal.class)).getLexicalForm(); - System.out.println("Trying to get model "+modelNameStr); // false = strict mode off, i.e., // if a model already exists of the given name, return it. Otherwise, create a new one. return vitroJenaModelMaker.createModel(modelNameStr,false); @@ -187,16 +189,27 @@ public class JenaIngestWorkflowProcessor { Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel)); Model modelToAdd = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToAdd)); Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); + Boolean applyChangesDirectlyToSource = false; + RDFNode valueNode = actionInd.getPropertyValue(WorkflowOntology.applyChangesDirectlyToSource); + if ((valueNode != null) && (valueNode.isLiteral())) { + applyChangesDirectlyToSource = ((Literal)valueNode.as(Literal.class)).getBoolean(); + } + sourceModel.enterCriticalSection(Lock.WRITE); try { modelToAdd.enterCriticalSection(Lock.READ); try { - destinationModel.enterCriticalSection(Lock.WRITE); - try{ - destinationModel.add(modelToAdd); - } finally { - destinationModel.leaveCriticalSection(); - } + if (applyChangesDirectlyToSource) { + // TODO: are all listeners notified this way? + sourceModel.add(modelToAdd); + } else { + destinationModel.enterCriticalSection(Lock.WRITE); + try{ + destinationModel.add(modelToAdd); + } finally { + destinationModel.leaveCriticalSection(); + } + } } finally { modelToAdd.leaveCriticalSection(); } @@ -216,16 +229,26 @@ public class JenaIngestWorkflowProcessor { Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel)); Model modelToSubtract = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToSubtract)); Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); + Boolean applyChangesDirectlyToSource = false; + RDFNode valueNode = actionInd.getPropertyValue(WorkflowOntology.applyChangesDirectlyToSource); + if ((valueNode != null) && (valueNode.isLiteral())) { + applyChangesDirectlyToSource = ((Literal)valueNode.as(Literal.class)).getBoolean(); + } sourceModel.enterCriticalSection(Lock.WRITE); try { modelToSubtract.enterCriticalSection(Lock.READ); try { - destinationModel.enterCriticalSection(Lock.WRITE); - try{ - destinationModel.add(sourceModel.difference(modelToSubtract)); - } finally { - destinationModel.leaveCriticalSection(); - } + if (applyChangesDirectlyToSource) { + // TODO: are all listeners notified this way? + sourceModel.remove(modelToSubtract); + } else { + destinationModel.enterCriticalSection(Lock.WRITE); + try{ + destinationModel.add(sourceModel.difference(modelToSubtract)); + } finally { + destinationModel.leaveCriticalSection(); + } + } } finally { modelToSubtract.leaveCriticalSection(); } @@ -247,18 +270,18 @@ public class JenaIngestWorkflowProcessor { if (instanceOf(actionInd,WorkflowOntology.SPARQLCONSTRUCTAction)) { OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); for (RDFNode node : (List) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { - System.out.println("SPARQL: adding submodel "); + log.debug("SPARQL: adding submodel "); sourceModel.addSubModel(getModel(node)); } if (actionInd.getPropertyValue(WorkflowOntology.destinationModel) == null) { - System.out.println("Error: destination model for SPARQL Construct action not specified for this action"); + log.debug("Error: destination model for SPARQL Construct action not specified for this action"); return null; } Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); Model tempModel = ModelFactory.createDefaultModel(); OntResource sparqlQuery = (OntResource) actionInd.getPropertyValue(WorkflowOntology.sparqlQuery); String queryStr = ((Literal)sparqlQuery.getPropertyValue(ResourceFactory.createProperty(QUERY_STR_PROPERTY))).getLexicalForm(); - System.out.println(queryStr); + log.debug("SPARQL query: \n" + queryStr); Query query = QueryFactory.create(queryStr,Syntax.syntaxARQ); QueryExecution qexec = QueryExecutionFactory.create(query,sourceModel); qexec.execConstruct(tempModel); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/WorkflowOntology.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/WorkflowOntology.java index 5bca73801..435986285 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/WorkflowOntology.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/WorkflowOntology.java @@ -82,6 +82,8 @@ public class WorkflowOntology { public static final ObjectProperty previousStep = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ns/vitro/rdfIngestWorkflow#previousStep" ); + public static final ObjectProperty addedInAction = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ns/vitro/rdfIngestWorkflow#addedInAction" ); + public static final ObjectProperty subtractedInAction = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ns/vitro/rdfIngestWorkflow#subtractedInAction" ); public static final ObjectProperty nextStep = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ns/vitro/rdfIngestWorkflow#nextStep" );