VIVO-248 Tweak some issues with file paths and Application Model init.

This commit is contained in:
j2blake 2013-08-21 15:08:48 -04:00
parent f2312a4067
commit 1c475a5661
2 changed files with 28 additions and 12 deletions

View file

@ -82,11 +82,9 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
if (isFirstStartup()) {
initializeApplicationMetadata(ctx, applicationMetadataModel);
RDFFilesLoader.loadFirstTimeFiles(ctx, "abox", baseABoxModel, true);
RDFFilesLoader.loadFirstTimeFiles(ctx, "tbox", baseTBoxModel, true);
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", applicationMetadataModel, true);
setPortalUriOnFirstTime(applicationMetadataModel, ctx);
} else {
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
* URI of the Portal based on the default namespace.
*/
private void setPortalUriOnFirstTime(OntModel model, ServletContext ctx) {
// currently, only a single portal is permitted in the initialization
// data
// Only a single portal is permitted in the initialization data
Resource portalResource = null;
ClosableIterator<Resource> portalResIt = model
.listSubjectsWithProperty(RDF.type,

View file

@ -33,6 +33,7 @@ public class RDFFilesLoader {
private static final String PROPERTY_VITRO_HOME = "vitro.home";
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 EVERY_TIME = "everytime";
@ -63,11 +64,14 @@ public class RDFFilesLoader {
public static void loadFirstTimeFiles(ServletContext ctx, String modelPath,
Model model, boolean firstTime) {
if (firstTime) {
Set<Path> paths = getPaths(locateHomeDirectory(ctx), modelPath,
FIRST_TIME);
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF_FILES,
modelPath, FIRST_TIME);
for (Path p : paths) {
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 everytimeModel = ModelFactory
.createOntologyModel(OntModelSpec.OWL_MEM);
Set<Path> paths = getPaths(locateHomeDirectory(ctx), modelPath,
EVERY_TIME);
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF_FILES,
modelPath, EVERY_TIME);
for (Path p : paths) {
readOntologyFileIntoModel(p, everytimeModel);
}
@ -144,13 +148,13 @@ public class RDFFilesLoader {
private static void readOntologyFileIntoModel(Path p, Model model) {
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())) {
model.read(stream, null, format);
log.debug("...successful");
} catch (Exception e) {
log.warn("Could not load RDF file '" + p
+ "'. Check that it contains valid " + format + " data.", e);
log.warn("Could not load file '" + p + "' as " + format
+ ". Check that it contains valid data.", e);
}
}