Skip to content

Commit

Permalink
Merge pull request #659 from ontodev/658-fix
Browse files Browse the repository at this point in the history
Ignore TDBFactory.release Exceptions
  • Loading branch information
jamesaoverton authored Apr 6, 2020
2 parents e292856 + 6dbf27b commit d176933
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fix filtering axioms with multiple axiom selectors [#644]
- Fix comparator method for sorting empty strings with [`export`] in [#654]
- Fix releasing dataset after exception when running [`report`] with `--tdb true` [#659]

## [1.6.0] - 2020-03-04

Expand Down Expand Up @@ -181,6 +182,7 @@ First official release of ROBOT!
[`report`]: http://robot.obolibrary.org/report
[`template`]: http://robot.obolibrary.org/template

[#659]: https://github.com/ontodev/robot/issues/659
[#657]: https://github.com/ontodev/robot/pull/657
[#654]: https://github.com/ontodev/robot/issues/654
[#646]: https://github.com/ontodev/robot/issues/646
Expand Down
35 changes: 23 additions & 12 deletions robot-core/src/main/java/org/obolibrary/robot/ReportOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.jena.query.*;
import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.tdb.transaction.TDBTransactionException;
import org.obolibrary.robot.checks.Report;
import org.obolibrary.robot.checks.Violation;
import org.semanticweb.owlapi.model.IRI;
Expand Down Expand Up @@ -338,7 +339,12 @@ public static Report getTDBReport(String inputPath, Map<String, String> options)
} finally {
// Close and release
dataset.close();
TDBFactory.release(dataset);
try {
TDBFactory.release(dataset);
} catch (TDBTransactionException e) {
// Do nothing - already released
}

if (!keepMappings) {
// Maybe delete
boolean success = IOHelper.cleanTDB(tdbDir);
Expand Down Expand Up @@ -371,27 +377,32 @@ public static Report getTDBReport(Dataset dataset, Map<String, String> options)

String profilePath = OptionsHelper.getOption(options, "profile", null);

// The profile is a map of rule name and reporting level
Map<String, String> profile = getProfile(profilePath);
// The queries is a map of rule name and query string
Map<String, String> queries = getQueryStrings(profile.keySet());

boolean useLabels = OptionsHelper.optionIsTrue(options, "labels");
Map<IRI, String> labelMap = null;
if (useLabels) {
labelMap = new HashMap<>();
// Run query over dataset to retrive all labels
String query =
"SELECT ?s ?label WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label }";
ResultSet labelResults = QueryOperation.execQuery(dataset, query);
while (labelResults.hasNext()) {
QuerySolution qs = labelResults.next();
IRI iri = IRI.create(qs.getResource("s").getURI());
String label = qs.getLiteral("label").getString();
labelMap.put(iri, label);
dataset.begin(ReadWrite.READ);
try {
ResultSet labelResults = QueryOperation.execQuery(dataset, query);
while (labelResults.hasNext()) {
QuerySolution qs = labelResults.next();
IRI iri = IRI.create(qs.getResource("s").getURI());
String label = qs.getLiteral("label").getString();
labelMap.put(iri, label);
}
} finally {
dataset.end();
}
}

// The profile is a map of rule name and reporting level
Map<String, String> profile = getProfile(profilePath);
// The queries is a map of rule name and query string
Map<String, String> queries = getQueryStrings(profile.keySet());

// Create the report object (maybe using labels)
Report report = new Report(labelMap);

Expand Down

0 comments on commit d176933

Please sign in to comment.