Merge branch 'develop' into feature/fauxEditing

This commit is contained in:
Jim Blake 2014-11-18 11:56:52 -05:00
commit ef6f92539f
113 changed files with 1463 additions and 9883 deletions

View file

@ -269,6 +269,12 @@
<include name="example.developer.properties" />
</fileset>
</copy>
<mkdir dir="${vitrohome.image.dir}/config" />
<copy todir="${vitrohome.image.dir}/config" >
<fileset dir="${appbase.dir}/config" >
<include name="applicationSetup.n3" />
</fileset>
</copy>
<copy todir="${vitrohome.image.dir}" >
<fileset dir="${appbase.dir}" >
<include name="rdf/**/*" />

View file

@ -859,6 +859,7 @@ local_name = Nombre local
group_capitalized = Grupo
domain_class = Clase de dominio
range_class = Clase Rango
range_data_type = Tipo de datos de gama
sub_properties = Subpropiedades
subproperty = subpropiedad

View file

@ -0,0 +1,57 @@
@prefix : <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#
# Specify the SearchIndexExcluders and DocumentModifiers.
#
# Exclude from the search index Individuals with types from these namespaces.
# Note: if you do OWL.NS here you will exclude all of owl:Thing.
:searchExcluder_namespaceExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnNamespace> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> ;
:excludes
"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" ,
"http://vitro.mannlib.cornell.edu/ns/vitro/public#" ,
"http://vitro.mannlib.cornell.edu/ns/bnode#" ,
"http://www.w3.org/2002/07/owl#" .
# Individuals of these types will be excluded from the search index
:searchExcluder_typeExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnType> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> ;
:excludes
"http://www.w3.org/2002/07/owl#AnnotationProperty" ,
"http://www.w3.org/2002/07/owl#DatatypeProperty" ,
"http://www.w3.org/2002/07/owl#ObjectProperty" .
# Exclude from the search index individuals who's URIs start with these namespaces.
:searchExcluder_typeNamespaceExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnTypeNamespace> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> ;
:excludes
"http://vitro.mannlib.cornell.edu/ns/vitro/role#public" .
:searchExcluder_vitroExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeNonFlagVitro> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> .
:searchExcluder_syncingTypeExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SyncingExcludeBasedOnType> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> .
# ------------------------------------
:documentModifier_nameFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:documentModifier_nameBoost
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameBoost> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> ;
:hasBoost "1.2"^^xsd:float .
:documentModifier_thumbnailImageUrl
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .

View file

@ -2,21 +2,28 @@
package edu.cornell.mannlib.vitro.webapp.application;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.filestorage.impl.FileStorageImplWrapper;
import edu.cornell.mannlib.vitro.webapp.imageprocessor.jai.JaiImageProcessor;
import com.hp.hpl.jena.ontology.OntDocumentManager;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.fileStorage.FileStorage;
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.searchengine.InstrumentedSearchEngineWrapper;
import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.startup.ComponentStartupStatusImpl;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/**
* The basic implementation of the Application interface.
@ -26,12 +33,16 @@ public class ApplicationImpl implements Application {
// The instance
// ----------------------------------------------------------------------
private final ServletContext ctx;
private ServletContext ctx;
private VitroHomeDirectory homeDirectory;
private SearchEngine searchEngine;
private ImageProcessor imageProcessor;
private FileStorage fileStorage;
private ContentTripleSource contentTripleSource;
private ConfigurationTripleSource configurationTripleSource;
public ApplicationImpl(ServletContext ctx) {
public void setServletContext(ServletContext ctx) {
this.ctx = ctx;
}
@ -40,13 +51,29 @@ public class ApplicationImpl implements Application {
return ctx;
}
@Override
public VitroHomeDirectory getHomeDirectory() {
return homeDirectory;
}
public void setHomeDirectory(VitroHomeDirectory homeDirectory) {
this.homeDirectory = homeDirectory;
}
@Override
public SearchEngine getSearchEngine() {
return searchEngine;
}
public void setSearchEngine(SearchEngine searchEngine) {
this.searchEngine = searchEngine;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSearchEngine")
public void setSearchEngine(SearchEngine se) {
if (searchEngine == null) {
searchEngine = se;
} else {
throw new IllegalStateException(
"Configuration includes multiple SearchEngine instancess: "
+ searchEngine + ", and " + se);
}
}
@Override
@ -54,8 +81,15 @@ public class ApplicationImpl implements Application {
return imageProcessor;
}
public void setImageProcessor(ImageProcessor imageProcessor) {
this.imageProcessor = imageProcessor;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasImageProcessor")
public void setImageProcessor(ImageProcessor ip) {
if (imageProcessor == null) {
imageProcessor = ip;
} else {
throw new IllegalStateException(
"Configuration includes multiple ImageProcessor instancess: "
+ imageProcessor + ", and " + ip);
}
}
@Override
@ -63,57 +97,151 @@ public class ApplicationImpl implements Application {
return fileStorage;
}
public void setFileStorage(FileStorage fileStorage) {
this.fileStorage = fileStorage;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasFileStorage")
public void setFileStorage(FileStorage fs) {
if (fileStorage == null) {
fileStorage = fs;
} else {
throw new IllegalStateException(
"Configuration includes multiple FileStorage intances: "
+ fileStorage + ", and " + fs);
}
}
@Override
public ContentTripleSource getContentTripleSource() {
return contentTripleSource;
}
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasContentTripleSource")
public void setContentTripleSource(ContentTripleSource source) {
if (contentTripleSource == null) {
contentTripleSource = source;
} else {
throw new IllegalStateException(
"Configuration includes multiple intances of ContentTripleSource: "
+ contentTripleSource + ", and " + source);
}
}
@Override
public ConfigurationTripleSource getConfigurationTripleSource() {
return configurationTripleSource;
}
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasConfigurationTripleSource")
public void setConfigurationTripleSource(ConfigurationTripleSource source) {
if (configurationTripleSource == null) {
configurationTripleSource = source;
} else {
throw new IllegalStateException(
"Configuration includes multiple intances of ConfigurationTripleSource: "
+ configurationTripleSource + ", and " + source);
}
}
@Validation
public void validate() throws Exception {
if (searchEngine == null) {
throw new IllegalStateException(
"Configuration did not include a SearchEngine.");
}
if (imageProcessor == null) {
throw new IllegalStateException(
"Configuration did not include an ImageProcessor.");
}
if (fileStorage == null) {
throw new IllegalStateException(
"Configuration did not include a FileStorage.");
}
if (contentTripleSource == null) {
throw new IllegalStateException(
"Configuration did not include a ContentTripleSource.");
}
if (configurationTripleSource == null) {
throw new IllegalStateException(
"Configuration did not include a ConfigurationTripleSource.");
}
}
@Override
public void shutdown() {
getFileStorage().shutdown(this);
getImageProcessor().shutdown(this);
getSearchEngine().shutdown(this);
}
// ----------------------------------------------------------------------
// The Setup class.
// Setup the major components.
//
// This must happen after the ConfigurationProperties and some other stuff.
// ----------------------------------------------------------------------
public static class Setup implements ServletContextListener {
private ApplicationImpl application;
public static class ComponentsSetup implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
Application app = ApplicationUtils.instance();
StartupStatus ss = StartupStatus.getBean(ctx);
ComponentStartupStatus css = new ComponentStartupStatusImpl(this,
ss);
try {
application = new ApplicationImpl(ctx);
ComponentStartupStatus css = new ComponentStartupStatusImpl(
this, ss);
SearchEngine searchEngine = app.getSearchEngine();
searchEngine.startup(app, css);
ss.info(this, "Started the SearchEngine: " + searchEngine);
SearchEngine searchEngine = new InstrumentedSearchEngineWrapper(
new SolrSearchEngine());
searchEngine.startup(application, css);
application.setSearchEngine(searchEngine);
ss.info(this, "Started the searchEngine: " + searchEngine);
ImageProcessor imageProcessor = app.getImageProcessor();
imageProcessor.startup(app, css);
ss.info(this, "Started the ImageProcessor: " + imageProcessor);
ImageProcessor imageProcessor = new JaiImageProcessor();
imageProcessor.startup(application, css);
application.setImageProcessor(imageProcessor);
ss.info(this, "Started the ImageProcessor: " + searchEngine);
FileStorage fileStorage = app.getFileStorage();
fileStorage.startup(app, css);
ss.info(this, "Started the FileStorage system: " + fileStorage);
FileStorage fileStorage = new FileStorageImplWrapper();
fileStorage.startup(application, css);
application.setFileStorage(fileStorage);
ss.info(this, "Started the FileStorage system: " + searchEngine);
ContentTripleSource contentTripleSource = app
.getContentTripleSource();
contentTripleSource.startup(app, css);
ss.info(this, "Started the ContentTripleSource: "
+ contentTripleSource);
ApplicationUtils.setInstance(application);
ss.info(this, "Appliation is configured.");
} catch (Exception e) {
ss.fatal(this, "Failed to initialize the Application.", e);
}
ConfigurationTripleSource configurationTripleSource = app
.getConfigurationTripleSource();
configurationTripleSource.startup(app, css);
ss.info(this, "Started the ConfigurationTripleSource: "
+ configurationTripleSource);
configureJena();
prepareCombinedTripleSource(app, ctx);
}
private void configureJena() {
// we do not want to fetch imports when we wrap Models in OntModels
OntDocumentManager.getInstance().setProcessImports(false);
}
private void prepareCombinedTripleSource(Application app,
ServletContext ctx) {
ContentTripleSource contentSource = app.getContentTripleSource();
ConfigurationTripleSource configurationSource = app
.getConfigurationTripleSource();
BasicCombinedTripleSource source = new BasicCombinedTripleSource(
contentSource, configurationSource);
RDFServiceUtils.setRDFServiceFactory(ctx,
contentSource.getRDFServiceFactory());
RDFServiceUtils.setRDFServiceFactory(ctx,
configurationSource.getRDFServiceFactory(), CONFIGURATION);
ModelAccess.setCombinedTripleSource(source);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
application.getFileStorage().shutdown(application);
application.getImageProcessor().shutdown(application);
application.getSearchEngine().shutdown(application);
Application app = ApplicationUtils.instance();
app.getSearchEngine().shutdown(app);
app.getImageProcessor().shutdown(app);
app.getFileStorage().shutdown(app);
}
}
}

View file

@ -0,0 +1,115 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.application;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockableModel;
/**
* Read the application setup file and create the components it describes.
*/
public class ApplicationSetup implements ServletContextListener {
private static final String APPLICATION_SETUP_PATH = "config/applicationSetup.n3";
private ServletContext ctx;
private StartupStatus ss;
private ApplicationImpl app;
private VitroHomeDirectory vitroHomeDir;
private Path configFile;
private LockableModel configModel;
private ConfigurationBeanLoader loader;
@Override
public void contextInitialized(ServletContextEvent sce) {
try {
this.ctx = sce.getServletContext();
this.ss = StartupStatus.getBean(ctx);
this.vitroHomeDir = VitroHomeDirectory.find(ctx);
ss.info(this, vitroHomeDir.getDiscoveryMessage());
locateApplicationConfigFile();
loadApplicationConfigFile();
createConfigurationBeanLoader();
instantiateTheApplication();
app.setServletContext(this.ctx);
app.setHomeDirectory(this.vitroHomeDir);
ApplicationUtils.setInstance(app);
ss.info(this, "Application is configured.");
} catch (Exception e) {
ss.fatal(this, "Failed to initialize the Application.", e);
}
}
private void locateApplicationConfigFile() {
Path path = this.vitroHomeDir.getPath().resolve(APPLICATION_SETUP_PATH);
if (!Files.exists(path)) {
throw new IllegalStateException("'" + path + "' does not exist.");
}
if (!Files.isReadable(path)) {
throw new IllegalStateException("Can't read '" + path + "'");
}
this.configFile = path;
}
private void loadApplicationConfigFile() {
try (InputStream in = Files.newInputStream(this.configFile)) {
Model m = ModelFactory.createDefaultModel();
m.read(in, null, "N3");
this.configModel = new LockableModel(m);
} catch (Exception e) {
throw new RuntimeException("Failed to read '" + this.configFile
+ "'", e);
}
}
private void createConfigurationBeanLoader() {
this.loader = new ConfigurationBeanLoader(configModel);
}
private void instantiateTheApplication() {
try {
Set<ApplicationImpl> apps = loader.loadAll(ApplicationImpl.class);
if (apps.isEmpty()) {
throw new IllegalStateException("'" + this.configFile
+ "' does not define an instance of "
+ ApplicationImpl.class.getName());
} else if (apps.size() > 1) {
throw new IllegalStateException("'" + this.configFile
+ "' defines " + apps.size() + " instances of "
+ ApplicationImpl.class.getName());
} else {
this.app = apps.iterator().next();
}
} catch (ConfigurationBeanLoaderException e) {
throw new IllegalStateException("Failed to setup the application",
e);
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
if (app != null) {
app.shutdown();
}
}
}

View file

@ -12,7 +12,7 @@ import edu.cornell.mannlib.vitro.webapp.modules.Application;
*/
public class ApplicationUtils {
private static final Log log = LogFactory.getLog(ApplicationUtils.class);
private static volatile Application instance;
public static Application instance() {
@ -25,9 +25,8 @@ public class ApplicationUtils {
"Called for Application before it was available", e);
}
}
static void setInstance(Application application) {
instance = application;
}
}

View file

@ -0,0 +1,54 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.application;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Obtains and provides the contents of the build.properties file.
*/
public class BuildProperties {
private static final Log log = LogFactory.getLog(BuildProperties.class);
/** Path to the file of build properties baked into the webapp. */
public static final String WEBAPP_PATH_BUILD_PROPERTIES = "/WEB-INF/resources/build.properties";
private final Map<String, String> propertyMap;
public BuildProperties(ServletContext ctx) {
Map<String, String> map = new HashMap<>();
try (InputStream stream = ctx
.getResourceAsStream(WEBAPP_PATH_BUILD_PROPERTIES)) {
if (stream == null) {
log.debug("Didn't find a resource at '"
+ WEBAPP_PATH_BUILD_PROPERTIES + "'.");
} else {
Properties props = new Properties();
props.load(stream);
for (String key : props.stringPropertyNames()) {
map.put(key, props.getProperty(key));
}
}
} catch (IOException e) {
throw new RuntimeException("Failed to load from '"
+ WEBAPP_PATH_BUILD_PROPERTIES + "'.", e);
}
propertyMap = Collections.unmodifiableMap(map);
}
public Map<String, String> getMap() {
return this.propertyMap;
}
}

View file

@ -0,0 +1,213 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.application;
import static edu.cornell.mannlib.vitro.webapp.application.BuildProperties.WEBAPP_PATH_BUILD_PROPERTIES;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.naming.InitialContext;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Encapsulates some of the info relating to the Vitro home directory.
*/
public class VitroHomeDirectory {
private static final Log log = LogFactory.getLog(VitroHomeDirectory.class);
public static VitroHomeDirectory find(ServletContext ctx) {
HomeDirectoryFinder finder = new HomeDirectoryFinder(ctx);
return new VitroHomeDirectory(ctx, finder.getPath(),
finder.getMessage());
}
private final ServletContext ctx;
private final Path path;
private final String discoveryMessage;
public VitroHomeDirectory(ServletContext ctx, Path path,
String discoveryMessage) {
this.ctx = ctx;
this.path = path;
this.discoveryMessage = discoveryMessage;
}
public ServletContext getCtx() {
return ctx;
}
public Path getPath() {
return path;
}
public String getDiscoveryMessage() {
return discoveryMessage;
}
/**
* Find something that specifies the location of the Vitro home directory.
* Look in the JDNI environment, the system properties, and the
* build.properties file.
*
* If we don't find it, fail. If we find it more than once, use the first
* one (with a warning). If it is not an existing, readable directory, fail.
*/
private static class HomeDirectoryFinder {
/** JNDI path that defines the Vitro home directory */
private static final String VHD_JNDI_PATH = "java:comp/env/vitro/home";
/** System property that defines the Vitro home directory */
private static final String VHD_SYSTEM_PROPERTY = "vitro.home";
/** build.properties property that defines the Vitro home directory */
private static final String VHD_BUILD_PROPERTY = "vitro.home";
private final ServletContext ctx;
private final List<Found> foundLocations = new ArrayList<>();
public HomeDirectoryFinder(ServletContext ctx) {
this.ctx = ctx;
getVhdFromJndi();
getVhdFromSystemProperties();
getVhdFromBuildProperties();
confirmExactlyOneResult();
confirmValidDirectory();
}
public String getMessage() {
return foundLocations.get(0).getMessage();
}
public Path getPath() {
return foundLocations.get(0).getPath();
}
public void getVhdFromJndi() {
try {
String vhdPath = (String) new InitialContext()
.lookup(VHD_JNDI_PATH);
if (vhdPath == null) {
log.debug("Didn't find a JNDI value at '" + VHD_JNDI_PATH
+ "'.");
} else {
log.debug("'" + VHD_JNDI_PATH + "' as specified by JNDI: "
+ vhdPath);
String message = String.format(
"JNDI environment '%s' was set to '%s'",
VHD_JNDI_PATH, vhdPath);
foundLocations.add(new Found(Paths.get(vhdPath), message));
}
} catch (Exception e) {
log.debug("JNDI lookup failed. " + e);
}
}
private void getVhdFromSystemProperties() {
String vhdPath = System.getProperty(VHD_SYSTEM_PROPERTY);
if (vhdPath == null) {
log.debug("Didn't find a system property value at '"
+ VHD_SYSTEM_PROPERTY + "'.");
} else {
log.debug("'" + VHD_SYSTEM_PROPERTY
+ "' as specified by system property: " + vhdPath);
String message = String.format(
"System property '%s' was set to '%s'",
VHD_SYSTEM_PROPERTY, vhdPath);
foundLocations.add(new Found(Paths.get(vhdPath), message));
}
}
private void getVhdFromBuildProperties() {
try {
Map<String, String> buildProps = new BuildProperties(ctx)
.getMap();
String vhdPath = buildProps.get(VHD_BUILD_PROPERTY);
if (vhdPath == null) {
log.debug("build properties doesn't contain a value for '"
+ VHD_BUILD_PROPERTY + "'.");
} else {
log.debug("'" + VHD_BUILD_PROPERTY
+ "' as specified by build.properties: " + vhdPath);
String message = String.format(
"In resource '%s', '%s' was set to '%s'.",
WEBAPP_PATH_BUILD_PROPERTIES, VHD_BUILD_PROPERTY,
vhdPath);
foundLocations.add(new Found(Paths.get(vhdPath), message));
}
} catch (Exception e) {
log.warn("Reading build properties failed. " + e);
}
}
private void confirmExactlyOneResult() {
if (foundLocations.isEmpty()) {
String message = String.format("Can't find a value "
+ "for the Vitro home directory. "
+ "Looked in JNDI environment at '%s'. "
+ "Looked for a system property named '%s'. "
+ "Looked in 'WEB-INF/resources/build.properties' "
+ "for '%s'.", VHD_JNDI_PATH, VHD_SYSTEM_PROPERTY,
VHD_BUILD_PROPERTY);
throw new IllegalStateException(message);
} else if (foundLocations.size() > 1) {
String message = String.format("Found multiple values for the "
+ "Vitro home directory: " + foundLocations);
log.warn(message);
}
}
private void confirmValidDirectory() {
Path vhd = getPath();
if (!Files.exists(vhd)) {
throw new IllegalStateException("Vitro home directory '" + vhd
+ "' does not exist.");
}
if (!Files.isDirectory(vhd)) {
throw new IllegalStateException("Vitro home directory '" + vhd
+ "' is not a directory.");
}
if (!Files.isReadable(vhd)) {
throw new IllegalStateException(
"Cannot read Vitro home directory '" + vhd + "'.");
}
if (!Files.isWritable(vhd)) {
throw new IllegalStateException(
"Can't write to Vitro home directory: '" + vhd + "'.");
}
}
/** We found it: where and how. */
private static class Found {
private final Path path;
private final String message;
public Found(Path path, String message) {
this.path = path;
this.message = message;
}
public Path getPath() {
return path;
}
public String getMessage() {
return message;
}
@Override
public String toString() {
return "Found[path=" + path + ", message=" + message + "]";
}
}
}
}

View file

@ -7,12 +7,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@ -20,6 +16,8 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.application.BuildProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
@ -48,23 +46,11 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
private static final Log log = LogFactory
.getLog(ConfigurationPropertiesSetup.class);
/** JNDI path that defines the Vitro home directory */
private static final String VHD_JNDI_PATH = "java:comp/env/vitro/home";
/** System property that defines the Vitro home directory */
private static final String VHD_SYSTEM_PROPERTY = "vitro.home";
/** build.properties property that defines the Vitro home directory */
private static final String VHD_BUILD_PROPERTY = "vitro.home";
/** Configuration property to store the Vitro home directory */
private static final String VHD_CONFIGURATION_PROPERTY = "vitro.home";
/** Name of the file that contains runtime properties. */
private static final String FILE_RUNTIME_PROPERTIES = "runtime.properties";
/** Path to the file of build properties baked into the webapp. */
private static final String PATH_BUILD_PROPERTIES = "/WEB-INF/resources/build.properties";
/** Configuration property to store the Vitro home directory */
private static final String VHD_CONFIGURATION_PROPERTY = "vitro.home";
@Override
public void contextInitialized(ServletContextEvent sce) {
@ -74,7 +60,8 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
try {
InputStream stream = null;
try {
File vitroHomeDir = locateVitroHomeDirectory(ctx, ss);
File vitroHomeDir = ApplicationUtils.instance()
.getHomeDirectory().getPath().toFile();
File runtimePropertiesFile = locateRuntimePropertiesFile(
vitroHomeDir, ss);
@ -82,9 +69,9 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
Map<String, String> preempts = createPreemptiveProperties(
VHD_CONFIGURATION_PROPERTY, vitroHomeDir);
ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(
stream, preempts, getBuildProperties(ctx));
stream, preempts, new BuildProperties(ctx).getMap());
ConfigurationProperties.setBean(ctx, bean);
ss.info(this, "Loaded " + bean.getPropertyMap().size()
@ -103,141 +90,6 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
}
}
/**
* Look in the JDNI environment, the system properties, and the
* build.properties file.
*
* If we don't find it, fail. If we find it more than once, warn and use the
* first one.
*
* Confirm that it is an existing, readable directory.
*/
private File locateVitroHomeDirectory(ServletContext ctx, StartupStatus ss) {
Map<String, String> whereWasIt = new LinkedHashMap<String, String>();
getVhdFromJndi(whereWasIt);
getVhdFromSystemProperties(whereWasIt);
getVhdFromBuildProperties(ctx, whereWasIt);
if (whereWasIt.isEmpty()) {
String message = String.format("Can't find a value "
+ "for the Vitro home directory. "
+ "Looked in JNDI environment at '%s'. "
+ "Looked for a system property named '%s'. "
+ "Looked in 'WEB-INF/resources/build.properties' "
+ "for '%s'.", VHD_JNDI_PATH, VHD_SYSTEM_PROPERTY,
VHD_BUILD_PROPERTY);
throw new IllegalStateException(message);
} else if (whereWasIt.size() > 1) {
String message = String.format("Found multiple values for the "
+ "Vitro home directory: " + whereWasIt.keySet());
ss.warning(this, message);
}
String message = whereWasIt.keySet().iterator().next();
String vhdPath = whereWasIt.values().iterator().next();
ss.info(this, message);
File vhd = new File(vhdPath);
if (!vhd.exists()) {
throw new IllegalStateException("Vitro home directory '" + vhdPath
+ "' does not exist.");
}
if (!vhd.isDirectory()) {
throw new IllegalStateException("Vitro home directory '" + vhdPath
+ "' is not a directory.");
}
if (!vhd.canRead()) {
throw new IllegalStateException("Vitro home directory '" + vhdPath
+ "' cannot be read.");
}
if (!vhd.canWrite()) {
throw new IllegalStateException(
"Can't write to Vitro home directory: '" + vhdPath + "'.");
}
return vhd;
}
private void getVhdFromJndi(Map<String, String> whereWasIt) {
try {
String vhdPath = (String) new InitialContext()
.lookup(VHD_JNDI_PATH);
if (vhdPath == null) {
log.debug("Didn't find a JNDI value at '" + VHD_JNDI_PATH
+ "'.");
return;
}
log.debug("'" + VHD_JNDI_PATH + "' as specified by JNDI: "
+ vhdPath);
String message = String.format(
"JNDI environment '%s' was set to '%s'", VHD_JNDI_PATH,
vhdPath);
whereWasIt.put(message, vhdPath);
} catch (NamingException e) {
log.debug("JNDI lookup failed. " + e);
}
}
private void getVhdFromSystemProperties(Map<String, String> whereWasIt) {
String vhdPath = System.getProperty(VHD_SYSTEM_PROPERTY);
if (vhdPath == null) {
log.debug("Didn't find a system property value at '"
+ VHD_SYSTEM_PROPERTY + "'.");
return;
}
log.debug("'" + VHD_SYSTEM_PROPERTY
+ "' as specified by system property: " + vhdPath);
String message = String.format("System property '%s' was set to '%s'",
VHD_SYSTEM_PROPERTY, vhdPath);
whereWasIt.put(message, vhdPath);
}
private void getVhdFromBuildProperties(ServletContext ctx,
Map<String, String> whereWasIt) {
Map<String, String> buildProps = getBuildProperties(ctx);
String vhdPath = buildProps.get(VHD_BUILD_PROPERTY);
if (vhdPath == null) {
log.debug("'" + PATH_BUILD_PROPERTIES
+ "' didn't contain a value for '" + VHD_BUILD_PROPERTY
+ "'.");
return;
}
log.debug("'" + VHD_BUILD_PROPERTY
+ "' as specified by build.properties: " + vhdPath);
String message = String.format(
"In resource '%s', '%s' was set to '%s'.",
PATH_BUILD_PROPERTIES, VHD_BUILD_PROPERTY, vhdPath);
whereWasIt.put(message, vhdPath);
}
private Map<String, String> getBuildProperties(ServletContext ctx) {
Map<String, String> map = new HashMap<>();
try (InputStream stream = ctx
.getResourceAsStream(PATH_BUILD_PROPERTIES)) {
if (stream == null) {
log.debug("Didn't find a resource at '" + PATH_BUILD_PROPERTIES
+ "'.");
} else {
Properties props = new Properties();
props.load(stream);
for (String key : props.stringPropertyNames()) {
map.put(key, props.getProperty(key));
}
}
} catch (IOException e) {
throw new SetupException("Failed to load from '"
+ PATH_BUILD_PROPERTIES + "'.", e);
}
return map;
}
private File locateRuntimePropertiesFile(File vitroHomeDir, StartupStatus ss) {
File rpf = new File(vitroHomeDir, FILE_RUNTIME_PROPERTIES);
@ -270,13 +122,4 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
// No need to remove the bean. It's only a map of strings, and if we
// restart the app, it will be replaced.
}
/**
* Indicates a problem setting up. Abandon ship.
*/
private static class SetupException extends RuntimeException {
public SetupException(String message, Throwable cause) {
super(message, cause);
}
}
}

View file

@ -25,7 +25,6 @@ public class ConfigurationPropertiesSmokeTests implements
private static final Log log = LogFactory
.getLog(ConfigurationPropertiesSmokeTests.class);
private static final String PROPERTY_HOME_DIRECTORY = "vitro.home";
private static final String PROPERTY_DEFAULT_NAMESPACE = "Vitro.defaultNamespace";
private static final String PROPERTY_LANGUAGE_BUILD = "languages.addToBuild";
private static final String PROPERTY_LANGUAGE_SELECTABLE = "languages.selectableLocales";
@ -38,47 +37,10 @@ public class ConfigurationPropertiesSmokeTests implements
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
StartupStatus ss = StartupStatus.getBean(ctx);
checkHomeDirectory(ctx, props, ss);
checkDefaultNamespace(ctx, props, ss);
checkLanguages(props, ss);
}
/**
* Confirm that: a home directory has been specified; it exists; it is a
* directory; it is readable and writable.
*/
private void checkHomeDirectory(ServletContext ctx,
ConfigurationProperties props, StartupStatus ss) {
String homeDirectoryPath = props.getProperty(PROPERTY_HOME_DIRECTORY);
if (homeDirectoryPath == null || homeDirectoryPath.isEmpty()) {
ss.fatal(this, "Can't find a value for the home directory: '"
+ PROPERTY_HOME_DIRECTORY + "'");
return;
}
File homeDirectory = new File(homeDirectoryPath);
if (!homeDirectory.exists()) {
ss.fatal(this, PROPERTY_HOME_DIRECTORY + " '" + homeDirectoryPath
+ "' does not exist.");
return;
}
if (!homeDirectory.isDirectory()) {
ss.fatal(this, PROPERTY_HOME_DIRECTORY + " '" + homeDirectoryPath
+ "' is not a directory.");
return;
}
if (!homeDirectory.canRead()) {
ss.fatal(this, PROPERTY_HOME_DIRECTORY + " '" + homeDirectoryPath
+ "' cannot be read.");
}
if (!homeDirectory.canWrite()) {
ss.fatal(this, PROPERTY_HOME_DIRECTORY + " '" + homeDirectoryPath
+ "' cannot be written to.");
}
}
/**
* Confirm that the default namespace is specified and a syntactically valid
* URI. It should also end with "/individual/".

View file

@ -25,8 +25,8 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -50,7 +50,6 @@ public class ContactMailController extends FreemarkerHttpServlet {
private final static String TEMPLATE_ERROR = "contactForm-error.ftl";
private final static String TEMPLATE_FORM = "contactForm-form.ftl";
private static final String PROPERTY_VITRO_HOME_DIR = "vitro.home";
private static final String EMAIL_JOURNAL_FILE_DIR = "emailJournal";
private static final String EMAIL_JOURNAL_FILE_NAME = "contactFormEmails.html";
@ -116,7 +115,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
try {
// Write the message to the journal file
FileWriter fw = new FileWriter(locateTheJournalFile(vreq),true);
FileWriter fw = new FileWriter(locateTheJournalFile(), true);
PrintWriter outFile = new PrintWriter(fw);
writeBackupCopy(outFile, msgText, vreq);
@ -159,21 +158,8 @@ public class ContactMailController extends FreemarkerHttpServlet {
* The journal file belongs in a sub-directory of the Vitro home directory.
* If the sub-directory doesn't exist, create it.
*/
private File locateTheJournalFile(VitroRequest vreq) {
String homeDirPath = ConfigurationProperties.getBean(vreq).getProperty(
PROPERTY_VITRO_HOME_DIR);
if (homeDirPath == null) {
throw new IllegalArgumentException(
"Configuration properties must contain a value for '"
+ PROPERTY_VITRO_HOME_DIR + "'");
}
File homeDir = new File(homeDirPath);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ homeDir.getAbsolutePath() + "' does not exist.");
}
private File locateTheJournalFile() {
File homeDir = ApplicationUtils.instance().getHomeDirectory().getPath().toFile();
File journalDir = new File(homeDir, EMAIL_JOURNAL_FILE_DIR);
if (!journalDir.exists()) {
boolean created = journalDir.mkdir();

View file

@ -11,6 +11,7 @@ import java.util.Collections;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
@ -22,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.modules.fileStorage.FileStorage;
*/
public class FileStorageImplWrapper implements FileStorage {
public static final String PROPERTY_DEFAULT_NAMESPACE = "Vitro.defaultNamespace";
public static final String PROPERTY_VITRO_HOME_DIR = "vitro.home";
public static final String FILE_STORAGE_SUBDIRECTORY = "uploads";
private FileStorageImpl fs;
@ -35,7 +35,7 @@ public class FileStorageImplWrapper implements FileStorage {
ServletContext ctx = application.getServletContext();
try {
File baseDirectory = figureBaseDir(ctx);
File baseDirectory = figureBaseDir();
Collection<String> fileNamespace = confirmDefaultNamespace(ctx);
fs = new FileStorageImpl(baseDirectory, fileNamespace);
} catch (Exception e) {
@ -47,21 +47,8 @@ public class FileStorageImplWrapper implements FileStorage {
* Get the configuration property for the file storage base directory, and
* check that it points to an existing, writeable directory.
*/
private File figureBaseDir(ServletContext ctx) throws IOException {
String homeDirPath = ConfigurationProperties.getBean(ctx).getProperty(
PROPERTY_VITRO_HOME_DIR);
if (homeDirPath == null) {
throw new IllegalArgumentException(
"Configuration properties must contain a value for '"
+ PROPERTY_VITRO_HOME_DIR + "'");
}
File homeDir = new File(homeDirPath);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ homeDir.getAbsolutePath() + "' does not exist.");
}
private File figureBaseDir() throws IOException {
File homeDir = ApplicationUtils.instance().getHomeDirectory().getPath().toFile();
File baseDir = new File(homeDir, FILE_STORAGE_SUBDIRECTORY);
if (!baseDir.exists()) {
boolean created = baseDir.mkdir();

View file

@ -10,7 +10,7 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.ContextModelAccessImpl;
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.RequestModelAccessImpl;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
/**
* The root access point for the RDF data structures: RDFServices, Datasets,
@ -136,18 +136,18 @@ public class ModelAccess {
// The factory
// ----------------------------------------------------------------------
private static volatile DataStructuresProvider dataStructuresProvider;
private static volatile CombinedTripleSource combinedTripleSource;
private static volatile ModelAccessFactory factory = new ModelAccessFactory();
/** These attributes should only be accessed through this class. */
private static final String ATTRIBUTE_NAME = ModelAccess.class.getName();
public static void setDataStructuresProvider(DataStructuresProvider provider) {
if (dataStructuresProvider != null) {
log.warn("Assigning DataStructuresProvider " + provider
+ ", but was already set to " + dataStructuresProvider);
public static void setCombinedTripleSource(CombinedTripleSource source) {
if (combinedTripleSource != null) {
log.warn("Assigning CombinedTripleSource " + source
+ ", but was already set to " + combinedTripleSource);
}
dataStructuresProvider = provider;
combinedTripleSource = source;
}
public static RequestModelAccess on(HttpServletRequest req) {
@ -182,7 +182,7 @@ public class ModelAccess {
public static class ModelAccessFactory {
public ContextModelAccess buildContextModelAccess(ServletContext ctx) {
return new ContextModelAccessImpl(ctx, dataStructuresProvider);
return new ContextModelAccessImpl(ctx, combinedTripleSource);
}
/**
@ -191,8 +191,7 @@ public class ModelAccess {
*/
public RequestModelAccess buildRequestModelAccess(HttpServletRequest req) {
return new RequestModelAccessImpl(req,
dataStructuresProvider
.getShortTermDataStructuresProvider(req));
combinedTripleSource.getShortTermCombinedTripleSource(req));
}
}
}

View file

@ -45,7 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -66,7 +66,7 @@ public class ContextModelAccessImpl implements ContextModelAccess {
private final ConfigurationProperties props;
private final DataStructuresProvider factory;
private final CombinedTripleSource factory;
private final Map<WhichService, RDFService> rdfServiceMap;
private final Map<WhichService, Dataset> datasetMap;
@ -86,7 +86,7 @@ public class ContextModelAccessImpl implements ContextModelAccess {
* requested.
*/
public ContextModelAccessImpl(ServletContext ctx,
DataStructuresProvider factory) {
CombinedTripleSource factory) {
this.props = ConfigurationProperties.getBean(ctx);
this.factory = factory;

View file

@ -51,7 +51,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.WebappDaoFactoryKe
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -89,14 +89,14 @@ public class RequestModelAccessImpl implements RequestModelAccess {
private final HttpServletRequest req;
private final ServletContext ctx;
private final ConfigurationProperties props;
private final ShortTermDataStructuresProvider provider;
private final ShortTermCombinedTripleSource source;
public RequestModelAccessImpl(HttpServletRequest req,
ShortTermDataStructuresProvider provider) {
ShortTermCombinedTripleSource source) {
this.req = req;
this.ctx = req.getSession().getServletContext();
this.props = ConfigurationProperties.getBean(req);
this.provider = provider;
this.source = source;
}
/**
@ -113,13 +113,13 @@ public class RequestModelAccessImpl implements RequestModelAccess {
@Override
public void close() {
this.provider.close();
this.source.close();
}
@Override
public String toString() {
return "RequestModelAccessImpl[" + ToString.hashHex(this) + ", req="
+ ToString.hashHex(req) + ", provider=" + provider + "]";
+ ToString.hashHex(req) + ", source=" + source + "]";
}
// ----------------------------------------------------------------------
@ -149,7 +149,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
if (key.getLanguageOption() == LANGUAGE_AWARE) {
return addLanguageAwareness(getRDFService(LANGUAGE_NEUTRAL));
} else {
return provider.getRDFService(key.getWhichService());
return source.getRDFService(key.getWhichService());
}
}
@ -222,7 +222,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
return addLanguageAwareness(getOntModel(key.getName(),
LANGUAGE_NEUTRAL));
} else {
return provider.getOntModelCache().getOntModel(key.getName());
return source.getOntModelCache().getOntModel(key.getName());
}
}
@ -313,7 +313,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
RDFService rdfService = getRDFService(key.rdfServiceKey());
OntModelSelector ontModelSelector = getOntModelSelector(key
.ontModelSelectorKey());
WebappDaoFactoryConfig config = provider.getWebappDaoFactoryConfig();
WebappDaoFactoryConfig config = source.getWebappDaoFactoryConfig();
switch (key.getReasoningOption()) {
case ASSERTIONS_ONLY:

View file

@ -4,21 +4,32 @@ package edu.cornell.mannlib.vitro.webapp.modules;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory;
import edu.cornell.mannlib.vitro.webapp.modules.fileStorage.FileStorage;
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
/**
* The interface that holds the modules and extensions together.
*/
public interface Application {
ServletContext getServletContext();
VitroHomeDirectory getHomeDirectory();
SearchEngine getSearchEngine();
ImageProcessor getImageProcessor();
FileStorage getFileStorage();
ContentTripleSource getContentTripleSource();
ConfigurationTripleSource getConfigurationTripleSource();
void shutdown();
public interface Component {
enum LifecycleState {

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY_DISPLAY;
@ -10,11 +10,9 @@ import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.USER_ACCOU
import com.hp.hpl.jena.rdf.model.ModelMaker;
/**
* The base class for a provider of configuration models. It just contains some
* useful constants and utility methods.
* A triple source for configuration models.
*/
public abstract class ConfigurationDataStructuresProvider implements
SingleSourceDataStructuresProvider {
public abstract class ConfigurationTripleSource implements TripleSource {
/**
* A list of all Configuration models, in case the implementation wants to
* add memory-mapping.
@ -33,5 +31,4 @@ public abstract class ConfigurationDataStructuresProvider implements
}
return sourceMM;
}
}

View file

@ -1,23 +1,20 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.APPLICATION_METADATA;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.FULL_UNION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_ASSERTIONS;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.*;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_INFERENCES;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.NamedDefaultModelMaker;
/**
* The base class for a provider of content models. It just contains some useful
* constants and utility methods.
* A triple source for content models.
*/
public abstract class ContentDataStructuresProvider implements
SingleSourceDataStructuresProvider {
public abstract class ContentTripleSource implements TripleSource {
/**
* These are the small content models that we want to keep in memory.
*/

View file

@ -1,22 +1,19 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
/**
* An RDFSource that provides Content models or Configuration models, but not
* both.
*
* Repeated calls for the same data structure should yield the same instance,
* except for the short-term OntModelCache.
* A provider of triples and the data structures by which they are accessed.
*/
public interface SingleSourceDataStructuresProvider extends AutoCloseable {
public interface TripleSource extends Application.Module{
RDFServiceFactory getRDFServiceFactory();
RDFService getRDFService();
@ -27,4 +24,7 @@ public interface SingleSourceDataStructuresProvider extends AutoCloseable {
OntModelCache getShortTermOntModels(RDFService shortTermRdfService,
OntModelCache longTermOntModelCache);
/** Ways in which this TripleSource behaves oddly. */
TripleStoreQuirks getQuirks();
}

View file

@ -0,0 +1,18 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import com.hp.hpl.jena.rdf.model.Model;
/**
* TODO
*/
public interface TripleStoreQuirks {
/**
* Test to see whether the FileGraph must be updated to reflect the current
* state of the file.
*/
boolean hasFileGraphChanged(Model fromFile, Model previous, String graphURI);
}

View file

@ -15,12 +15,12 @@ import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
/**
* DocumentModifier that will run SPARQL queries for an
@ -30,19 +30,24 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
* @author bdc34
*
*/
public class ContextNodeFields implements DocumentModifier{
public class ContextNodeFields implements DocumentModifier, ContextModelsUser{
protected List<String> queries = new ArrayList<String>();
protected boolean shutdown = false;
protected Log log = LogFactory.getLog(ContextNodeFields.class);
protected RDFServiceFactory rdfServiceFactory;
private RDFService rdfService;
@Override
public void setContextModels(ContextModelAccess models) {
this.rdfService = models.getRDFService();
}
/**
* Construct this with a model to query when building search documents and
* a list of the SPARQL queries to run.
*/
protected ContextNodeFields(List<String> queries, RDFServiceFactory rdfServiceFactory){
protected ContextNodeFields(List<String> queries){
this.queries = queries;
this.rdfServiceFactory = rdfServiceFactory;
}
@ -74,7 +79,6 @@ public class ContextNodeFields implements DocumentModifier{
*/
protected StringBuffer executeQueryForValues( Individual individual, Collection<String> queries){
/* execute all the queries on the list and concat the values to add to all text */
RDFService rdfService = rdfServiceFactory.getRDFService();
StringBuffer allValues = new StringBuffer("");
for(String query : queries ){
@ -102,8 +106,6 @@ public class ContextNodeFields implements DocumentModifier{
}
allValues.append(valuesForQuery);
}
rdfService.close();
return allValues;
}
@ -137,4 +139,11 @@ public class ContextNodeFields implements DocumentModifier{
public void shutdown(){
shutdown=true;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "[]";
}
}

View file

@ -1,34 +1,36 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
/**
* Skip individual if its URI is from any of the excludeNamepsaces
*
* Skip individual if its URI is from any of the excludeNamespaces.
*/
public class ExcludeBasedOnNamespace implements SearchIndexExcluder {
List<String> excludeNamepsaces;
public ExcludeBasedOnNamespace(String ... excludeNamepsaces) {
super();
this.excludeNamepsaces = Arrays.asList(excludeNamepsaces);
}
private List<String> excludeNamespaces = new ArrayList<>();
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#excludes")
public void addExcludedNamespace(String ns) {
excludeNamespaces.add(ns);
}
@Override
public String checkForExclusion(Individual ind) {
for( String ns: excludeNamepsaces){
if( ns.equals( ind.getNamespace() ) ){
return "skipping because of namespace " ;
}
}
return null;
}
@Override
public String checkForExclusion(Individual ind) {
for (String ns : excludeNamespaces) {
if (ns.equals(ind.getNamespace())) {
return "skipping because of namespace " + ns;
}
}
return null;
}
@Override
public String toString() {
return "ExcludeBasedOnNamespace[namespaces=" + excludeNamespaces + "]";
}
}

View file

@ -1,83 +1,96 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import static edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument.DONT_EXCLUDE;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
/**
* Exclude individual from search index if
* it is a member of any of the the types.
* Exclude individual from search index if it is a member of any of the the
* types.
*
* @author bdc34
*
*
*/
public class ExcludeBasedOnType implements SearchIndexExcluder {
private static final String SKIP_MSG = "skipping due to type.";
/** The add, set and remove methods must keep this list sorted. */
List<String> typeURIs;
public ExcludeBasedOnType(String ... typeURIs) {
setExcludedTypes( typeURIs );
}
@Override
public String checkForExclusion(Individual ind) {
if( ind == null )
return null;
if( typeURIinExcludeList( ind.getVClass() ))
return SKIP_MSG;
List<VClass> vclasses = new ArrayList<VClass>();
vclasses.addAll( ind.getVClasses()!=null?ind.getVClasses():Collections.EMPTY_LIST );
vclasses.addAll( ind.getVClasses(true)!=null?ind.getVClasses(true):Collections.EMPTY_LIST );
for( VClass vclz : vclasses){
if( typeURIinExcludeList( vclz ))
return SKIP_MSG;
}
return null;
}
protected boolean typeURIinExcludeList( VClass vclz){
if( vclz != null && vclz.getURI() != null && !vclz.isAnonymous() ){
int pos = Collections.binarySearch(typeURIs, vclz.getURI());
return pos >= 0;
}else{
return false;
}
}
public void setExcludedTypes(String ... typeURIs){
setExcludedTypes(Arrays.asList(typeURIs));
}
public void setExcludedTypes(List<String> typeURIs){
synchronized(this){
this.typeURIs = new ArrayList<String>(typeURIs) ;
Collections.sort( this.typeURIs );
}
}
protected void addTypeToExclude(String typeURI){
if( typeURI != null && !typeURI.isEmpty()){
synchronized(this){
typeURIs.add(typeURI);
Collections.sort( this.typeURIs );
}
}
}
protected void removeTypeToExclude(String typeURI){
synchronized(this){
typeURIs.remove(typeURI);
}
}
private final Set<String> typeURIs = new HashSet<>();
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#excludes")
public void addTypeURI(String uri) {
typeURIs.add(uri);
}
@Override
public String checkForExclusion(Individual ind) {
if (ind == null) {
return DONT_EXCLUDE;
}
if (typeURIinExcludeList(ind.getVClass())) {
return SKIP_MSG;
}
List<VClass> vclasses = new ArrayList<>();
addToList(vclasses, ind.getVClasses());
addToList(vclasses, ind.getVClasses(true));
for (VClass vclz : vclasses) {
if (typeURIinExcludeList(vclz))
return SKIP_MSG;
}
return DONT_EXCLUDE;
}
private void addToList(List<VClass> list, List<VClass> additions) {
if (additions != null) {
list.addAll(additions);
}
}
protected boolean typeURIinExcludeList(VClass vclz) {
if (vclz != null && vclz.getURI() != null && !vclz.isAnonymous()) {
synchronized (typeURIs) {
return typeURIs.contains(vclz.getURI());
}
} else {
return false;
}
}
protected void setExcludedTypes(List<String> typeURIs) {
synchronized (typeURIs) {
this.typeURIs.clear();
this.typeURIs.addAll(typeURIs);
}
}
protected void addTypeToExclude(String typeURI) {
if (typeURI != null && !typeURI.isEmpty()) {
synchronized (typeURIs) {
typeURIs.add(typeURI);
}
}
}
protected void removeTypeToExclude(String typeURI) {
synchronized (typeURIs) {
typeURIs.remove(typeURI);
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " [typeURIs=" + typeURIs + "]";
}
}

View file

@ -1,34 +1,39 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/**
* Exclude individuals based on the namespaces of their types.
*/
public class ExcludeBasedOnTypeNamespace implements SearchIndexExcluder {
final List<String> namespaces;
private final List<String> namespaces = new ArrayList<>();
Pattern nsRegexPattern;
public ExcludeBasedOnTypeNamespace(String ... namespaces) {
super();
this.namespaces = Collections.unmodifiableList(Arrays.asList( namespaces ));
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#excludes")
public void addExcludedNamespace(String uri) {
namespaces.add(uri);
}
@Validation
public void compileRegexPattern() {
String nsOrPattern = "";
for( int i=0; i<namespaces.length; i++){
String ns = namespaces[i];
for( int i=0; i<namespaces.size(); i++){
String ns = namespaces.get(i);
nsOrPattern = nsOrPattern + (i!=0?"|":"") + Pattern.quote(ns) + "[^/#]*$";
}
this.nsRegexPattern = Pattern.compile(nsOrPattern);
}
}
@Override
public String checkForExclusion(Individual ind) {
@ -50,7 +55,11 @@ public class ExcludeBasedOnTypeNamespace implements SearchIndexExcluder {
}
}
return null;
}
}
@Override
public String toString() {
return "ExcludeBasedOnTypeNamespace [namespaces=" + namespaces + "]";
}
}

View file

@ -54,4 +54,9 @@ public class ExcludeNonFlagVitro implements SearchIndexExcluder {
return DONT_EXCLUDE;
}
@Override
public String toString() {
return "ExcludeNonFlagVitro []";
}
}

View file

@ -350,5 +350,5 @@ public class IndividualToSearchDocument {
}
}
protected static final String DONT_EXCLUDE =null;
public static final String DONT_EXCLUDE =null;
}

View file

@ -6,9 +6,14 @@ import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW;
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_STEMMED;
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_UNSTEMMED;
import java.util.Arrays;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
public class NameBoost implements DocumentModifier {
@ -18,13 +23,22 @@ public class NameBoost implements DocumentModifier {
* please consider if you need to change this list
* of name fields to boost.
*/
String[] fieldsToBoost = {NAME_RAW,NAME_LOWERCASE,NAME_UNSTEMMED,NAME_STEMMED};
private String[] fieldsToBoost = {NAME_RAW,NAME_LOWERCASE,NAME_UNSTEMMED,NAME_STEMMED};
private Float boost;
final float boost;
@Property(uri="http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasBoost")
public void setBoost(float boost) {
this.boost = boost;
}
public NameBoost(float boost){
this.boost = boost;
@Validation
public void validate() {
if (boost == null) {
throw new IllegalStateException(
"Configuration did not include a boost value.");
}
}
@Override
@ -43,4 +57,10 @@ public class NameBoost implements DocumentModifier {
// do nothing.
}
@Override
public String toString() {
return "NameBoost[fieldsToBoost=" + Arrays.toString(fieldsToBoost)
+ ", boost=" + boost + "]";
}
}

View file

@ -10,26 +10,28 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ResultFormat;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
/**
* Adds all labels to name fields, not just the one returned by Individual.getName().
*/
public class NameFields implements DocumentModifier {
RDFServiceFactory rsf;
public class NameFields implements DocumentModifier, ContextModelsUser {
private RDFService rdfService;
public static final VitroSearchTermNames term = new VitroSearchTermNames();
public static final Log log = LogFactory.getLog(NameFields.class.getName());
public NameFields( RDFServiceFactory rsf){
this.rsf = rsf;
@Override
public void setContextModels(ContextModelAccess models) {
this.rdfService = models.getRDFService();
}
@Override
public void modifyDocument(Individual ind, SearchInputDocument doc) {
if( ind == null || ind.getURI() == null ){
@ -43,7 +45,6 @@ public class NameFields implements DocumentModifier {
"<http://www.w3.org/2000/01/rdf-schema#label> ?label }";
try {
RDFService rdfService = rsf.getRDFService();
BufferedReader stream =
new BufferedReader(new InputStreamReader(rdfService.sparqlSelectQuery(query, ResultFormat.CSV)));

View file

@ -1,12 +1,16 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.EXCLUDE_CLASS;
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SEARCH_INDEX_URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
@ -23,25 +27,35 @@ import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/**
* This excludes based on types defined as EXCLUDE_CLASS in the
* configuration RDF model.
*/
public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements ModelChangedListener{
public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements ModelChangedListener, ContextModelsUser {
static final Log log = LogFactory.getLog(SyncingExcludeBasedOnType.class);
private static final String queryForProhibitedClasses =
"SELECT ?prohibited WHERE{" +
"?searchConfig <" + DisplayVocabulary.EXCLUDE_CLASS + "> ?prohibited . " +
"?searchConfig <" + EXCLUDE_CLASS + "> ?prohibited . " +
"}";
String searchIndexURI = DisplayVocabulary.SEARCH_INDEX_URI;
public SyncingExcludeBasedOnType( Model model){
this.setExcludedTypes( buildProhibitedClassesList(searchIndexURI, model) );
log.info("types excluded from search: " + typeURIs);
private ContextModelAccess models;
@Override
public void setContextModels(ContextModelAccess models) {
this.models = models;
}
@Validation
public void buildClassList( ){
OntModel model = models.getOntModel(ModelNames.DISPLAY);
this.setExcludedTypes( buildProhibitedClassesList(SEARCH_INDEX_URI, model) );
log.debug(this);
}
private List<String> buildProhibitedClassesList( String URI, Model model){
@ -81,10 +95,10 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
public void addedStatement(Statement s) {
try{
if( isExcludeClassPredicate( s ) && isAboutSearchIndex(s)){
if( s.getObject() != null && s.getObject().canAs(Resource.class)){
String classURI = ((Resource)s.getObject().as(Resource.class)).getURI();
if( s.getObject() != null && s.getObject().isURIResource()){
String classURI = s.getObject().asResource().getURI();
this.addTypeToExclude(classURI);
log.debug("prohibited classes: " + this.typeURIs);
log.debug("prohibited classes: " + this);
}
}
}catch(Exception ex){
@ -97,10 +111,10 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
public void removedStatement(Statement s) {
try{
if( isExcludeClassPredicate( s ) && isAboutSearchIndex(s)){
if( s.getObject() != null && s.getObject().canAs(Resource.class)){
String classURI = ((Resource)s.getObject().as(Resource.class)).getURI();
if( s.getObject() != null && s.getObject().isURIResource()){
String classURI = s.getObject().asResource().getURI();
this.removeTypeToExclude(classURI);
log.debug("prohibited classes: " + this.typeURIs);
log.debug("prohibited classes: " + this);
}
}
}catch(Exception ex){
@ -111,13 +125,13 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
private boolean isExcludeClassPredicate(Statement s){
return s != null
&& s.getPredicate() != null
&& DisplayVocabulary.EXCLUDE_CLASS.getURI().equals( s.getPredicate().getURI());
&& EXCLUDE_CLASS.getURI().equals( s.getPredicate().getURI());
}
private boolean isAboutSearchIndex(Statement s){
if( s.getSubject() != null ){
String subURI = ((Resource) s.getSubject()).getURI() ;
return this.searchIndexURI.equals(subURI);
String subURI = s.getSubject().getURI() ;
return SEARCH_INDEX_URI.equals(subURI);
}else{
return false;
}
@ -152,10 +166,9 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
@Override
public void addedStatements(Model model) {
if( model != null){
addedStatements(model.listStatements(
model.createResource(searchIndexURI),
DisplayVocabulary.EXCLUDE_CLASS,
(RDFNode)null));
addedStatements(model.listStatements(
model.createResource(SEARCH_INDEX_URI), EXCLUDE_CLASS,
(RDFNode) null));
}
}
@ -193,10 +206,9 @@ public class SyncingExcludeBasedOnType extends ExcludeBasedOnType implements Mod
@Override
public void removedStatements(Model model) {
if( model != null){
removedStatements(model.listStatements(
model.createResource(searchIndexURI),
DisplayVocabulary.EXCLUDE_CLASS,
(RDFNode)null));
removedStatements(model.listStatements(
model.createResource(SEARCH_INDEX_URI), EXCLUDE_CLASS,
(RDFNode) null));
}
}

View file

@ -15,12 +15,13 @@ import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
public class ThumbnailImageURL implements DocumentModifier {
public class ThumbnailImageURL implements DocumentModifier, ContextModelsUser {
private static final String PREFIX = "prefix owl: <http://www.w3.org/2002/07/owl#> "
+ " prefix vitroDisplay: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> "
@ -36,12 +37,12 @@ public class ThumbnailImageURL implements DocumentModifier {
+ " ?uri <http://vitro.mannlib.cornell.edu/ns/vitro/public#mainImage> ?a . "
+ " ?a <http://vitro.mannlib.cornell.edu/ns/vitro/public#downloadLocation> ?downloadLocation . } ";
private RDFServiceFactory rsf;
private RDFService rdf;
private Log log = LogFactory.getLog(ThumbnailImageURL.class);
public ThumbnailImageURL( RDFServiceFactory rsf ){
this.rsf = rsf;
@Override
public void setContextModels(ContextModelAccess models) {
this.rdf = models.getRDFService();
}
@Override
@ -71,7 +72,6 @@ public class ThumbnailImageURL implements DocumentModifier {
String uri = "<" + individual.getURI() + "> ";
String query = QUERY_TEMPLATE.replaceAll("\\?uri", uri);
RDFService rdf = rsf.getRDFService();
try{
ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, rdf);
while(results.hasNext()){
@ -89,8 +89,6 @@ public class ThumbnailImageURL implements DocumentModifier {
}
}catch(Throwable t){
log.error(t,t);
} finally{
rdf.close();
}
return result.toString();
}

View file

@ -18,6 +18,8 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineExcepti
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/**
* Manages the life-cycle of the SearchEngine. Adds logging, controlled by
@ -27,17 +29,30 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
private static final Log log = LogFactory
.getLog(InstrumentedSearchEngineWrapper.class);
private final SearchEngine innerEngine;
private SearchEngine innerEngine;
private volatile LifecycleState lifecycleState = NEW;
public InstrumentedSearchEngineWrapper(SearchEngine innerEngine) {
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#wraps")
public void setInnerEngine(SearchEngine inner) {
if (innerEngine == null) {
throw new NullPointerException("innerEngine may not be null.");
innerEngine = inner;
} else {
throw new IllegalStateException(
"Configuration includes multiple SearchEngine instancess: "
+ innerEngine + ", and " + inner);
}
this.innerEngine = innerEngine;
}
@Validation
public void validate() throws Exception {
if (innerEngine == null) {
throw new IllegalStateException(
"Configuration did not include a wrapped SearchEngine.");
}
}
/**
* Complain unless ACTIVE.
*/

View file

@ -6,17 +6,18 @@ import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
@ -25,25 +26,18 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.search.SearchIndexer;
import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnNamespace;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnType;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnTypeNamespace;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeNonFlagVitro;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameBoost;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameFields;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SyncingExcludeBasedOnType;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL;
import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalUriFinders;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
import edu.cornell.mannlib.vitro.webapp.utils.developer.Key;
import edu.cornell.mannlib.vitro.webapp.utils.developer.listeners.DeveloperDisabledModelChangeListener;
@ -51,63 +45,26 @@ import edu.cornell.mannlib.vitro.webapp.utils.developer.listeners.DeveloperDisab
* TODO
*/
public class SearchIndexerSetup implements ServletContextListener {
private static final Log log = LogFactory.getLog(SearchIndexerSetup.class);
public static final String PROHIBITED_FROM_SEARCH = "edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch";
/**
* Exclude from the search index Individuals with types from these
* namespaces
*/
private static final String[] TYPE_NS_EXCLUDES = { VitroVocabulary.PUBLIC
// if you do OWL.NS here you will exclude all of owl:Thing.
};
/**
* Exclude from the search index individuals who's URIs start with these
* namespaces.
*/
private static final String[] INDIVIDUAL_NS_EXCLUDES = {
VitroVocabulary.vitroURI, VitroVocabulary.VITRO_PUBLIC,
VitroVocabulary.PSEUDO_BNODE_NS, OWL.NS };
/** Individuals of these types will be excluded from the search index */
private static final String[] OWL_TYPES_EXCLUDES = {
OWL.ObjectProperty.getURI(), OWL.DatatypeProperty.getURI(),
OWL.AnnotationProperty.getURI() };
private ServletContext ctx;
private OntModel displayModel;
private ConfigurationBeanLoader beanLoader;
@Override
public void contextInitialized(ServletContextEvent sce) {
this.ctx = sce.getServletContext();
this.displayModel = ModelAccess.on(ctx).getOntModel(DISPLAY);
this.beanLoader = new ConfigurationBeanLoader(displayModel, ctx);
ServletContext context = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(context);
SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine();
try {
/* set up the individual to search doc translation */
OntModel jenaOntModel = ModelAccess.on(context).getOntModel();
OntModel displayModel = ModelAccess.on(context).getOntModel(DISPLAY);
/*
* try to get context attribute DocumentModifiers and use that as
* the start of the list of DocumentModifier objects. This allows
* other ContextListeners to add to the basic set of
* DocumentModifiers.
*/
@SuppressWarnings("unchecked")
List<DocumentModifier> modifiersFromContext = (List<DocumentModifier>) context
.getAttribute("DocumentModifiers");
/*
* try to get context attribute SearchIndexExcludes and use that as
* the start of the list of exclude objects. This allows other
* ContextListeners to add to the basic set of SearchIndexExcludes .
*/
@SuppressWarnings("unchecked")
List<SearchIndexExcluder> searchIndexExcludesFromContext = (List<SearchIndexExcluder>) context
.getAttribute("SearchIndexExcludes");
IndividualToSearchDocument indToSearchDoc = setupTranslation(
jenaOntModel, displayModel,
RDFServiceUtils.getRDFServiceFactory(context),
modifiersFromContext, searchIndexExcludesFromContext);
IndividualToSearchDocument indToSearchDoc = setupTranslation();
/* setup search indexer */
SearchIndexer searchIndexer = new SearchIndexer(searchEngine, indToSearchDoc);
@ -156,42 +113,17 @@ public class SearchIndexerSetup implements ServletContextListener {
}
public static IndividualToSearchDocument setupTranslation(
OntModel jenaOntModel, Model displayModel,
RDFServiceFactory rdfServiceFactory,
List<DocumentModifier> modifiersFromContext,
List<SearchIndexExcluder> searchIndexExcludesFromContext) {
private IndividualToSearchDocument setupTranslation() {
try {
Set<SearchIndexExcluder> excluders = beanLoader.loadAll(SearchIndexExcluder.class);
log.debug("Excludes: (" + excluders.size() + ") " + excluders);
/*
* try to get context attribute DocumentModifiers and use that as the
* start of the list of DocumentModifier objects. This allows other
* ContextListeners to add to the basic set of DocumentModifiers.
*/
List<DocumentModifier> modifiers = new ArrayList<DocumentModifier>();
if (modifiersFromContext != null) {
modifiers.addAll(modifiersFromContext);
Set<DocumentModifier> modifiers = beanLoader.loadAll(DocumentModifier.class);
log.debug("Modifiers: (" + modifiers.size() + ") " + modifiers);
return new IndividualToSearchDocument(new ArrayList<>(excluders), new ArrayList<>(modifiers));
} catch (ConfigurationBeanLoaderException e) {
throw new RuntimeException("Failed to configure the SearchIndexer", e);
}
modifiers.add(new NameFields(rdfServiceFactory));
modifiers.add(new NameBoost(1.2f));
modifiers.add(new ThumbnailImageURL(rdfServiceFactory));
/*
* try to get context attribute SearchIndexExcludes and use that as the
* start of the list of exclude objects. This allows other
* ContextListeners to add to the basic set of SearchIndexExcludes .
*/
List<SearchIndexExcluder> excludes = new ArrayList<SearchIndexExcluder>();
if (searchIndexExcludesFromContext != null) {
excludes.addAll(searchIndexExcludesFromContext);
}
excludes.add(new ExcludeBasedOnNamespace(INDIVIDUAL_NS_EXCLUDES));
excludes.add(new ExcludeBasedOnTypeNamespace(TYPE_NS_EXCLUDES));
excludes.add(new ExcludeBasedOnType(OWL_TYPES_EXCLUDES));
excludes.add(new ExcludeNonFlagVitro());
excludes.add(new SyncingExcludeBasedOnType(displayModel));
return new IndividualToSearchDocument(excludes, modifiers);
}
}

View file

@ -52,13 +52,12 @@ public class ConfigurationModelsSetup implements ServletContextListener {
private void loadFirstTimeFiles(ServletContext ctx, String modelPath,
OntModel baseModel) {
RDFFilesLoader.loadFirstTimeFiles(ctx, modelPath, baseModel,
baseModel.isEmpty());
RDFFilesLoader.loadFirstTimeFiles(modelPath, baseModel, baseModel.isEmpty());
}
private void loadEveryTimeFiles(ServletContext ctx, String modelPath,
OntModel memoryModel) {
RDFFilesLoader.loadEveryTimeFiles(ctx, modelPath, memoryModel);
RDFFilesLoader.loadEveryTimeFiles(modelPath, memoryModel);
}
@Override

View file

@ -62,13 +62,13 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
if (isFirstStartup()) {
initializeApplicationMetadata(ctx, applicationMetadataModel);
RDFFilesLoader.loadFirstTimeFiles(ctx, "abox", baseABoxModel, true);
RDFFilesLoader.loadFirstTimeFiles(ctx, "tbox", baseTBoxModel, true);
RDFFilesLoader.loadFirstTimeFiles("abox", baseABoxModel, true);
RDFFilesLoader.loadFirstTimeFiles("tbox", baseTBoxModel, true);
} else {
checkForNamespaceMismatch( applicationMetadataModel, ctx );
}
RDFFilesLoader.loadEveryTimeFiles(ctx, "abox", baseABoxModel);
RDFFilesLoader.loadEveryTimeFiles(ctx, "tbox", baseTBoxModel);
RDFFilesLoader.loadEveryTimeFiles("abox", baseABoxModel);
RDFFilesLoader.loadEveryTimeFiles("tbox", baseTBoxModel);
log.info("Setting up DAO factories");
}
@ -89,7 +89,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
private void initializeApplicationMetadata(ServletContext ctx,
Model applicationMetadataModel) {
OntModel temporaryAMModel = VitroModelFactory.createOntologyModel();
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
RDFFilesLoader.loadFirstTimeFiles("applicationMetadata", temporaryAMModel, true);
setPortalUriOnFirstTime(temporaryAMModel, ctx);
applicationMetadataModel.add(temporaryAMModel);
}

View file

@ -31,10 +31,9 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.jena.BlankNodeFilteringModelMaker;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
@ -49,7 +48,6 @@ public class FileGraphSetup implements ServletContextListener {
private static final String ABOX = "abox";
private static final String TBOX = "tbox";
private static final String FILEGRAPH = "filegraph";
private static final String PROPERTY_VITRO_HOME = "vitro.home";
public static final String FILEGRAPH_URI_ROOT = "http://vitro.mannlib.cornell.edu/filegraph/";
@ -73,8 +71,6 @@ public class FileGraphSetup implements ServletContextListener {
OntDocumentManager.getInstance().setProcessImports(true);
Dataset dataset = ModelAccess.on(ctx).getDataset();
RDFService rdfService = ModelAccess.on(ctx).getRDFService(CONTENT);
ModelMaker modelMaker = new BlankNodeFilteringModelMaker(
rdfService, ModelAccess.on(ctx).getModelMaker(CONTENT));
// ABox files
Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH);
@ -82,7 +78,7 @@ public class FileGraphSetup implements ServletContextListener {
cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX);
// Just update the ABox filegraphs in the DB; don't attach them to a base model.
aboxChanged = readGraphs(paths, modelMaker, ABOX, /* aboxBaseModel */ null);
aboxChanged = readGraphs(paths, rdfService, ABOX, /* aboxBaseModel */ null);
// TBox files
paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH);
@ -90,7 +86,7 @@ public class FileGraphSetup implements ServletContextListener {
cleanupDB(dataset, pathsToURIs(paths, TBOX),TBOX);
OntModel tboxBaseModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS);
tboxChanged = readGraphs(paths, modelMaker, TBOX, tboxBaseModel);
tboxChanged = readGraphs(paths, rdfService, TBOX, tboxBaseModel);
} catch (ClassCastException cce) {
String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage();
log.error(errMsg);
@ -118,8 +114,7 @@ public class FileGraphSetup implements ServletContextListener {
private Set<Path> getFilegraphPaths(ServletContext ctx, String... strings) {
StartupStatus ss = StartupStatus.getBean(ctx);
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
String homeDirProperty = props.getProperty(PROPERTY_VITRO_HOME);
String homeDirProperty = ApplicationUtils.instance().getHomeDirectory().getPath().toString();
Path filegraphDir = Paths.get(homeDirProperty, strings);
Set<Path> paths = new TreeSet<>();
@ -151,7 +146,7 @@ public class FileGraphSetup implements ServletContextListener {
* Note: no connection needs to be maintained between the in-memory copy of the
* graph and the DB copy.
*/
private boolean readGraphs(Set<Path> pathSet, ModelMaker modelMaker, String type, OntModel baseModel) {
private boolean readGraphs(Set<Path> pathSet, RDFService rdfService, String type, OntModel baseModel) {
int count = 0;
@ -180,7 +175,7 @@ public class FileGraphSetup implements ServletContextListener {
log.debug("Attached file graph as " + type + " submodel " + p.getFileName());
}
modelChanged = modelChanged | updateGraphInDB(modelMaker, model, type, p);
modelChanged = modelChanged | updateGraphInDB(rdfService, model, type, p);
} catch (Exception ioe) {
log.error("Unable to process file graph " + p, ioe);
@ -214,21 +209,24 @@ public class FileGraphSetup implements ServletContextListener {
* Otherwise, if a graph with the given name is in the DB and is isomorphic with
* the graph that was read from the files system, then do nothing.
*/
public boolean updateGraphInDB(ModelMaker modelMaker, Model fileModel, String type, Path path) {
public boolean updateGraphInDB(RDFService rdfService, Model fileModel, String type, Path path) {
String graphURI = pathToURI(path,type);
Model dbModel = modelMaker.getModel(graphURI);
Model dbModel = new RDFServiceDataset(rdfService).getNamedModel(graphURI);
boolean modelChanged = false;
log.debug(String.format(
"%s %s dbModel size is %d, fileModel size is %d", type,
path.getFileName(), dbModel.size(), fileModel.size()));
boolean isIsomorphic = dbModel.isIsomorphicWith(fileModel);
// Isomorphism has some quirky issues with TDB, and perhaps also with Virtuoso.
boolean isChanged = ApplicationUtils.instance()
.getContentTripleSource().getQuirks()
.hasFileGraphChanged(fileModel, dbModel, graphURI);
if (dbModel.isEmpty() && !fileModel.isEmpty()) {
dbModel.add(fileModel);
modelChanged = true;
} else if (!isIsomorphic) {
} else if (isChanged) {
log.info("Updating " + path + " because graphs are not isomorphic");
log.info("dbModel: " + dbModel.size() + " ; fileModel: " + fileModel.size());
dbModel.removeAll();

View file

@ -13,8 +13,6 @@ import java.nio.file.Paths;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -23,7 +21,7 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
/**
* Help to load RDF files on first time and on every startup.
@ -31,7 +29,6 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
public class RDFFilesLoader {
private static final Log log = LogFactory.getLog(RDFFilesLoader.class);
private static final String PROPERTY_VITRO_HOME = "vitro.home";
private static final String DEFAULT_RDF_FORMAT = "RDF/XML";
private static final String RDF = "rdf";
private static final String FIRST_TIME = "firsttime";
@ -61,10 +58,10 @@ public class RDFFilesLoader {
*
* The files from the directory are added to the model.
*/
public static void loadFirstTimeFiles(ServletContext ctx, String modelPath,
Model model, boolean firstTime) {
public static void loadFirstTimeFiles(String modelPath, Model model,
boolean firstTime) {
if (firstTime) {
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF,
Set<Path> paths = getPaths(locateHomeDirectory(), RDF,
modelPath, FIRST_TIME);
for (Path p : paths) {
readOntologyFileIntoModel(p, model);
@ -83,11 +80,10 @@ public class RDFFilesLoader {
*
* The files from the directory become a sub-model of the model.
*/
public static void loadEveryTimeFiles(ServletContext ctx, String modelPath,
OntModel model) {
public static void loadEveryTimeFiles(String modelPath, OntModel model) {
OntModel everytimeModel = ModelFactory
.createOntologyModel(OntModelSpec.OWL_MEM);
String home = locateHomeDirectory(ctx);
String home = locateHomeDirectory();
Set<Path> paths = getPaths(home, RDF, modelPath, EVERY_TIME);
for (Path p : paths) {
log.info("Loading " + relativePath(p, home));
@ -177,9 +173,9 @@ public class RDFFilesLoader {
return DEFAULT_RDF_FORMAT;
}
private static String locateHomeDirectory(ServletContext ctx) {
return ConfigurationProperties.getBean(ctx).getProperty(
PROPERTY_VITRO_HOME);
private static String locateHomeDirectory() {
return ApplicationUtils.instance().getHomeDirectory().getPath()
.toString();
}
/**

View file

@ -13,7 +13,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@ -44,6 +43,7 @@ import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -98,7 +98,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setUnionOntModelSelector(ModelAccess.on(ctx).getOntModelSelector());
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
Path homeDir = Paths.get(props.getProperty("vitro.home"));
Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath();
settings.setDisplayModel(ModelAccess.on(ctx).getOntModel(DISPLAY));
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
settings.setOldTBoxModel(oldTBoxModel);
@ -202,8 +202,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
* Put the paths for the directories and files into the settings object.
*/
private void putReportingPathsIntoSettings(ServletContext ctx, UpdateSettings settings) throws IOException {
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
Path homeDir = Paths.get(props.getProperty("vitro.home"));
Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath();
Path dataDir = createDirectory(homeDir, "upgrade", "knowledgeBase");
settings.setDataDir(dataDir.toString());

View file

@ -1,113 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sparql.ContentDataStructuresProviderSPARQL.PROPERTY_SPARQL_ENDPOINT_URI;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb.ContentDataStructuresProviderTDB.PROPERTY_CONTENT_TDB_PATH;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntDocumentManager;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.BasicDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ConfigurationDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sparql.ContentDataStructuresProviderSPARQL;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb.ConfigurationDataStructuresProviderTDB;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb.ContentDataStructuresProviderTDB;
/**
* Create the RDFServiceFactories and ModelMakers for the application to use.
*/
public class RDFSetup implements ServletContextListener {
private static final Log log = LogFactory.getLog(RDFSetup.class);
private ServletContext ctx;
private ConfigurationProperties configProps;
private ContentDataStructuresProvider contentProvider;
private ConfigurationDataStructuresProvider configurationProvider;
private BasicDataStructuresProvider provider;
@Override
public void contextInitialized(ServletContextEvent sce) {
this.ctx = sce.getServletContext();
this.configProps = ConfigurationProperties.getBean(ctx);
configureJena();
createProviders();
RDFServiceUtils.setRDFServiceFactory(ctx,
contentProvider.getRDFServiceFactory());
RDFServiceUtils.setRDFServiceFactory(ctx,
configurationProvider.getRDFServiceFactory(), CONFIGURATION);
ModelAccess.setDataStructuresProvider(provider);
}
private void configureJena() {
// we do not want to fetch imports when we wrap Models in OntModels
OntDocumentManager.getInstance().setProcessImports(false);
}
/**
* For now, these steps are hard-coded. They should be driven by a
* configuration file.
*/
private void createProviders() {
if (isSparqlEndpointContentConfigured()) {
contentProvider = new ContentDataStructuresProviderSPARQL(ctx, this);
} else if (isTdbConfigured()) {
contentProvider = new ContentDataStructuresProviderTDB(ctx, this);
} else {
contentProvider = new ContentDataStructuresProviderSDB(ctx, this);
}
configurationProvider = new ConfigurationDataStructuresProviderTDB(ctx,
this);
provider = new BasicDataStructuresProvider(contentProvider,
configurationProvider);
}
private boolean isSparqlEndpointContentConfigured() {
return StringUtils.isNotBlank(configProps
.getProperty(PROPERTY_SPARQL_ENDPOINT_URI));
}
private boolean isTdbConfigured() {
return StringUtils.isNotBlank(configProps
.getProperty(PROPERTY_CONTENT_TDB_PATH));
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
if (contentProvider != null) {
try {
contentProvider.close();
} catch (Exception e) {
log.error("Problem when closing content provider", e);
}
}
if (configurationProvider != null) {
try {
configurationProvider.close();
} catch (Exception e) {
log.error("Problem when closing configuration provider", e);
}
}
}
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup;
package edu.cornell.mannlib.vitro.webapp.triplesource;
import javax.servlet.http.HttpServletRequest;
@ -17,11 +17,11 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
*
* Repeated calls for the same data structure should yield the same instance.
*
* Repeated calls for the ShortTermDataStructuresProvider need not yield the
* Repeated calls for the ShortTermCombinedTripleSource need not yield the
* same instance, but must yield an instance that will return the same
* structures as any other instance for the same request.
*/
public interface DataStructuresProvider {
public interface CombinedTripleSource {
RDFService getRDFService(WhichService whichService);
Dataset getDataset(WhichService whichService);
@ -30,6 +30,6 @@ public interface DataStructuresProvider {
OntModelCache getOntModelCache();
ShortTermDataStructuresProvider getShortTermDataStructuresProvider(
ShortTermCombinedTripleSource getShortTermCombinedTripleSource(
HttpServletRequest req);
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup;
package edu.cornell.mannlib.vitro.webapp.triplesource;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
@ -16,7 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
* Repeated calls for the WebappDaoFactoryConfig need not yield the same
* instance.
*/
public interface ShortTermDataStructuresProvider {
public interface ShortTermCombinedTripleSource {
RDFService getRDFService(WhichService whichService);
OntModelCache getOntModelCache();

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
@ -27,23 +27,26 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.ModelMakerOntModel
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache.UnionSpec;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
* A simple implementation of DataStructuresProvider.
* A simple implementation of CombinedTripleSource.
*
* Note that we don't bother to cache the RDFServices, RDFServiceFactories, and
* ModelMakers, since the providers can be expected to cache them.
* ModelMakers, since the sources can be expected to cache them.
*
* We must cache the OntModelCache because it was created here. If we were to
* recreate it, we would lose any sub-models that had been attached in the
* meantime.
*/
public class BasicDataStructuresProvider implements DataStructuresProvider {
public class BasicCombinedTripleSource implements CombinedTripleSource {
/**
* Create union models for ABox and TBox, and full models for assertions and
* inferences. No need to create FULL_UNION, since it's the default model.
@ -58,16 +61,15 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
UnionSpec.base(ABOX_INFERENCES).plus(TBOX_INFERENCES)
.yields(FULL_INFERENCES) };
private final Map<WhichService, SingleSourceDataStructuresProvider> providers;
private final Map<WhichService, TripleSource> sources;
private final Map<WhichService, OntModelCache> ontModels;
private final OntModelCache ontModelCache;
public BasicDataStructuresProvider(
SingleSourceDataStructuresProvider contentProvider,
SingleSourceDataStructuresProvider configurationProvider) {
providers = new EnumMap<>(WhichService.class);
providers.put(CONTENT, contentProvider);
providers.put(CONFIGURATION, configurationProvider);
public BasicCombinedTripleSource(ContentTripleSource contentSource,
ConfigurationTripleSource configurationSource) {
sources = new EnumMap<>(WhichService.class);
sources.put(CONTENT, contentSource);
sources.put(CONFIGURATION, configurationSource);
ontModels = new EnumMap<>(WhichService.class);
ontModels.put(CONTENT, new ModelMakerOntModelCache(
@ -85,22 +87,22 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
}
protected RDFServiceFactory getRDFServiceFactory(WhichService whichService) {
return providers.get(whichService).getRDFServiceFactory();
return sources.get(whichService).getRDFServiceFactory();
}
@Override
public RDFService getRDFService(WhichService whichService) {
return providers.get(whichService).getRDFService();
return sources.get(whichService).getRDFService();
}
@Override
public Dataset getDataset(WhichService whichService) {
return providers.get(whichService).getDataset();
return sources.get(whichService).getDataset();
}
@Override
public ModelMaker getModelMaker(WhichService whichService) {
return providers.get(whichService).getModelMaker();
return sources.get(whichService).getModelMaker();
}
@Override
@ -109,16 +111,15 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
}
@Override
public ShortTermDataStructuresProvider getShortTermDataStructuresProvider(
public ShortTermCombinedTripleSource getShortTermCombinedTripleSource(
HttpServletRequest req) {
return new BasicShortTermDataStructuresProvider(req, this, providers);
return new BasicShortTermCombinedTripleSource(req, this, sources);
}
@Override
public String toString() {
return "BasicDataStructuresProvider[" + ToString.hashHex(this)
+ ", providers=" + providers + ", ontModels=" + ontModelCache
+ "]";
return "BasicCombinedTripleSource[" + ToString.hashHex(this)
+ ", sources=" + sources + ", ontModels=" + ontModelCache + "]";
}
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
@ -25,39 +25,39 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.JoinedOntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
* The simple implementation of ShortTermDataStructuresProvider.
* The simple implementation of ShortTermCombinedTripleSource.
*
* The short-term RDFServices are cached, lest we somehow create duplicates for
* the same request. Similarly with the short-term OntModels.
*/
public class BasicShortTermDataStructuresProvider implements
ShortTermDataStructuresProvider {
public class BasicShortTermCombinedTripleSource implements
ShortTermCombinedTripleSource {
private static final Log log = LogFactory
.getLog(BasicShortTermDataStructuresProvider.class);
.getLog(BasicShortTermCombinedTripleSource.class);
private final HttpServletRequest req;
private final ServletContext ctx;
private final ConfigurationProperties props;
private final BasicDataStructuresProvider parent;
private final Map<WhichService, SingleSourceDataStructuresProvider> providers;
private final BasicCombinedTripleSource parent;
private final Map<WhichService, TripleSource> sources;
private final Map<WhichService, RDFService> rdfServices;
private final OntModelCache ontModelCache;
public BasicShortTermDataStructuresProvider(
HttpServletRequest req,
BasicDataStructuresProvider parent,
final Map<WhichService, SingleSourceDataStructuresProvider> providers) {
public BasicShortTermCombinedTripleSource(HttpServletRequest req,
BasicCombinedTripleSource parent,
final Map<WhichService, TripleSource> sources) {
this.req = req;
this.ctx = req.getSession().getServletContext();
this.props = ConfigurationProperties.getBean(ctx);
this.parent = parent;
this.providers = providers;
this.sources = sources;
this.rdfServices = populateRdfServicesMap();
this.ontModelCache = createOntModelCache();
}
@ -77,12 +77,12 @@ public class BasicShortTermDataStructuresProvider implements
}
/**
* Ask each provider what short-term models should mask their long-term
* Ask each triple source what short-term models should mask their long-term
* counterparts.
*/
private OntModelCache shortModels(WhichService which) {
return providers.get(which).getShortTermOntModels(
rdfServices.get(which), parent.getOntModels(which));
return sources.get(which).getShortTermOntModels(rdfServices.get(which),
parent.getOntModels(which));
}
@Override
@ -142,8 +142,8 @@ public class BasicShortTermDataStructuresProvider implements
@Override
public String toString() {
return "BasicShortTermDataStructuresProvider[" + ToString.hashHex(this)
+ ", req=" + ToString.hashHex(req) + ", providers=" + providers
return "BasicShortTermCombinedTripleSource[" + ToString.hashHex(this)
+ ", req=" + ToString.hashHex(req) + ", sources=" + sources
+ ", ontModels=" + ontModelCache + "]";
}

View file

@ -0,0 +1,19 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.triplesource.impl;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleStoreQuirks;
/**
* The behavior for non-quirky TripleSource implementations.
*/
public class DefaultTripleStoreQuirks implements TripleStoreQuirks {
@Override
public boolean hasFileGraphChanged(Model fromFile, Model previous, String graphURI) {
return !fromFile.isIsomorphicWith(previous);
}
}

View file

@ -1,14 +1,13 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.BasicDataStructuresProvider.CONTENT_UNIONS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource.CONTENT_UNIONS;
import java.sql.SQLException;
import java.util.Arrays;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
@ -36,13 +35,16 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.MaskingOntModelCac
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.ModelMakerOntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb.RDFServiceFactorySDB;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.DefaultTripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -51,10 +53,9 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
* Do some smoke-tests on the parameters, create the connection pool, and create
* the RDFServiceFactory.
*/
public class ContentDataStructuresProviderSDB extends
ContentDataStructuresProvider {
public class ContentTripleSourceSDB extends ContentTripleSource {
private static final Log log = LogFactory
.getLog(ContentDataStructuresProviderSDB.class);
.getLog(ContentTripleSourceSDB.class);
static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
static final String PROPERTY_DB_USERNAME = "VitroConnection.DataSource.username";
@ -77,33 +78,31 @@ public class ContentDataStructuresProviderSDB extends
static final boolean DEFAULT_TESTONBORROW = true;
static final boolean DEFAULT_TESTONRETURN = true;
private final TripleStoreQuirks quirks = new DefaultTripleStoreQuirks();
private final ServletContext ctx;
private final StartupStatus ss;
private final ComboPooledDataSource ds;
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
private ServletContext ctx;
private ComboPooledDataSource ds;
private RDFServiceFactory rdfServiceFactory;
private RDFService rdfService;
private Dataset dataset;
private ModelMaker modelMaker;
public ContentDataStructuresProviderSDB(ServletContext ctx,
ServletContextListener ctxListener) {
@Override
public void startup(Application application, ComponentStartupStatus ss) {
try {
this.ctx = ctx;
this.ss = StartupStatus.getBean(ctx);
this.ctx = application.getServletContext();
configureSDBContext();
new SDBConnectionSmokeTests(ctx, ctxListener)
.checkDatabaseConnection();
new SDBConnectionSmokeTests(ctx, ss).checkDatabaseConnection();
this.ds = new SDBDataSource(ctx).getDataSource();
this.rdfServiceFactory = createRdfServiceFactory();
this.rdfService = rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.rdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener,
"Initialized the content data structures for SDB");
ss.info("Initialized the content data structures for SDB");
} catch (SQLException e) {
throw new RuntimeException(
"Failed to set up the content data structures for SDB", e);
@ -211,16 +210,20 @@ public class ContentDataStructuresProviderSDB extends
}
@Override
public void close() {
public TripleStoreQuirks getQuirks() {
return quirks;
}
@Override
public String toString() {
return "ContentTripleSourceSDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
if (ds != null) {
ds.close();
}
}
@Override
public String toString() {
return "ContentDataStructuresProviderSDB[" + ToString.hashHex(this)
+ "]";
}
}

View file

@ -1,13 +1,13 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
@ -19,10 +19,9 @@ import java.sql.Statement;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
/**
* Smoke tests for the database connection that SDB will use.
@ -38,38 +37,31 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
* encoding. Don't know how well this works.
*/
public class SDBConnectionSmokeTests {
private final ServletContextListener parent;
private final ConfigurationProperties props;
private final StartupStatus ss;
private final ComponentStartupStatus ss;
public SDBConnectionSmokeTests(ServletContext ctx,
ServletContextListener parent) {
this.parent = parent;
public SDBConnectionSmokeTests(ServletContext ctx, ComponentStartupStatus ss) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
this.ss = ss;
}
public void checkDatabaseConnection() {
String url = props.getProperty(PROPERTY_DB_URL);
if (url == null || url.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_URL + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_URL + "'");
return;
}
String username = props.getProperty(PROPERTY_DB_USERNAME);
if (username == null || username.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_USERNAME + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_USERNAME + "'");
return;
}
String password = props.getProperty(PROPERTY_DB_PASSWORD);
if (password == null || password.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_PASSWORD + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_PASSWORD + "'");
return;
}
@ -79,16 +71,16 @@ public class SDBConnectionSmokeTests {
try {
Class.forName(DEFAULT_DRIVER_CLASS).newInstance();
} catch (Exception e) {
ss.fatal(parent, "The default Database Driver failed to load. "
+ "The driver class is '" + DEFAULT_DRIVER_CLASS
+ "'", e);
ss.fatal("The default Database Driver failed to load. "
+ "The driver class is '" + DEFAULT_DRIVER_CLASS + "'",
e);
return;
}
} else {
try {
Class.forName(driverClassName).newInstance();
} catch (Exception e) {
ss.fatal(parent, "The Database Driver failed to load. "
ss.fatal("The Database Driver failed to load. "
+ "The driver class was set by "
+ PROPERTY_DB_DRIVER_CLASS_NAME + " to be '"
+ driverClassName + "'", e);
@ -104,9 +96,9 @@ public class SDBConnectionSmokeTests {
.getConnection(url, connectionProps)) {
// Just open the connection and close it.
} catch (SQLException e) {
ss.fatal(parent, "Can't connect to the database: "
+ PROPERTY_DB_URL + "='" + url + "', "
+ PROPERTY_DB_USERNAME + "='" + username + "'", e);
ss.fatal("Can't connect to the database: " + PROPERTY_DB_URL + "='"
+ url + "', " + PROPERTY_DB_USERNAME + "='" + username
+ "'", e);
return;
}
@ -151,15 +143,14 @@ public class SDBConnectionSmokeTests {
+ "set on the database?";
if ("MySQL".equals(dbType)) {
// For MySQL, we know that this is a configuration problem.
ss.fatal(parent, message);
ss.fatal(message);
} else {
// For other databases, it might not be.
ss.warning(parent, message);
ss.warning(message);
}
}
} catch (SQLException e) {
ss.fatal(parent, "Failed to check handling of Unicode characters",
e);
ss.fatal("Failed to check handling of Unicode characters", e);
}
}

View file

@ -1,23 +1,23 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_MAXIDLE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TESTONBORROW;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TESTONRETURN;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.MINIMUM_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_MAX_ACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_MAX_IDLE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXIDLE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONBORROW;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONRETURN;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.MINIMUM_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_ACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_VALIDATION_QUERY;
import java.beans.PropertyVetoException;

View file

@ -1,26 +1,27 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sparql;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sparql;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.DefaultTripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -33,44 +34,61 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
*
* Memory-map the small content models, and add the standard decorators.
*/
public class ContentDataStructuresProviderSPARQL extends
ContentDataStructuresProvider {
public static final String PROPERTY_SPARQL_ENDPOINT_URI = "VitroConnection.DataSource.endpointURI";
public static final String PROPERTY_SPARQL_UPDATE_ENDPOINT_URI = "VitroConnection.DataSource.updateEndpointURI";
public class ContentTripleSourceSPARQL extends ContentTripleSource {
private String endpointURI;
private String updateEndpointURI; // Optional
private final TripleStoreQuirks quirks = new DefaultTripleStoreQuirks();
private final ServletContextListener ctxListener;
private final ConfigurationProperties props;
private final StartupStatus ss;
private final String endpointURI;
private final String updateEndpointURI;
private RDFService rdfService;
private RDFServiceFactory rdfServiceFactory;
private Dataset dataset;
private ModelMaker modelMaker;
private final RDFService rdfService;
private final RDFServiceFactory rdfServiceFactory;
private final Dataset dataset;
private final ModelMaker modelMaker;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasEndpointURI")
public void setEndpointURI(String eUri) {
if (endpointURI == null) {
endpointURI = eUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of EndpointURI: "
+ endpointURI + ", and " + eUri);
}
}
public ContentDataStructuresProviderSPARQL(ServletContext ctx,
ServletContextListener ctxListener) {
this.ctxListener = ctxListener;
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUpdateEndpointURI")
public void setUpdateEndpointURI(String ueUri) {
if (updateEndpointURI == null) {
updateEndpointURI = ueUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of UpdateEndpointURI: "
+ updateEndpointURI + ", and " + ueUri);
}
}
this.endpointURI = props.getProperty(PROPERTY_SPARQL_ENDPOINT_URI);
this.updateEndpointURI = props
.getProperty(PROPERTY_SPARQL_UPDATE_ENDPOINT_URI);
@Validation
public void validate() throws Exception {
if (endpointURI == null) {
throw new IllegalStateException(
"Configuration did not include an EndpointURI.");
}
}
this.rdfServiceFactory = createRDFServiceFactory(createRDFService());
@Override
public void startup(Application application, ComponentStartupStatus ss) {
this.rdfServiceFactory = createRDFServiceFactory(createRDFService(ss));
this.rdfService = this.rdfServiceFactory.getRDFService();
this.dataset = createDataset();
this.modelMaker = createModelMaker();
}
private RDFService createRDFService() {
private RDFService createRDFService(ComponentStartupStatus ss) {
if (updateEndpointURI == null) {
ss.info(ctxListener, "Using endpoint at " + endpointURI);
ss.info("Using endpoint at " + endpointURI);
return new RDFServiceSparql(endpointURI);
} else {
ss.info(ctxListener, "Using read endpoint at " + endpointURI
ss.info("Using read endpoint at " + endpointURI
+ " and update endpoint at " + updateEndpointURI);
return new RDFServiceSparql(endpointURI, updateEndpointURI);
}
@ -119,17 +137,22 @@ public class ContentDataStructuresProviderSPARQL extends
}
@Override
public void close() {
public TripleStoreQuirks getQuirks() {
return quirks;
}
@Override
public String toString() {
return "ContentTripleSourceSPARQL[" + ToString.hashHex(this)
+ ", endpointURI=" + endpointURI + ", updateEndpointURI="
+ updateEndpointURI + "]";
}
@Override
public void shutdown(Application application) {
if (this.rdfService != null) {
this.rdfService.close();
}
}
@Override
public String toString() {
return "ContentDataStructuresProviderSPARQL[" + ToString.hashHex(this)
+ ", endpointURI=" + endpointURI + ", updateEndpointURI="
+ updateEndpointURI + "]";
}
}

View file

@ -1,30 +1,29 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.tdb;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import java.nio.file.Path;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.tdb.TDB;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceTDB;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ConfigurationDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -35,37 +34,37 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
* returns that single RDFService, a single instance of the Dataset and the
* ModelMaker.
*
* We keep a copy of the RDFService wrapped in an Unclosable shell, and hand
* that out when requested. The inner RDFService is only closed on shutdown().
*
* Memory-map all of the configuration models, and add the standard decorators.
*/
public class ConfigurationDataStructuresProviderTDB extends
ConfigurationDataStructuresProvider {
public class ConfigurationTripleSourceTDB extends ConfigurationTripleSource {
private static final String DIRECTORY_TDB = "tdbModels";
private final ConfigurationProperties props;
private final StartupStatus ss;
private final TripleStoreQuirks quirks = new TDBTripleStoreQuirks();
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
public ConfigurationDataStructuresProviderTDB(ServletContext ctx,
ServletContextListener ctxListener) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
private volatile RDFService rdfService;
private RDFServiceFactory rdfServiceFactory;
private RDFService unclosableRdfService;
private Dataset dataset;
private ModelMaker modelMaker;
@Override
public void startup(Application application, ComponentStartupStatus ss) {
configureTDB();
String tdbPath = props.getProperty("vitro.home") + File.separatorChar
+ DIRECTORY_TDB;
Path vitroHome = ApplicationUtils.instance().getHomeDirectory()
.getPath();
String tdbPath = vitroHome.resolve(DIRECTORY_TDB).toString();
try {
this.rdfServiceFactory = createRDFServiceFactory(tdbPath);
this.rdfService = this.rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.rdfService);
this.rdfService = new RDFServiceTDB(tdbPath);
this.rdfServiceFactory = createRDFServiceFactory();
this.unclosableRdfService = this.rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.unclosableRdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener, "Initialized the RDF source for TDB");
ss.info("Initialized the RDF source for TDB");
} catch (IOException e) {
throw new RuntimeException(
"Failed to set up the RDF source for TDB", e);
@ -76,16 +75,15 @@ public class ConfigurationDataStructuresProviderTDB extends
TDB.getContext().setTrue(TDB.symUnionDefaultGraph);
}
private RDFServiceFactory createRDFServiceFactory(String tdbPath)
throws IOException {
private RDFServiceFactory createRDFServiceFactory() {
return new LoggingRDFServiceFactory(new RDFServiceFactorySingle(
new RDFServiceTDB(tdbPath)));
this.rdfService));
}
private ModelMaker createModelMaker() {
ModelMaker longTermModelMaker = new ListCachingModelMaker(
new MemoryMappingModelMaker(new RDFServiceModelMaker(
this.rdfService), CONFIGURATION_MODELS));
this.unclosableRdfService), CONFIGURATION_MODELS));
return addConfigurationDecorators(longTermModelMaker);
}
@ -96,7 +94,7 @@ public class ConfigurationDataStructuresProviderTDB extends
@Override
public RDFService getRDFService() {
return this.rdfService;
return this.unclosableRdfService;
}
@Override
@ -117,15 +115,23 @@ public class ConfigurationDataStructuresProviderTDB extends
}
@Override
public void close() {
if (this.rdfService != null) {
this.rdfService.close();
}
public TripleStoreQuirks getQuirks() {
return quirks;
}
@Override
public String toString() {
return "ConfigurationDataStructuresProviderTDB["
+ ToString.hashHex(this) + "]";
return "ConfigurationTripleSourceTDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
synchronized (this) {
if (this.rdfService != null) {
this.rdfService.close();
this.rdfService = null;
}
}
}
}

View file

@ -1,29 +1,29 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.tdb;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.tdb.TDB;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleStoreQuirks;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceTDB;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -34,36 +34,51 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
* returns that single RDFService, a single instance of the Dataset and the
* ModelMaker.
*
* We keep a copy of the RDFService wrapped in an Unclosable shell, and hand
* that out when requested. The inner RDFService is only closed on shutdown().
*
* Memory-map the small content models, and add the standard decorators.
*/
public class ContentDataStructuresProviderTDB extends
ContentDataStructuresProvider {
public class ContentTripleSourceTDB extends ContentTripleSource {
private final TripleStoreQuirks quirks = new TDBTripleStoreQuirks();
public static final String PROPERTY_CONTENT_TDB_PATH = "VitroConnection.DataSource.tdbDirectory";
private String tdbPath;
private final ConfigurationProperties props;
private final StartupStatus ss;
private volatile RDFService rdfService;
private RDFServiceFactory rdfServiceFactory;
private RDFService unclosableRdfService;
private Dataset dataset;
private ModelMaker modelMaker;
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTdbDirectory")
public void setTdbPath(String path) {
if (tdbPath == null) {
tdbPath = path;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of TdbDirectory: "
+ tdbPath + ", and " + path);
}
}
public ContentDataStructuresProviderTDB(ServletContext ctx,
ServletContextListener ctxListener) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
@Validation
public void validate() throws Exception {
if (tdbPath == null) {
throw new IllegalStateException(
"Configuration did not include a TdbDirectory.");
}
}
@Override
public void startup(Application application, ComponentStartupStatus ss) {
configureTDB();
String tdbPath = props.getProperty(PROPERTY_CONTENT_TDB_PATH);
try {
this.rdfService = new RDFServiceTDB(tdbPath);
this.rdfServiceFactory = createRDFServiceFactory();
this.dataset = new RDFServiceDataset(this.rdfService);
this.unclosableRdfService = this.rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.unclosableRdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener, "Initialized the RDF source for TDB");
ss.info("Initialized the RDF source for TDB");
} catch (IOException e) {
throw new RuntimeException(
"Failed to set up the RDF source for TDB", e);
@ -82,7 +97,7 @@ public class ContentDataStructuresProviderTDB extends
private ModelMaker createModelMaker() {
return addContentDecorators(new ListCachingModelMaker(
new MemoryMappingModelMaker(new RDFServiceModelMaker(
this.rdfService), SMALL_CONTENT_MODELS)));
this.unclosableRdfService), SMALL_CONTENT_MODELS)));
}
@Override
@ -92,7 +107,7 @@ public class ContentDataStructuresProviderTDB extends
@Override
public RDFService getRDFService() {
return this.rdfService;
return this.unclosableRdfService;
}
@Override
@ -113,16 +128,22 @@ public class ContentDataStructuresProviderTDB extends
}
@Override
public void close() {
if (this.rdfService != null) {
this.rdfService.close();
}
public TripleStoreQuirks getQuirks() {
return quirks;
}
@Override
public String toString() {
return "ContentDataStructuresProviderTDB[" + ToString.hashHex(this)
+ "]";
return "ContentTripleSourceTDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
synchronized (this) {
if (this.rdfService != null) {
this.rdfService.close();
this.rdfService = null;
}
}
}
}

View file

@ -0,0 +1,58 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.tdb;
import static com.hp.hpl.jena.datatypes.xsd.XSDDatatype.XSDinteger;
import static com.hp.hpl.jena.datatypes.xsd.XSDDatatype.XSDnonNegativeInteger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.DefaultTripleStoreQuirks;
/**
* TDB has some odd behaviors to deal with.
*/
public class TDBTripleStoreQuirks extends DefaultTripleStoreQuirks {
private static final Log log = LogFactory
.getLog(TDBTripleStoreQuirks.class);
/**
* When the file graph was previously written to the TDB store, TDB mangled
* some of the literal types: any type of XMLSchema#nonNegativeInteger was
* changed to XMLSchema#integer.
*
* We need to mangle our new model in the same way before comparing to the
* previous one.
*/
@Override
public boolean hasFileGraphChanged(Model fromFile, Model previous,
String graphURI) {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
fromFile.write(buffer, "N-TRIPLE");
String fromString = buffer.toString("UTF-8");
String mangleString = fromString.replace(
XSDnonNegativeInteger.getURI(), XSDinteger.getURI());
InputStream mangleStream = new ByteArrayInputStream(
mangleString.getBytes("UTF-8"));
Model mangled = ModelFactory.createDefaultModel();
mangled.read(mangleStream, null, "N-TRIPLE");
return !mangled.isIsomorphicWith(previous);
} catch (Exception e) {
log.warn("Failed to test for changes in filegraph. "
+ "Change assumed.", e);
return true;
}
}
}

View file

@ -5,7 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.utils.developer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashMap;
@ -20,7 +20,7 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
@ -194,12 +194,10 @@ public class DeveloperSettings {
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
ConfigurationProperties props = ConfigurationProperties
.getBean(ctx);
DeveloperSettings devSettings = DeveloperSettings.getInstance();
String home = props.getProperty("vitro.home");
File dsFile = Paths.get(home, "developer.properties").toFile();
Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath();
File dsFile = homeDir.resolve("developer.properties").toFile();
try (FileReader reader = new FileReader(dsFile)) {
Properties dsProps = new Properties();

View file

@ -124,8 +124,9 @@ public class StackTraceUtility {
StringBuilder sb = new StringBuilder();
if (requested) {
for (StackTraceElement ste : stackTrace) {
sb.append(String.format(" line %4d, %s \n",
ste.getLineNumber(), ste.getClassName()));
sb.append(String.format(" %s.%s(%s:%d) \n",
ste.getClassName(), ste.getMethodName(),
ste.getFileName(), ste.getLineNumber()));
}
sb.append(" ...\n");
}

View file

@ -2,9 +2,9 @@
package edu.cornell.mannlib.vitro.testing;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;

View file

@ -5,9 +5,9 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy;
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.AUTHORIZED;
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.INCONCLUSIVE;
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction.SOME_LITERAL;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;

View file

@ -4,7 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.config;
import static edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean.DUMMY_BEAN;
import static edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean.LevelRevisionInfo.DUMMY_LEVEL;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Date;

View file

@ -5,8 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.individual;
import static edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.N3_MIMETYPE;
import static edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.RDFXML_MIMETYPE;
import static edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.TTL_MIMETYPE;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.URL;

View file

@ -3,7 +3,7 @@
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction.SOME_URI;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;

View file

@ -2,6 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW;
import static org.junit.Assert.assertEquals;
@ -9,6 +10,7 @@ import org.junit.Before;
import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.beans.IndividualStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
@ -16,8 +18,6 @@ import com.hp.hpl.jena.rdf.model.Statement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchInputDocument;
@ -38,27 +38,29 @@ public class NameFieldsTest {
doc = new BaseSearchInputDocument();
RDFServiceModel rdfService = new RDFServiceModel(baseModel);
RDFServiceFactory rdfServiceFactory = new RDFServiceFactorySingle(
rdfService);
nameFields = new NameFields(rdfServiceFactory);
ContextModelAccessStub models = new ContextModelAccessStub();
models.setRDFService(CONTENT, rdfService);
nameFields = new NameFields();
nameFields.setContextModels(models);
}
@Test
public void nullIndividual() throws SkipIndividualException {
public void nullIndividual() {
SearchInputDocument expected = new BaseSearchInputDocument(doc);
assertResultingSearchDocument(null, expected);
}
@Test
public void nullUri() throws SkipIndividualException {
public void nullUri() {
SearchInputDocument expected = new BaseSearchInputDocument(doc);
assertResultingSearchDocument(new IndividualStub(null), expected);
}
@Test
public void foundNoLabels() throws SkipIndividualException {
public void foundNoLabels() {
SearchInputDocument expected = new BaseSearchInputDocument(doc);
expected.addField(NAME_RAW, "");
@ -67,7 +69,7 @@ public class NameFieldsTest {
}
@Test
public void foundOneLabel() throws SkipIndividualException {
public void foundOneLabel() {
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label1"));
SearchInputDocument expected = new BaseSearchInputDocument(doc);
@ -78,7 +80,7 @@ public class NameFieldsTest {
}
@Test
public void foundTwoLabels() throws SkipIndividualException {
public void foundTwoLabels() {
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label1"));
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label2"));
@ -100,7 +102,7 @@ public class NameFieldsTest {
}
private void assertResultingSearchDocument(Individual ind,
SearchInputDocument expected) throws SkipIndividualException {
SearchInputDocument expected) {
nameFields.modifyDocument(ind, doc);
assertEquals(expected, doc);
}

View file

@ -4,6 +4,8 @@
*/
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
import java.io.InputStream;
import org.apache.log4j.Level;
@ -11,6 +13,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub;
import stubs.javax.servlet.ServletContextStub;
@ -25,13 +28,11 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
public class ThumbnailImageURLTest extends AbstractTestClass{
RDFServiceFactory testRDF;
ContextModelAccessStub contextModels;
String personsURI = "http://vivo.cornell.edu/individual/individual8803";
/**
@ -45,7 +46,8 @@ public class ThumbnailImageURLTest extends AbstractTestClass{
Model model = ModelFactory.createDefaultModel();
InputStream in = ThumbnailImageURLTest.class.getResourceAsStream("testPerson.n3");
model.read(in,"","N3");
testRDF = new RDFServiceFactorySingle( new RDFServiceModel( model ) );
contextModels = new ContextModelAccessStub();
contextModels.setRDFService(CONTENT, new RDFServiceModel( model ));
}
/**
@ -55,7 +57,8 @@ public class ThumbnailImageURLTest extends AbstractTestClass{
@Test
public void testThumbnailFieldCreatedInSearchDoc() {
SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument();
ThumbnailImageURL testMe = new ThumbnailImageURL( testRDF );
ThumbnailImageURL testMe = new ThumbnailImageURL();
testMe.setContextModels(contextModels);
Individual ind = new IndividualImpl();
ind.setURI(personsURI);

View file

@ -2,8 +2,8 @@
package freemarker.ext.dump;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.StringReader;
import java.io.StringWriter;

View file

@ -2,8 +2,8 @@
package freemarker.ext.dump;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.StringReader;

View file

@ -3,7 +3,9 @@
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption.ASSERTIONS_AND_INFERENCES;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
@ -30,6 +32,7 @@ public class ContextModelAccessStub implements ContextModelAccess {
// ----------------------------------------------------------------------
private final Map<ReasoningOption, WebappDaoFactory> wadfMap = new HashMap<>();
private final Map<WhichService, RDFService> rdfServiceMap = new EnumMap<>(WhichService.class);
public void setWebappDaoFactory(WebappDaoFactory wadf) {
setWebappDaoFactory(wadf, ASSERTIONS_AND_INFERENCES);
@ -39,6 +42,10 @@ public class ContextModelAccessStub implements ContextModelAccess {
ReasoningOption option) {
wadfMap.put(option, wadf);
}
public void setRDFService(WhichService which, RDFService rdfService) {
rdfServiceMap.put(which, rdfService);
}
// ----------------------------------------------------------------------
// Stub methods
@ -49,22 +56,20 @@ public class ContextModelAccessStub implements ContextModelAccess {
return wadfMap.get(ASSERTIONS_AND_INFERENCES);
}
@Override
public RDFService getRDFService() {
return getRDFService(CONTENT);
}
@Override
public RDFService getRDFService(WhichService which) {
return rdfServiceMap.get(which);
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public RDFService getRDFService() {
throw new RuntimeException(
"ContextModelAccessStub.getRDFService() not implemented.");
}
@Override
public RDFService getRDFService(WhichService which) {
throw new RuntimeException(
"ContextModelAccessStub.getRDFService() not implemented.");
}
@Override
public Dataset getDataset() {
throw new RuntimeException(

View file

@ -7,10 +7,13 @@ import java.lang.reflect.Field;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.fileStorage.FileStorage;
import edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
/**
* TODO
@ -61,6 +64,12 @@ public class ApplicationStub implements Application {
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public VitroHomeDirectory getHomeDirectory() {
throw new RuntimeException(
"ApplicationStub.getHomeDirectory() not implemented.");
}
@Override
public ImageProcessor getImageProcessor() {
throw new RuntimeException(
@ -74,4 +83,22 @@ public class ApplicationStub implements Application {
"ApplicationStub.getFileStorage() not implemented.");
}
@Override
public void shutdown() {
throw new RuntimeException(
"ApplicationStub.shutdown() not implemented.");
}
@Override
public ContentTripleSource getContentTripleSource() {
throw new RuntimeException(
"ApplicationStub.getContentTripleSource() not implemented.");
}
@Override
public ConfigurationTripleSource getConfigurationTripleSource() {
throw new RuntimeException(
"ApplicationStub.getConfigurationTripleSource() not implemented.");
}
}

View file

@ -7,7 +7,7 @@
<nav role="navigation">
<ul id="main-nav" role="list">
<#list menu.items as item>
<li role="listitem"><a href="${item.url}" <#if item.active> class="selected" </#if> title="${i18n().menu_item}">${item.linkText}</a></li>
<li role="listitem"><a href="${item.url}" <#if item.active> class="selected" </#if> title="${item.linkText!} ${i18n().menu_item}">${item.linkText}</a></li>
</#list>
</ul>
</nav>

View file

@ -7,6 +7,8 @@
edu.cornell.mannlib.vitro.webapp.servlet.setup.JvmSmokeTests
edu.cornell.mannlib.vitro.webapp.application.ApplicationSetup
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSetup
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests
@ -16,15 +18,12 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.GuardAgainstUnmigratedRDB
edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings$Setup
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$Setup
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$ComponentsSetup
edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup
edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup
# In 1.8, this should replace JenaPersistentDataSourceSetup, RDFServiceSetup, and maybe more.
edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.RDFSetup
edu.cornell.mannlib.vitro.webapp.servlet.setup.ConfigurationModelsSetup
edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup

View file

@ -872,6 +872,7 @@ local_name = Local Name
group_capitalized = Group
domain_class = Domain Class
range_class = Range Class
range_data_type = Range Data Type
sub_properties = Subproperties
subproperty = subproperty

View file

@ -46,6 +46,13 @@
// this.toggleSpan = $('span#propsToggle');
// this.toggleLink = $('span#propsToggle').find('a');
noProps = new Boolean;
this.range = ""
if ( propertyType == "object" ) {
this.range = i18nStrings.rangeClass;
}
else {
this.range = i18nStrings.rangeDataType;
}
},
bindEventListeners: function() {
@ -148,7 +155,7 @@
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>" + i18nStrings.domainClass + ":</td><td>"
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>" + i18nStrings.rangeClass + ":</span>"
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>" + objectPropHierarchyUtils.range + ":</span>"
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
if ( descendants.length > 1 ) {
@ -209,7 +216,7 @@
childDetails += "<tr><td class='classDetail'>" + i18nStrings.domainClass + ":</td><td>"
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
childDetails += "<span class='rangeClass'>" + i18nStrings.rangeClass + ":</span>"
childDetails += "<span class='rangeClass'>" + objectPropHierarchyUtils.range + ":</span>"
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
if ( this.children ) {
@ -300,7 +307,7 @@
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>" + i18nStrings.domainClass + ":</td><td>"
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>" + i18nStrings.rangeClass + ":</span>"
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>" + objectPropHierarchyUtils.range + ":</span>"
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
objectPropHierarchyUtils.classHtml += "</table>";

View file

@ -45,6 +45,7 @@
</section>
<script language="javascript" type="text/javascript" >
var json = [${jsonTree!}];
var propertyType = '${propType}';
var i18nStrings = {
hideProperties: '${i18n().hide_properties}',
showProperties: '${i18n().show_properties}',
@ -52,6 +53,7 @@
groupString: '${i18n().group_capitalized}',
domainClass: '${i18n().domain_class}',
rangeClass: '${i18n().range_class}',
rangeDataType: '${i18n().range_data_type}',
expandAll: '${i18n().expand_all}',
collapseAll: '${i18n().collapse_all}',
subProperties: '${i18n().sub_properties}',