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