NIHVIVO-1585 Gerhard's improvements to workflow processing

This commit is contained in:
bjl23 2011-01-14 16:11:10 +00:00
parent eae3203b45
commit f45eafa3f4
2 changed files with 43 additions and 18 deletions

View file

@ -67,7 +67,7 @@ public class JenaIngestWorkflowProcessor {
public void run(Individual startingWorkflowStep) { public void run(Individual startingWorkflowStep) {
for (Individual step : getWorkflowSteps(startingWorkflowStep)) { for (Individual step : getWorkflowSteps(startingWorkflowStep)) {
Individual action = getAction(step); Individual action = getAction(step);
System.out.println("Executing action "+action.getURI()); log.debug("Executing workflow action "+action.getURI());
for (ActionHandler handler : actionHandlerList) { for (ActionHandler handler : actionHandlerList) {
ActionResult result = handler.handleAction(action); ActionResult result = handler.handleAction(action);
if (result != null) { if (result != null) {
@ -81,7 +81,7 @@ public class JenaIngestWorkflowProcessor {
* returns the Action related to the supplied WorkflowStep * returns the Action related to the supplied WorkflowStep
*/ */
private Individual getAction(Individual stepInd) { private Individual getAction(Individual stepInd) {
System.out.println("Workflow step: "+stepInd.getURI()); log.debug("Workflow step: "+stepInd.getURI());
RDFNode actionNode = stepInd.getPropertyValue(WorkflowOntology.action); RDFNode actionNode = stepInd.getPropertyValue(WorkflowOntology.action);
if (actionNode != null && actionNode.canAs(Individual.class)) { if (actionNode != null && actionNode.canAs(Individual.class)) {
return (Individual) actionNode.as(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 * returns the model represented by the given Node, which is expected to be an Individual of type Model
*/ */
private Model getModel(RDFNode modelNode) { private Model getModel(RDFNode modelNode) {
if (modelNode == null) {
return null;
}
Individual modelInd = (Individual) modelNode.as(Individual.class); Individual modelInd = (Individual) modelNode.as(Individual.class);
String modelNameStr = ((Literal)modelInd.getPropertyValue(WorkflowOntology.modelName).as(Literal.class)).getLexicalForm(); 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., // false = strict mode off, i.e.,
// if a model already exists of the given name, return it. Otherwise, create a new one. // if a model already exists of the given name, return it. Otherwise, create a new one.
return vitroJenaModelMaker.createModel(modelNameStr,false); return vitroJenaModelMaker.createModel(modelNameStr,false);
@ -187,16 +189,27 @@ public class JenaIngestWorkflowProcessor {
Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel)); Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel));
Model modelToAdd = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToAdd)); Model modelToAdd = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToAdd));
Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); 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); sourceModel.enterCriticalSection(Lock.WRITE);
try { try {
modelToAdd.enterCriticalSection(Lock.READ); modelToAdd.enterCriticalSection(Lock.READ);
try { try {
if (applyChangesDirectlyToSource) {
// TODO: are all listeners notified this way?
sourceModel.add(modelToAdd);
} else {
destinationModel.enterCriticalSection(Lock.WRITE); destinationModel.enterCriticalSection(Lock.WRITE);
try{ try{
destinationModel.add(modelToAdd); destinationModel.add(modelToAdd);
} finally { } finally {
destinationModel.leaveCriticalSection(); destinationModel.leaveCriticalSection();
} }
}
} finally { } finally {
modelToAdd.leaveCriticalSection(); modelToAdd.leaveCriticalSection();
} }
@ -216,16 +229,26 @@ public class JenaIngestWorkflowProcessor {
Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel)); Model sourceModel = getModel(actionInd.getPropertyValue(WorkflowOntology.sourceModel));
Model modelToSubtract = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToSubtract)); Model modelToSubtract = getModel(actionInd.getPropertyValue(WorkflowOntology.modelToSubtract));
Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); 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); sourceModel.enterCriticalSection(Lock.WRITE);
try { try {
modelToSubtract.enterCriticalSection(Lock.READ); modelToSubtract.enterCriticalSection(Lock.READ);
try { try {
if (applyChangesDirectlyToSource) {
// TODO: are all listeners notified this way?
sourceModel.remove(modelToSubtract);
} else {
destinationModel.enterCriticalSection(Lock.WRITE); destinationModel.enterCriticalSection(Lock.WRITE);
try{ try{
destinationModel.add(sourceModel.difference(modelToSubtract)); destinationModel.add(sourceModel.difference(modelToSubtract));
} finally { } finally {
destinationModel.leaveCriticalSection(); destinationModel.leaveCriticalSection();
} }
}
} finally { } finally {
modelToSubtract.leaveCriticalSection(); modelToSubtract.leaveCriticalSection();
} }
@ -247,18 +270,18 @@ public class JenaIngestWorkflowProcessor {
if (instanceOf(actionInd,WorkflowOntology.SPARQLCONSTRUCTAction)) { if (instanceOf(actionInd,WorkflowOntology.SPARQLCONSTRUCTAction)) {
OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) {
System.out.println("SPARQL: adding submodel "); log.debug("SPARQL: adding submodel ");
sourceModel.addSubModel(getModel(node)); sourceModel.addSubModel(getModel(node));
} }
if (actionInd.getPropertyValue(WorkflowOntology.destinationModel) == null) { 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; return null;
} }
Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel));
Model tempModel = ModelFactory.createDefaultModel(); Model tempModel = ModelFactory.createDefaultModel();
OntResource sparqlQuery = (OntResource) actionInd.getPropertyValue(WorkflowOntology.sparqlQuery); OntResource sparqlQuery = (OntResource) actionInd.getPropertyValue(WorkflowOntology.sparqlQuery);
String queryStr = ((Literal)sparqlQuery.getPropertyValue(ResourceFactory.createProperty(QUERY_STR_PROPERTY))).getLexicalForm(); 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); Query query = QueryFactory.create(queryStr,Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query,sourceModel); QueryExecution qexec = QueryExecutionFactory.create(query,sourceModel);
qexec.execConstruct(tempModel); qexec.execConstruct(tempModel);

View file

@ -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 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 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" ); public static final ObjectProperty nextStep = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ns/vitro/rdfIngestWorkflow#nextStep" );