in taverna-provenanceconnector/src/main/java/org/apache/taverna/provenance/opm/OPMImporter.java [122:245]
public void importGraph(String XMLOPMGraphFilename) throws Exception,
SQLException {
try {
logger.info("Importing OPM XML from file " + XMLOPMGraphFilename);
// deserialize an XML OPM graph from file
OPMDeserialiser deser = new OPMDeserialiser();
graph = deser.deserialiseOPMGraph(new File(XMLOPMGraphFilename));
} catch (Exception e) {
logger.fatal("exception while deserializing -- unable to continue");
logger.fatal(e.getMessage());
return;
}
logger.debug("XML graph deserialized");
/*
* generates one pair <workflowId, workflowRun> for each account in the
* graph
*/
try {
Accounts accounts = graph.getAccounts();
// use this global account alongside any other that may be defined in the graph
generateWFFromAccount(OPM_DEF_ACCOUNT);
if (accounts == null) {
logger.warn("this graph contains no accounts -- using only the default");
} else {
for (Account acc:accounts.getAccount())
// writes both workflow and instance into the DB, updates accountToWorkflow
generateWFFromAccount(acc.getId());
}
} catch (Exception e) {
logger.warn("exception while getting accounts for this graph");
}
// what have we got?
// retrieve all OPM relations from the graph
Dependencies dependencies = graph.getDependencies();
/*
* associates processes and ports to workflows and varbindings to
* corresponding workflowRuns
*/
List<Object> allDeps = dependencies
.getUsedOrWasGeneratedByOrWasTriggeredBy();
// make sure these are processed in the right order: used, wgby, THEN wdf because this latter is derived from the first 2!
// so collect them into sets and process them separately
Set<WasGeneratedBy> wgbSet = new HashSet<>();
Set<Used> usedSet = new HashSet<>();
Set<WasDerivedFrom> wdfSet = new HashSet<>();
Set<WasControlledBy> wcbSet = new HashSet<>();
Set<WasTriggeredBy> wtbSet = new HashSet<>();
for (Object dep : allDeps) {
logger.info("dependency of type: " + dep.getClass().getName());
if (dep instanceof org.openprovenance.model.WasGeneratedBy)
wgbSet.add((WasGeneratedBy) dep);
else if (dep instanceof org.openprovenance.model.Used)
usedSet.add((Used) dep);
else if (dep instanceof org.openprovenance.model.WasDerivedFrom)
wdfSet.add((WasDerivedFrom) dep);
else if (dep instanceof org.openprovenance.model.WasControlledBy)
wcbSet.add((WasControlledBy) dep);
else if (dep instanceof org.openprovenance.model.WasTriggeredBy)
wtbSet.add((WasTriggeredBy) dep);
}
// process these in the correct order
for (WasGeneratedBy dep: wgbSet)
processWGBy(dep);
for (Used dep : usedSet)
processUsed(dep);
for (WasDerivedFrom dep : wdfSet)
processWDF(dep);
// we actually ignore the others...
// *********
// complete the induced graph by building datalinks using the Artifact -> [Port] maps
// *********
List<String> accountNames = new ArrayList<>();
accountNames.add(OPM_DEF_ACCOUNT);
/* Disabled as allAccounts is never assigned to
if (allAccounts != null)
for (Account acc:allAccounts) { accountNames.add(acc.getId()); }
*/
for (String acc : accountNames) {
String workflowId = accountToWorkflow.get(acc);
Map<String, List<Port>> usedVars = usedVarsByAccount
.get(workflowId);
Map<String, List<Port>> wgbVars = wgbVarsByAccount.get(workflowId);
if (usedVars == null || wgbVars == null)
continue;
// install an Datalink from each wgb var to each used var when the artifact is the same
for (Map.Entry<String, List<Port>> entry : wgbVars.entrySet()) {
// all Ports for this artifact get connected to all corresponding Ports in used
List<Port> sourceVars = entry.getValue();
List<Port> targetVars = usedVars.get(entry.getKey());
if (sourceVars == null || targetVars == null)
continue;
// create an datalink from each sourceVar to each targetVar
// note that we expect a single targetVar, but this is not guaranteed
for (Port sourceVar : sourceVars)
for (Port targetVar : targetVars)
pw.addDataLink(sourceVar, targetVar, workflowId);
}
}
}