fix for NIHVIVO-2043 can't start in SDB mode with empty DB
This commit is contained in:
parent
5a896aad34
commit
2e9cd79352
4 changed files with 67 additions and 17 deletions
|
@ -9,9 +9,7 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -284,20 +282,34 @@ public class KnowledgeBaseUpdater {
|
|||
*/
|
||||
public boolean updateRequired() throws IOException {
|
||||
|
||||
boolean required = false;
|
||||
|
||||
String sparqlQueryStr = loadSparqlQuery(settings.getAskQueryFile());
|
||||
if (sparqlQueryStr == null) {
|
||||
return false;
|
||||
return required;
|
||||
}
|
||||
|
||||
Model m = settings.getOntModelSelector().getApplicationMetadataModel();
|
||||
Query query = QueryFactory.create(sparqlQueryStr);
|
||||
QueryExecution qexec = QueryExecutionFactory.create(query, m);
|
||||
QueryExecution isUpdated = QueryExecutionFactory.create(query, m);
|
||||
|
||||
// if the ASK query DOES have a solution (i.e. the assertions exist
|
||||
// showing that the update has already been performed), then the update
|
||||
// is NOT required.
|
||||
return !qexec.execAsk();
|
||||
|
||||
if (isUpdated.execAsk()) {
|
||||
required = false;
|
||||
} else {
|
||||
required = true;
|
||||
String sparqlQueryStr2 = loadSparqlQuery(settings.getAskEmptyQueryFile());
|
||||
if (sparqlQueryStr2 != null) {
|
||||
Query query2 = QueryFactory.create(sparqlQueryStr2);
|
||||
QueryExecution isNotEmpty = QueryExecutionFactory.create(query2, m);
|
||||
required = isNotEmpty.execAsk();
|
||||
}
|
||||
}
|
||||
|
||||
return required;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -306,6 +318,7 @@ public class KnowledgeBaseUpdater {
|
|||
* @return the query string or null if file not found
|
||||
*/
|
||||
public static String loadSparqlQuery(String filePath) throws IOException {
|
||||
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
|
@ -401,8 +414,5 @@ public class KnowledgeBaseUpdater {
|
|||
public List<AtomicOntologyChange> getAtomicPropertyChanges() {
|
||||
return atomicPropertyChanges;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ public class UpdateSettings {
|
|||
private String sparqlConstructAdditionsPass2Dir;
|
||||
private String sparqlConstructDeletionsDir;
|
||||
private String askQueryFile;
|
||||
private String askEmptyQueryFile;
|
||||
private String askEverQueryFile;
|
||||
private String successAssertionsFile;
|
||||
private String successRDFFormat = "N3";
|
||||
private String diffFile;
|
||||
|
@ -57,6 +59,18 @@ public class UpdateSettings {
|
|||
public void setAskQueryFile(String askQueryFile) {
|
||||
this.askQueryFile = askQueryFile;
|
||||
}
|
||||
public String getAskEverQueryFile() {
|
||||
return askEverQueryFile;
|
||||
}
|
||||
public void setAskEverQueryFile(String askEverQueryFile) {
|
||||
this.askEverQueryFile = askEverQueryFile;
|
||||
}
|
||||
public String getAskEmptyQueryFile() {
|
||||
return askEmptyQueryFile;
|
||||
}
|
||||
public void setAskEmptyQueryFile(String askEmptyQueryFile) {
|
||||
this.askEmptyQueryFile = askEmptyQueryFile;
|
||||
}
|
||||
public String getSuccessAssertionsFile() {
|
||||
return successAssertionsFile;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
|||
// that it is not executed in a post-sdb-conversion environment.
|
||||
OntModel memModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
||||
|
||||
//memModel.writeAll(System.out,"N3",null);
|
||||
|
||||
if ( updateRequired(sce.getServletContext(), memModel)) {
|
||||
log.error(getMigrationErrString());
|
||||
System.out.println(getMigrationErrString());
|
||||
|
@ -664,21 +666,34 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
|||
*/
|
||||
public boolean updateRequired(ServletContext ctx, OntModel m) throws IOException {
|
||||
|
||||
boolean required = false;
|
||||
|
||||
String sparqlQueryStr = KnowledgeBaseUpdater.loadSparqlQuery(UpdateKnowledgeBase.getAskQueryPath(ctx));
|
||||
if (sparqlQueryStr == null) {
|
||||
return false;
|
||||
return required;
|
||||
}
|
||||
|
||||
Query query = QueryFactory.create(sparqlQueryStr);
|
||||
QueryExecution qexec = QueryExecutionFactory.create(query, m);
|
||||
QueryExecution isUpdated = QueryExecutionFactory.create(query, m);
|
||||
|
||||
// if the ASK query DOES have a solution (i.e. the assertions exist
|
||||
// showing that the update has already been performed), then the update
|
||||
// is NOT required.
|
||||
return !qexec.execAsk();
|
||||
|
||||
if (isUpdated.execAsk()) {
|
||||
required = false;
|
||||
} else {
|
||||
required = true;
|
||||
String sparqlQueryStr2 = KnowledgeBaseUpdater.loadSparqlQuery(UpdateKnowledgeBase.getAskEmptyQueryPath(ctx));
|
||||
if (sparqlQueryStr2 != null) {
|
||||
Query query2 = QueryFactory.create(sparqlQueryStr2);
|
||||
QueryExecution isNotEmpty = QueryExecutionFactory.create(query2, m);
|
||||
required = isNotEmpty.execAsk();
|
||||
}
|
||||
}
|
||||
|
||||
return required;
|
||||
}
|
||||
|
||||
private String getMigrationErrString() {
|
||||
String errMessage = "\n*******************************************************************";
|
||||
errMessage += "\nA knowledge base migration is " +
|
||||
|
|
|
@ -47,6 +47,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
private static final String LOG_DIR = "logs/";
|
||||
private static final String CHANGED_DATA_DIR = "changedData/";
|
||||
private static final String ASK_QUERY_FILE = DATA_DIR + "ask.sparql";
|
||||
private static final String ASK_EMPTY_QUERY_FILE = DATA_DIR + "askEmpty.sparql";
|
||||
private static final String ASK_EVER_QUERY_FILE = DATA_DIR + "askEver.sparql";
|
||||
private static final String SUCCESS_ASSERTIONS_FILE = DATA_DIR + "success.n3";
|
||||
private static final String SUCCESS_RDF_FORMAT = "N3";
|
||||
private static final String DIFF_FILE = DATA_DIR + "diff.tab.txt";
|
||||
|
@ -77,6 +79,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
|
||||
UpdateSettings settings = new UpdateSettings();
|
||||
settings.setAskQueryFile(getAskQueryPath(ctx));
|
||||
settings.setAskEverQueryFile(getAskEverQueryPath(ctx));
|
||||
settings.setAskEmptyQueryFile(getAskEmptyQueryPath(ctx));
|
||||
settings.setDataDir(ctx.getRealPath(DATA_DIR));
|
||||
settings.setSparqlConstructAdditionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_DIR));
|
||||
settings.setSparqlConstructAdditionsPass2Dir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_PASS2_DIR));
|
||||
|
@ -235,9 +239,16 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
public void contextDestroyed(ServletContextEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public static String getAskQueryPath(ServletContext ctx) {
|
||||
return ctx.getRealPath(ASK_QUERY_FILE);
|
||||
|
||||
}
|
||||
public static String getAskEverQueryPath(ServletContext ctx) {
|
||||
return ctx.getRealPath(ASK_EVER_QUERY_FILE);
|
||||
|
||||
}
|
||||
public static String getAskEmptyQueryPath(ServletContext ctx) {
|
||||
return ctx.getRealPath(ASK_EMPTY_QUERY_FILE);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue