VIVO-248 Tweak some issues with file paths and Application Model init.
This commit is contained in:
parent
f2312a4067
commit
1c475a5661
2 changed files with 28 additions and 12 deletions
|
@ -82,11 +82,9 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
|
|
||||||
|
|
||||||
if (isFirstStartup()) {
|
if (isFirstStartup()) {
|
||||||
|
initializeApplicationMetadata(ctx, applicationMetadataModel);
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "abox", baseABoxModel, true);
|
RDFFilesLoader.loadFirstTimeFiles(ctx, "abox", baseABoxModel, true);
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "tbox", baseTBoxModel, true);
|
RDFFilesLoader.loadFirstTimeFiles(ctx, "tbox", baseTBoxModel, true);
|
||||||
|
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", applicationMetadataModel, true);
|
|
||||||
setPortalUriOnFirstTime(applicationMetadataModel, ctx);
|
|
||||||
} else {
|
} else {
|
||||||
checkForNamespaceMismatch( applicationMetadataModel, ctx );
|
checkForNamespaceMismatch( applicationMetadataModel, ctx );
|
||||||
}
|
}
|
||||||
|
@ -171,13 +169,27 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
|
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We need to read the RDF files and change the Portal from a blank node to
|
||||||
|
* one with a URI in the default namespace.
|
||||||
|
*
|
||||||
|
* Do this before adding the data to the RDFService-backed model, to avoid
|
||||||
|
* warnings about editing a blank node.
|
||||||
|
*/
|
||||||
|
private void initializeApplicationMetadata(ServletContext ctx,
|
||||||
|
OntModel applicationMetadataModel) {
|
||||||
|
OntModel temporaryAMModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
|
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
|
||||||
|
setPortalUriOnFirstTime(temporaryAMModel, ctx);
|
||||||
|
applicationMetadataModel.add(temporaryAMModel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we are loading the application metadata for the first time, set the
|
* If we are loading the application metadata for the first time, set the
|
||||||
* URI of the Portal based on the default namespace.
|
* URI of the Portal based on the default namespace.
|
||||||
*/
|
*/
|
||||||
private void setPortalUriOnFirstTime(OntModel model, ServletContext ctx) {
|
private void setPortalUriOnFirstTime(OntModel model, ServletContext ctx) {
|
||||||
// currently, only a single portal is permitted in the initialization
|
// Only a single portal is permitted in the initialization data
|
||||||
// data
|
|
||||||
Resource portalResource = null;
|
Resource portalResource = null;
|
||||||
ClosableIterator<Resource> portalResIt = model
|
ClosableIterator<Resource> portalResIt = model
|
||||||
.listSubjectsWithProperty(RDF.type,
|
.listSubjectsWithProperty(RDF.type,
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class RDFFilesLoader {
|
||||||
|
|
||||||
private static final String PROPERTY_VITRO_HOME = "vitro.home";
|
private static final String PROPERTY_VITRO_HOME = "vitro.home";
|
||||||
private static final String DEFAULT_RDF_FORMAT = "RDF/XML";
|
private static final String DEFAULT_RDF_FORMAT = "RDF/XML";
|
||||||
|
private static final String RDF_FILES = "rdffiles";
|
||||||
private static final String FIRST_TIME = "firsttime";
|
private static final String FIRST_TIME = "firsttime";
|
||||||
private static final String EVERY_TIME = "everytime";
|
private static final String EVERY_TIME = "everytime";
|
||||||
|
|
||||||
|
@ -63,11 +64,14 @@ public class RDFFilesLoader {
|
||||||
public static void loadFirstTimeFiles(ServletContext ctx, String modelPath,
|
public static void loadFirstTimeFiles(ServletContext ctx, String modelPath,
|
||||||
Model model, boolean firstTime) {
|
Model model, boolean firstTime) {
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
Set<Path> paths = getPaths(locateHomeDirectory(ctx), modelPath,
|
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF_FILES,
|
||||||
FIRST_TIME);
|
modelPath, FIRST_TIME);
|
||||||
for (Path p : paths) {
|
for (Path p : paths) {
|
||||||
readOntologyFileIntoModel(p, model);
|
readOntologyFileIntoModel(p, model);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Not loading first time files on '" + modelPath
|
||||||
|
+ "', firstTime=false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +87,8 @@ public class RDFFilesLoader {
|
||||||
OntModel model) {
|
OntModel model) {
|
||||||
OntModel everytimeModel = ModelFactory
|
OntModel everytimeModel = ModelFactory
|
||||||
.createOntologyModel(OntModelSpec.OWL_MEM);
|
.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
Set<Path> paths = getPaths(locateHomeDirectory(ctx), modelPath,
|
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF_FILES,
|
||||||
EVERY_TIME);
|
modelPath, EVERY_TIME);
|
||||||
for (Path p : paths) {
|
for (Path p : paths) {
|
||||||
readOntologyFileIntoModel(p, everytimeModel);
|
readOntologyFileIntoModel(p, everytimeModel);
|
||||||
}
|
}
|
||||||
|
@ -144,13 +148,13 @@ public class RDFFilesLoader {
|
||||||
|
|
||||||
private static void readOntologyFileIntoModel(Path p, Model model) {
|
private static void readOntologyFileIntoModel(Path p, Model model) {
|
||||||
String format = getRdfFormat(p);
|
String format = getRdfFormat(p);
|
||||||
log.info("Loading ontology file at " + p + " as format " + format);
|
log.info("Loading file at " + p + " as " + format);
|
||||||
try (InputStream stream = new FileInputStream(p.toFile())) {
|
try (InputStream stream = new FileInputStream(p.toFile())) {
|
||||||
model.read(stream, null, format);
|
model.read(stream, null, format);
|
||||||
log.debug("...successful");
|
log.debug("...successful");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Could not load RDF file '" + p
|
log.warn("Could not load file '" + p + "' as " + format
|
||||||
+ "'. Check that it contains valid " + format + " data.", e);
|
+ ". Check that it contains valid data.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue