improvements for NIHVIVO-205 ontology upgrade
This commit is contained in:
parent
cbb889c818
commit
03a2a13a37
4 changed files with 24 additions and 12 deletions
|
@ -12,4 +12,6 @@ public interface OntologyChangeLogger {
|
|||
|
||||
public void closeLogs() throws IOException;
|
||||
|
||||
public boolean errorsWritten();
|
||||
|
||||
}
|
||||
|
|
|
@ -63,9 +63,15 @@ public class OntologyUpdater {
|
|||
// Check to see if the update is necessary.
|
||||
if (updateRequired()) {
|
||||
performUpdate();
|
||||
// add assertions to the knowledge base showing that the
|
||||
// update was successful, so we don't need to run it again.
|
||||
assertSuccess();
|
||||
|
||||
if (!logger.errorsWritten()) {
|
||||
// add assertions to the knowledge base showing that the
|
||||
// update was successful, so we don't need to run it again.
|
||||
// TODO improve error handling in future version.
|
||||
assertSuccess();
|
||||
}
|
||||
|
||||
logger.closeLogs();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +94,6 @@ public class OntologyUpdater {
|
|||
|
||||
updateTBoxAnnotations();
|
||||
|
||||
logger.closeLogs();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,7 +229,7 @@ public class OntologyUpdater {
|
|||
return fileContents.toString();
|
||||
}
|
||||
|
||||
private void assertSuccess() throws FileNotFoundException {
|
||||
private void assertSuccess() throws FileNotFoundException, IOException {
|
||||
try {
|
||||
Model m = settings.getOntModelSelector().getApplicationMetadataModel();
|
||||
File successAssertionsFile =
|
||||
|
@ -232,19 +237,17 @@ public class OntologyUpdater {
|
|||
InputStream inStream = new FileInputStream(successAssertionsFile);
|
||||
m.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
m.read(inStream, settings.getSuccessRDFFormat());
|
||||
m.read(inStream, null, settings.getSuccessRDFFormat());
|
||||
logger.log(" finished without errors.");
|
||||
} finally {
|
||||
m.leaveCriticalSection();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: log something to the error log
|
||||
logger.logError(" unable to make RDF assertions about successful " +
|
||||
" update to new ontology version: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String log) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class that allows to access two different ontology change lists,
|
||||
* one for class changes and the other for property changes. The
|
||||
|
|
|
@ -13,6 +13,8 @@ public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
|
|||
private Writer logWriter;
|
||||
private Writer errorWriter;
|
||||
|
||||
private boolean errorsWritten = false;
|
||||
|
||||
public SimpleOntologyChangeLogger( String logPath,
|
||||
String errorPath ) {
|
||||
File logFile = new File(logPath);
|
||||
|
@ -40,6 +42,7 @@ public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
|
|||
|
||||
public void logError(String errorMessage) throws IOException {
|
||||
|
||||
errorsWritten = true;
|
||||
Exception e = new Exception();
|
||||
StackTraceElement[] elements = e.getStackTrace();
|
||||
String className = ((StackTraceElement)elements[1]).getClassName();
|
||||
|
@ -57,4 +60,8 @@ public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
|
|||
errorWriter.flush();
|
||||
errorWriter.close();
|
||||
}
|
||||
|
||||
public boolean errorsWritten() {
|
||||
return errorsWritten;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
|
||||
settings.setSuccessAssertionsFile(
|
||||
ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
|
||||
settings.setSuccessRDFFormat(ctx.getRealPath(SUCCESS_RDF_FORMAT));
|
||||
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
|
||||
settings.setLogFile(ctx.getRealPath(LOG_FILE));
|
||||
settings.setErrorLogFile(ctx.getRealPath(ERROR_LOG_FILE));
|
||||
settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE));
|
||||
|
|
Loading…
Add table
Reference in a new issue