Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore TDBFactory.release Exceptions #659

Merged
merged 3 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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