Merge branch 'develop' of https://github.com/vivo-project/Vitro into develop

This commit is contained in:
brianjlowe 2013-05-22 15:03:54 -04:00
commit d65d4109fa
36 changed files with 171 additions and 240 deletions

View file

@ -10,6 +10,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -101,13 +102,7 @@ public class LoginStatusBean {
} }
ServletContext ctx = session.getServletContext(); ServletContext ctx = session.getServletContext();
WebappDaoFactory wadf = (WebappDaoFactory) ctx WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
if (wadf == null) {
log.error("No WebappDaoFactory");
return null;
}
UserAccountsDao userAccountsDao = wadf.getUserAccountsDao(); UserAccountsDao userAccountsDao = wadf.getUserAccountsDao();
if (userAccountsDao == null) { if (userAccountsDao == null) {
log.error("No UserAccountsDao"); log.error("No UserAccountsDao");

View file

@ -175,18 +175,12 @@ public class BaseEditController extends VitroHttpServlet {
} }
protected WebappDaoFactory getWebappDaoFactory(VitroRequest vreq) { protected WebappDaoFactory getWebappDaoFactory() {
WebappDaoFactory wadf = (WebappDaoFactory) getServletContext().getAttribute( return ModelAccess.on(getServletContext()).getBaseWebappDaoFactory();
"assertionsWebappDaoFactory");
if (wadf == null) {
log.info("Using vreq.getFullWebappDaoFactory()");
wadf = vreq.getFullWebappDaoFactory();
}
return wadf;
} }
protected WebappDaoFactory getWebappDaoFactory(VitroRequest vreq, String userURI) { protected WebappDaoFactory getWebappDaoFactory(String userURI) {
return getWebappDaoFactory(vreq).getUserAwareDaoFactory(userURI); return getWebappDaoFactory().getUserAwareDaoFactory(userURI);
} }
public String getDefaultLandingPage(HttpServletRequest request) { public String getDefaultLandingPage(HttpServletRequest request) {

View file

@ -6,6 +6,7 @@ import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundleFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundleFactory;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -24,16 +25,7 @@ public abstract class BaseIdentifierBundleFactory implements
throw new NullPointerException("ctx may not be null."); throw new NullPointerException("ctx may not be null.");
} }
this.ctx = ctx; this.ctx = ctx;
this.wdf = ModelAccess.on(ctx).getWebappDaoFactory();
Object wdfObject = ctx.getAttribute("webappDaoFactory");
if (wdfObject instanceof WebappDaoFactory) {
this.wdf = (WebappDaoFactory) wdfObject;
} else {
throw new IllegalStateException(
"Didn't find a WebappDaoFactory in the context. Found '"
+ wdfObject + "' instead.");
}
this.uaDao = wdf.getUserAccountsDao(); this.uaDao = wdf.getUserAccountsDao();
this.indDao = wdf.getIndividualDao(); this.indDao = wdf.getIndividualDao();
} }

View file

@ -273,8 +273,7 @@ public class PermissionSetsLoader implements ServletContextListener {
this.ctx = ctx; this.ctx = ctx;
this.ss = ss; this.ss = ss;
WebappDaoFactory wadf = (WebappDaoFactory) ctx WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
if (wadf == null) { if (wadf == null) {
throw new IllegalStateException( throw new IllegalStateException(
"No webappDaoFactory on the servlet context"); "No webappDaoFactory on the servlet context");

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.auth.policy; package edu.cornell.mannlib.vitro.webapp.auth.policy;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -23,8 +21,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
@ -79,7 +77,8 @@ public class RootUserPolicy implements PolicyIface {
ss = StartupStatus.getBean(ctx); ss = StartupStatus.getBean(ctx);
try { try {
uaDao = getUserAccountsDao(); uaDao = ModelAccess.on(ctx).getWebappDaoFactory()
.getUserAccountsDao();
configuredRootUser = getRootEmailFromConfig(); configuredRootUser = getRootEmailFromConfig();
otherRootUsers = getEmailsOfAllRootUsers(); otherRootUsers = getEmailsOfAllRootUsers();
@ -105,16 +104,6 @@ public class RootUserPolicy implements PolicyIface {
} }
} }
private UserAccountsDao getUserAccountsDao() {
WebappDaoFactory wadf = (WebappDaoFactory) ctx
.getAttribute("webappDaoFactory");
if (wadf == null) {
throw new IllegalStateException(
"No webappDaoFactory on the servlet context");
}
return wadf.getUserAccountsDao();
}
private String getRootEmailFromConfig() { private String getRootEmailFromConfig() {
String email = ConfigurationProperties.getBean(ctx).getProperty( String email = ConfigurationProperties.getBean(ctx).getProperty(
PROPERTY_ROOT_USER_EMAIL); PROPERTY_ROOT_USER_EMAIL);

View file

@ -59,8 +59,7 @@ public abstract class AbstractPageHandler {
userAccountsModel = ModelAccess.on(ctx).getUserAccountsModel(); userAccountsModel = ModelAccess.on(ctx).getUserAccountsModel();
unionModel = ModelAccess.on(ctx).getOntModel(ModelID.UNION_FULL); unionModel = ModelAccess.on(ctx).getOntModel(ModelID.UNION_FULL);
WebappDaoFactory wdf = (WebappDaoFactory) this.ctx WebappDaoFactory wdf = ModelAccess.on(ctx).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
userAccountsDao = wdf.getUserAccountsDao(); userAccountsDao = wdf.getUserAccountsDao();
vclassDao = wdf.getVClassDao(); vclassDao = wdf.getVClassDao();
indDao = wdf.getIndividualDao(); indDao = wdf.getIndividualDao();

View file

@ -71,13 +71,9 @@ public class VitroRequest extends HttpServletRequestWrapper {
setAttribute("unfilteredRDFService", rdfService); setAttribute("unfilteredRDFService", rdfService);
} }
public void setWebappDaoFactory( WebappDaoFactory wdf){
setAttribute("webappDaoFactory",wdf);
}
/** gets WebappDaoFactory with appropriate filtering for the request */ /** gets WebappDaoFactory with appropriate filtering for the request */
public WebappDaoFactory getWebappDaoFactory(){ public WebappDaoFactory getWebappDaoFactory(){
return (WebappDaoFactory) getAttribute("webappDaoFactory"); return ModelAccess.on(this).getWebappDaoFactory();
} }
public void setUnfilteredWebappDaoFactory(WebappDaoFactory wdf) { public void setUnfilteredWebappDaoFactory(WebappDaoFactory wdf) {
@ -92,10 +88,6 @@ public class VitroRequest extends HttpServletRequestWrapper {
return (WebappDaoFactory) getAttribute("unfilteredWebappDaoFactory"); return (WebappDaoFactory) getAttribute("unfilteredWebappDaoFactory");
} }
public void setFullWebappDaoFactory(WebappDaoFactory wdf) {
setAttribute("fullWebappDaoFactory", wdf);
}
public Dataset getDataset() { public Dataset getDataset() {
return (Dataset) getAttribute("dataset"); return (Dataset) getAttribute("dataset");
} }
@ -106,51 +98,12 @@ public class VitroRequest extends HttpServletRequestWrapper {
/** gets assertions + inferences WebappDaoFactory with no filtering **/ /** gets assertions + inferences WebappDaoFactory with no filtering **/
public WebappDaoFactory getFullWebappDaoFactory() { public WebappDaoFactory getFullWebappDaoFactory() {
Object webappDaoFactoryAttr = _req.getAttribute("fullWebappDaoFactory"); return ModelAccess.on(this).getWebappDaoFactory();
if (webappDaoFactoryAttr instanceof WebappDaoFactory) {
return (WebappDaoFactory) webappDaoFactoryAttr;
} else {
webappDaoFactoryAttr = _req.getSession().getAttribute("webappDaoFactory");
if (webappDaoFactoryAttr instanceof WebappDaoFactory) {
return (WebappDaoFactory) webappDaoFactoryAttr;
} else {
return (WebappDaoFactory) _req.getSession().getServletContext().getAttribute("webappDaoFactory");
}
}
} }
/** gets assertions-only WebappDaoFactory with no filtering */ /** gets assertions-only WebappDaoFactory with no filtering */
public WebappDaoFactory getAssertionsWebappDaoFactory() { public WebappDaoFactory getAssertionsWebappDaoFactory() {
Object webappDaoFactoryAttr = _req.getSession().getAttribute("assertionsWebappDaoFactory"); return ModelAccess.on(this).getBaseWebappDaoFactory();
if (webappDaoFactoryAttr instanceof WebappDaoFactory) {
log.debug("Returning assertionsWebappDaoFactory from session");
return (WebappDaoFactory) webappDaoFactoryAttr;
} else {
webappDaoFactoryAttr = getAttribute("assertionsWebappDaoFactory");
if (webappDaoFactoryAttr instanceof WebappDaoFactory) {
log.debug("returning assertionsWebappDaoFactory from request attribute");
return (WebappDaoFactory) webappDaoFactoryAttr;
} else {
log.debug("Returning assertionsWebappDaoFactory from context");
return (WebappDaoFactory) _req.getSession().getServletContext().getAttribute("assertionsWebappDaoFactory");
}
}
}
/** gets assertions-only WebappDaoFactory with no filtering */
public void setAssertionsWebappDaoFactory(WebappDaoFactory wadf) {
setAttribute("assertionsWebappDaoFactory", wadf);
}
/** gets inferences-only WebappDaoFactory with no filtering */
public WebappDaoFactory getDeductionsWebappDaoFactory() {
Object webappDaoFactoryAttr = _req.getSession().getAttribute("deductionsWebappDaoFactory");
if (webappDaoFactoryAttr instanceof WebappDaoFactory) {
return (WebappDaoFactory) webappDaoFactoryAttr;
} else {
return (WebappDaoFactory) _req.getSession().getServletContext().getAttribute("deductionsWebappDaoFactory");
}
} }
//Method that retrieves write model, returns special model in case of write model //Method that retrieves write model, returns special model in case of write model
@ -167,20 +120,18 @@ public class VitroRequest extends HttpServletRequestWrapper {
return ModelAccess.on(this).getOntModelSelector(); return ModelAccess.on(this).getOntModelSelector();
} }
public void setJenaOntModel(OntModel ontModel) {
ModelAccess.on(this).setJenaOntModel(ontModel);
}
public OntModel getJenaOntModel() { public OntModel getJenaOntModel() {
return ModelAccess.on(this).getJenaOntModel(); return ModelAccess.on(this).getJenaOntModel();
} }
/** JB - surprising that this comes from session. */
public OntModel getAssertionsOntModel() { public OntModel getAssertionsOntModel() {
return ModelAccess.on(this).getBaseOntModel(); return ModelAccess.on(this.getSession()).getBaseOntModel();
} }
/** JB - surprising that this comes from session. */
public OntModel getInferenceOntModel() { public OntModel getInferenceOntModel() {
return ModelAccess.on(this).getInferenceOntModel(); return ModelAccess.on(this.getSession()).getInferenceOntModel();
} }
public OntModel getDisplayModel(){ public OntModel getDisplayModel(){

View file

@ -25,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate; import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginEvent;
@ -302,14 +303,7 @@ public class BasicAuthenticator extends Authenticator {
} }
ServletContext servletContext = session.getServletContext(); ServletContext servletContext = session.getServletContext();
WebappDaoFactory wadf = (WebappDaoFactory) servletContext return ModelAccess.on(servletContext).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
if (wadf == null) {
log.error("no WebappDaoFactory");
return null;
}
return wadf;
} }
@Override @Override

View file

@ -79,8 +79,7 @@ public class EntityRetryController extends BaseEditController {
} }
LoginStatusBean loginBean = LoginStatusBean.getBean(request); LoginStatusBean loginBean = LoginStatusBean.getBean(request);
WebappDaoFactory myWebappDaoFactory = getWebappDaoFactory( WebappDaoFactory myWebappDaoFactory = getWebappDaoFactory(loginBean.getUserURI());
vreq, loginBean.getUserURI());
IndividualDao ewDao = myWebappDaoFactory.getIndividualDao(); IndividualDao ewDao = myWebappDaoFactory.getIndividualDao();
epo.setDataAccessObject(ewDao); epo.setDataAccessObject(ewDao);

View file

@ -27,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
@ -52,8 +53,8 @@ public class ClassHierarchyListingController extends BaseEditController {
try { try {
boolean inferred = (vrequest.getParameter("inferred") != null); boolean inferred = (vrequest.getParameter("inferred") != null);
if (vrequest.getAssertionsWebappDaoFactory() != null && !inferred) { if (!inferred) {
vcDao = vrequest.getAssertionsWebappDaoFactory().getVClassDao(); vcDao = ModelAccess.on(vrequest).getBaseWebappDaoFactory().getVClassDao();
} else { } else {
vcDao = vrequest.getFullWebappDaoFactory().getVClassDao(); vcDao = vrequest.getFullWebappDaoFactory().getVClassDao();
} }

View file

@ -17,6 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
@ -200,7 +201,7 @@ public class DeletePropertyController extends FreemarkerHttpServlet {
Individual object = EditConfigurationUtils.getIndividual(vreq, objectUri); Individual object = EditConfigurationUtils.getIndividual(vreq, objectUri);
if(object == null) { if(object == null) {
WebappDaoFactory wadf = (WebappDaoFactory) vreq.getSession().getServletContext().getAttribute("webappDaoFactory"); WebappDaoFactory wadf = ModelAccess.on(vreq.getSession().getServletContext()).getWebappDaoFactory();
object = wadf.getIndividualDao().getIndividualByURI(objectUri); object = wadf.getIndividualDao().getIndividualByURI(objectUri);
} }

View file

@ -2,7 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.dao; package edu.cornell.mannlib.vitro.webapp.dao;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -24,29 +24,26 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
* *
* <pre> * <pre>
* VitroRequest.getAssertionsWebappDaoFactory() * VitroRequest.getAssertionsWebappDaoFactory()
* VitroRequest.getDeductionsWebappDaoFactory()
* VitroRequest.getFullWebappDaoFactory() * VitroRequest.getFullWebappDaoFactory()
* VitroRequest.getRDFService() * VitroRequest.getRDFService()
* VitroRequest.getUnfilteredRDFService() * VitroRequest.getUnfilteredRDFService()
* VitroRequest.getWebappDaoFactory() * VitroRequest.getWebappDaoFactory()
* VitroRequest.getWriteModel() * VitroRequest.getWriteModel()
* VitroRequest.getJenaOntModel() * VitroRequest.getJenaOntModel()
* VitroRequest.setJenaOntModel() * vreq.setUnfilteredWebappDaoFactory(wadf);
* OntModelSelector.getAboxModel *
* OntModelSelector.getApplicationMetadataModel() * OntModelSelector.getABoxModel
* OntModelSelector.getFullModel() * OntModelSelector.getFullModel()
* OntModelSelector.getTBoxModel() * OntModelSelector.getTBoxModel()
* OntModelSelector.getTBoxModel(ontologyURI) * OntModelSelector.getTBoxModel(ontologyURI)
* OntModelSelector.getUserAccountsModel()
* VitroModelSource.getModel(URL) * VitroModelSource.getModel(URL)
* VitroModelSource.getModel(URL, loadIfAbsent) * VitroModelSource.getModel(URL, loadIfAbsent)
* VitroModelSource.openModel(name) * VitroModelSource.openModel(name)
* VitroModelSource.openModelIfPresent(string) * VitroModelSource.openModelIfPresent(string)
* ServletContext.getAttribute("assertionsWebappDaoFactory") * ServletContext.getAttribute("deductionsWebappDaoFactory")
* ServletContext.getAttribute("baseOntModelSelector") * ServletContext.getAttribute("baseOntModelSelector")
* ServletContext.getAttribute("jenaPersistentOntModel") * ServletContext.getAttribute("jenaPersistentOntModel")
* ServletContext.getAttribute("pelletOntModel") * ServletContext.getAttribute("pelletOntModel")
* ServletContext.getAttribute("webappDaoFactory")
* VitroJenaModelMaker * VitroJenaModelMaker
* VitroJenaSpecialModelMaker * VitroJenaSpecialModelMaker
* JenaDataSourceSetupBase.getApplicationDataSource(ctx) * JenaDataSourceSetupBase.getApplicationDataSource(ctx)
@ -75,6 +72,10 @@ public class ModelAccess {
UNION_ABOX, UNION_TBOX, UNION_FULL UNION_ABOX, UNION_TBOX, UNION_FULL
} }
public enum FactoryID {
BASE, UNION
}
private enum Scope { private enum Scope {
CONTEXT, SESSION, REQUEST CONTEXT, SESSION, REQUEST
} }
@ -124,7 +125,9 @@ public class ModelAccess {
private final Scope scope; private final Scope scope;
private final ModelAccess parent; private final ModelAccess parent;
private final Map<String, OntModel> modelMap = new HashMap<>(); private final Map<ModelID, OntModel> modelMap = new EnumMap<>(ModelID.class);
private final Map<FactoryID, WebappDaoFactory> factoryMap = new EnumMap<>(
FactoryID.class);
public ModelAccess(Scope scope, ModelAccess parent) { public ModelAccess(Scope scope, ModelAccess parent) {
this.scope = scope; this.scope = scope;
@ -176,19 +179,21 @@ public class ModelAccess {
} }
public void setOntModel(ModelID id, OntModel ontModel) { public void setOntModel(ModelID id, OntModel ontModel) {
String key = id.toString();
if (ontModel == null) { if (ontModel == null) {
modelMap.remove(key); modelMap.remove(id);
} else { } else {
modelMap.put(key, ontModel); modelMap.put(id, ontModel);
} }
} }
public void removeOntModel(ModelID id) {
setOntModel(id, null);
}
public OntModel getOntModel(ModelID id) { public OntModel getOntModel(ModelID id) {
String key = id.toString(); if (modelMap.containsKey(id)) {
if (modelMap.containsKey(key)) {
log.debug("Using " + id + " model from " + scope); log.debug("Using " + id + " model from " + scope);
return modelMap.get(key); return modelMap.get(id);
} else if (parent != null) { } else if (parent != null) {
return parent.getOntModel(id); return parent.getOntModel(id);
} else { } else {
@ -197,6 +202,50 @@ public class ModelAccess {
} }
} }
// ----------------------------------------------------------------------
// Accessing the Webapp DAO factories.
// ----------------------------------------------------------------------
public void setWebappDaoFactory(WebappDaoFactory wadf) {
setWebappDaoFactory(FactoryID.UNION, wadf);
}
public WebappDaoFactory getWebappDaoFactory() {
return getWebappDaoFactory(FactoryID.UNION);
}
public void setBaseWebappDaoFactory(WebappDaoFactory wadf) {
setWebappDaoFactory(FactoryID.BASE, wadf);
}
public WebappDaoFactory getBaseWebappDaoFactory() {
return getWebappDaoFactory(FactoryID.BASE);
}
public void setWebappDaoFactory(FactoryID id, WebappDaoFactory wadf) {
if (wadf == null) {
factoryMap.remove(id);
} else {
factoryMap.put(id, wadf);
}
}
public void removeWebappDaoFactory(FactoryID id) {
setWebappDaoFactory(id, null);
}
public WebappDaoFactory getWebappDaoFactory(FactoryID id) {
if (factoryMap.containsKey(id)) {
log.debug("Using " + id + " DAO factory from " + scope);
return factoryMap.get(id);
} else if (parent != null) {
return parent.getWebappDaoFactory(id);
} else {
log.warn("No DAO factory found for " + id);
return null;
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Accessing the OntModelSelectors // Accessing the OntModelSelectors
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View file

@ -174,12 +174,7 @@ public class VClassGroupCache implements IndexingEventListener {
} }
protected VClassGroupDao getVCGDao() { protected VClassGroupDao getVCGDao() {
WebappDaoFactory wdf = (WebappDaoFactory) context.getAttribute("webappDaoFactory"); return ModelAccess.on(context).getWebappDaoFactory().getVClassGroupDao();
if (wdf == null) {
log.error("Cannot get webappDaoFactory from context");
return null;
} else
return wdf.getVClassGroupDao();
} }
public void doSynchronousRebuild(){ public void doSynchronousRebuild(){
@ -242,11 +237,8 @@ public class VClassGroupCache implements IndexingEventListener {
*/ */
protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SolrServerException{ protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SolrServerException{
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
WebappDaoFactory wdFactory = (WebappDaoFactory) cache.context.getAttribute("webappDaoFactory"); WebappDaoFactory wdFactory = ModelAccess.on(cache.context).getWebappDaoFactory();
if (wdFactory == null){
log.error("Unable to rebuild cache: could not get 'webappDaoFactory' from Servletcontext");
return;
}
SolrServer solrServer = (SolrServer)cache.context.getAttribute(SolrSetup.SOLR_SERVER); SolrServer solrServer = (SolrServer)cache.context.getAttribute(SolrSetup.SOLR_SERVER);
if( solrServer == null){ if( solrServer == null){
log.error("Unable to rebuild cache: could not get solrServer from ServletContext"); log.error("Unable to rebuild cache: could not get solrServer from ServletContext");

View file

@ -2,10 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.dwr; package edu.cornell.mannlib.vitro.webapp.dwr;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -18,7 +15,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/** /**
This is a class to support Direct Web Remoting(DWR) in This is a class to support Direct Web Remoting(DWR) in
@ -31,7 +28,7 @@ public class EntityDWR {
public EntityDWR(){ public EntityDWR(){
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
ServletContext sc= ctx.getServletContext(); ServletContext sc= ctx.getServletContext();
entityWADao = ((WebappDaoFactory)sc.getAttribute("webappDaoFactory")).getIndividualDao(); entityWADao = ModelAccess.on(sc).getWebappDaoFactory().getIndividualDao();
} }
/** /**

View file

@ -409,7 +409,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
if(isSelectFromExisting(vreq)) { if(isSelectFromExisting(vreq)) {
// set ProhibitedFromSearch object so picklist doesn't show // set ProhibitedFromSearch object so picklist doesn't show
// individuals from classes that should be hidden from list views // individuals from classes that should be hidden from list views
OntModel displayOntModel = ModelAccess.on(session).getDisplayModel(); OntModel displayOntModel = ModelAccess.on(session.getServletContext()).getDisplayModel();
ProhibitedFromSearch pfs = new ProhibitedFromSearch( ProhibitedFromSearch pfs = new ProhibitedFromSearch(
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel); DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
if( editConfig != null ) if( editConfig != null )

View file

@ -11,6 +11,7 @@ import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
@ -21,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.PageController; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.PageController;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.PageDao; import edu.cornell.mannlib.vitro.webapp.dao.PageDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
/** /**
@ -52,7 +54,9 @@ public class PageRoutingFilter implements Filter{
@Override @Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
PageDao pageDao = getPageDao(); ServletContext ctx = filterConfig.getServletContext();
PageDao pageDao = ModelAccess.on(ctx).getWebappDaoFactory().getPageDao();
Map<String,String> urlMappings = pageDao.getPageMappings(); Map<String,String> urlMappings = pageDao.getPageMappings();
// get URL without hostname or servlet context // get URL without hostname or servlet context
@ -81,7 +85,7 @@ public class PageRoutingFilter implements Filter{
String controllerName = getControllerToForwardTo(req, pageUri, pageDao); String controllerName = getControllerToForwardTo(req, pageUri, pageDao);
log.debug(path + " is being forwarded to controller " + controllerName); log.debug(path + " is being forwarded to controller " + controllerName);
RequestDispatcher rd = filterConfig.getServletContext().getNamedDispatcher( controllerName ); RequestDispatcher rd = ctx.getNamedDispatcher( controllerName );
if( rd == null ){ if( rd == null ){
log.error(path + " should be forwarded to controller " + controllerName + " but there " + log.error(path + " should be forwarded to controller " + controllerName + " but there " +
"is no servlet named that defined for the web application in web.xml"); "is no servlet named that defined for the web application in web.xml");
@ -91,7 +95,7 @@ public class PageRoutingFilter implements Filter{
rd.forward(req, response); rd.forward(req, response);
}else if( "/".equals( path ) || path.isEmpty() ){ }else if( "/".equals( path ) || path.isEmpty() ){
log.debug("url '" +path + "' is being forward to home controller" ); log.debug("url '" +path + "' is being forward to home controller" );
RequestDispatcher rd = filterConfig.getServletContext().getNamedDispatcher( HOME_CONTROLLER_NAME ); RequestDispatcher rd = ctx.getNamedDispatcher( HOME_CONTROLLER_NAME );
rd.forward(req, response); rd.forward(req, response);
}else{ }else{
doNonDisplayPage(path,arg0,arg1,chain); doNonDisplayPage(path,arg0,arg1,chain);
@ -132,12 +136,6 @@ public class PageRoutingFilter implements Filter{
return false; return false;
} }
protected PageDao getPageDao(){
WebappDaoFactory wdf = (WebappDaoFactory)
filterConfig.getServletContext().getAttribute("webappDaoFactory");
return wdf.getPageDao();
}
@Override @Override
public void destroy() { public void destroy() {
//nothing to do here //nothing to do here

View file

@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import freemarker.cache.WebappTemplateLoader; import freemarker.cache.WebappTemplateLoader;
@ -116,8 +116,7 @@ public class StartupStatusDisplayFilter implements Filter {
private Object getApplicationName() { private Object getApplicationName() {
String name = ""; String name = "";
try { try {
WebappDaoFactory wadf = (WebappDaoFactory) ctx WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
ApplicationBean app = wadf.getApplicationDao().getApplicationBean(); ApplicationBean app = wadf.getApplicationDao().getApplicationBean();
name = app.getApplicationName(); name = app.getApplicationName();
} catch (Exception e) { } catch (Exception e) {

View file

@ -8,7 +8,6 @@ import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper; import javax.servlet.http.HttpServletResponseWrapper;
@ -18,6 +17,7 @@ import org.apache.commons.logging.LogFactory;
import org.openrdf.model.URI; import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl; import org.openrdf.model.impl.URIImpl;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
@ -36,7 +36,7 @@ public class URLRewritingHttpServletResponse extends HttpServletResponseWrapper/
super(response); super(response);
this._response = response; this._response = response;
this._context = context; this._context = context;
this.wadf = (WebappDaoFactory) context.getAttribute("webappDaoFactory"); this.wadf = ModelAccess.on(context).getWebappDaoFactory();
this.contextPathDepth = slashPattern.split(request.getContextPath()).length-1; this.contextPathDepth = slashPattern.split(request.getContextPath()).length-1;
} }

View file

@ -123,15 +123,7 @@ public class VitroRequestPrep implements Filter {
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
//-- setup DAO factory --// //-- setup DAO factory --//
WebappDaoFactory wdf = getWebappDaoFactory(vreq); WebappDaoFactory wdf = ModelAccess.on(vreq.getSession()).getWebappDaoFactory();
//TODO: get accept-language from request and set as preferred languages
// if there is a WebappDaoFactory in the session, use it
Object o = req.getSession().getAttribute("webappDaoFactory");
if (o instanceof WebappDaoFactory) {
wdf = (WebappDaoFactory) o;
log.debug("Found a WebappDaoFactory in the session and using it for this request");
}
// Set up the DisplayModel with language filtering, if appropriate. // Set up the DisplayModel with language filtering, if appropriate.
ConfigurationProperties props = ConfigurationProperties.getBean(req); ConfigurationProperties props = ConfigurationProperties.getBean(req);
@ -160,7 +152,7 @@ public class VitroRequestPrep implements Filter {
HideFromDisplayByPolicyFilter filter = new HideFromDisplayByPolicyFilter( HideFromDisplayByPolicyFilter filter = new HideFromDisplayByPolicyFilter(
RequestIdentifiers.getIdBundleForRequest(req), RequestIdentifiers.getIdBundleForRequest(req),
ServletPolicyList.getPolicies(_context)); ServletPolicyList.getPolicies(_context));
vreq.setWebappDaoFactory(new WebappDaoFactoryFiltering(wdf, filter)); ModelAccess.on(vreq).setWebappDaoFactory(new WebappDaoFactoryFiltering(wdf, filter));
// support for Dataset interface if using Jena in-memory model // support for Dataset interface if using Jena in-memory model
if (vreq.getDataset() == null) { if (vreq.getDataset() == null) {
@ -181,12 +173,6 @@ public class VitroRequestPrep implements Filter {
chain.doFilter(req, response); chain.doFilter(req, response);
} }
private WebappDaoFactory getWebappDaoFactory(VitroRequest vreq){
WebappDaoFactory webappDaoFactory = vreq.getWebappDaoFactory();
return (webappDaoFactory != null) ? webappDaoFactory :
(WebappDaoFactory) _context.getAttribute("webappDaoFactory");
}
private VitroFilters getFiltersFromContextFilterFactory( HttpServletRequest request, WebappDaoFactory wdf){ private VitroFilters getFiltersFromContextFilterFactory( HttpServletRequest request, WebappDaoFactory wdf){
FilterFactory ff = (FilterFactory)_context.getAttribute("FilterFactory"); FilterFactory ff = (FilterFactory)_context.getAttribute("FilterFactory");
if( ff == null ){ if( ff == null ){

View file

@ -115,6 +115,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
OntModelSelector oms = ModelAccess.on(_ctx).getUnionOntModelSelector(); OntModelSelector oms = ModelAccess.on(_ctx).getUnionOntModelSelector();
wadf = new WebappDaoFactorySDB(rdfService, oms, config); wadf = new WebappDaoFactorySDB(rdfService, oms, config);
ModelAccess.on(vreq).setWebappDaoFactory(wadf);
OntModelSelector baseOms = ModelAccess.on(_ctx).getBaseOntModelSelector(); OntModelSelector baseOms = ModelAccess.on(_ctx).getBaseOntModelSelector();
WebappDaoFactory assertions = new WebappDaoFactorySDB( WebappDaoFactory assertions = new WebappDaoFactorySDB(
@ -122,9 +123,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
vreq.setRDFService(rdfService); vreq.setRDFService(rdfService);
vreq.setUnfilteredRDFService(unfilteredRDFService); vreq.setUnfilteredRDFService(unfilteredRDFService);
vreq.setWebappDaoFactory(wadf); ModelAccess.on(vreq).setBaseWebappDaoFactory(assertions);
vreq.setAssertionsWebappDaoFactory(assertions);
vreq.setFullWebappDaoFactory(wadf);
vreq.setUnfilteredWebappDaoFactory(new WebappDaoFactorySDB( vreq.setUnfilteredWebappDaoFactory(new WebappDaoFactorySDB(
rdfService, ModelAccess.on(_ctx).getUnionOntModelSelector())); rdfService, ModelAccess.on(_ctx).getUnionOntModelSelector()));
vreq.setDataset(dataset); vreq.setDataset(dataset);

View file

@ -146,25 +146,17 @@ public class WebappDaoFactorySparqlPrep implements Filter {
Model m = ModelFactory.createModelForGraph(g); Model m = ModelFactory.createModelForGraph(g);
OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m); OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m);
dataset = DatasetFactory.create(new SparqlDatasetGraph(endpointURI));
//DataSource datasource = DatasetFactory.create();
//datasource.addNamedModel("fake:fake", m);
//dataset = datasource;
vreq.setAssertionsWebappDaoFactory(wadf);
ModelAccess.on(vreq).setOntModel(ModelID.UNION_ABOX, om); ModelAccess.on(vreq).setOntModel(ModelID.UNION_ABOX, om);
ModelAccess.on(vreq).setOntModel(ModelID.UNION_TBOX, om); ModelAccess.on(vreq).setOntModel(ModelID.UNION_TBOX, om);
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, om); ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, om);
OntModelSelector oms = ModelAccess.on(vreq).getOntModelSelector();
OntModelSelector oms = ModelAccess.on(vreq).getOntModelSelector();
wadf = new WebappDaoFactoryJena(oms, config); wadf = new WebappDaoFactoryJena(oms, config);
//wadf = new WebappDaoFactorySDB(oms, dataset, config); ModelAccess.on(vreq).setWebappDaoFactory(wadf);
vreq.setFullWebappDaoFactory(wadf); ModelAccess.on(vreq).setBaseWebappDaoFactory(wadf);
vreq.setUnfilteredWebappDaoFactory(wadf); vreq.setUnfilteredWebappDaoFactory(wadf);
vreq.setWebappDaoFactory(wadf);
dataset = DatasetFactory.create(new SparqlDatasetGraph(endpointURI));
vreq.setDataset(dataset); vreq.setDataset(dataset);
} }
} catch (Throwable t) { } catch (Throwable t) {

View file

@ -13,8 +13,6 @@ import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
@ -44,22 +42,6 @@ public class LanguageFilteringUtils {
} }
/**
* Make a new OntModelSelector that containing a new display model and all
* of the other models in the original OntModelSelector.
*/
public static OntModelSelector replaceDisplayModelInSelector(
OntModelSelector oldOms, OntModel newDisplayModel) {
OntModelSelectorImpl newOms = new OntModelSelectorImpl();
newOms.setABoxModel(oldOms.getABoxModel());
newOms.setApplicationMetadataModel(oldOms.getApplicationMetadataModel());
newOms.setDisplayModel(newDisplayModel);
newOms.setFullModel(oldOms.getFullModel());
newOms.setTBoxModel(oldOms.getTBoxModel());
newOms.setUserAccountsModel(oldOms.getUserAccountsModel());
return newOms;
}
/** /**
* Add a Language Filtering layer to an OntModel by treating it as an RDFService. * Add a Language Filtering layer to an OntModel by treating it as an RDFService.
*/ */

View file

@ -155,7 +155,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
// This is where the builder gets the list of places to try to // This is where the builder gets the list of places to try to
// get objects to index. It is filtered so that non-public text // get objects to index. It is filtered so that non-public text
// does not get into the search index. // does not get into the search index.
WebappDaoFactory wadf = (WebappDaoFactory) context.getAttribute("webappDaoFactory"); WebappDaoFactory wadf = ModelAccess.on(context).getWebappDaoFactory();
VitroFilters vf = VitroFilterUtils.getPublicFilter(context); VitroFilters vf = VitroFilterUtils.getPublicFilter(context);
wadf = new WebappDaoFactoryFiltering(wadf, vf); wadf = new WebappDaoFactoryFiltering(wadf, vf);

View file

@ -3,7 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup; package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY; import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY;
import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,6 +27,7 @@ import com.hp.hpl.jena.util.ResourceUtils;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.FactoryID;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
@ -110,15 +110,11 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
OntModelSelector baseOms = models.getBaseOntModelSelector(); OntModelSelector baseOms = models.getBaseOntModelSelector();
WebappDaoFactory baseWadf = new WebappDaoFactorySDB(rdfService, baseOms, config, ASSERTIONS_ONLY); WebappDaoFactory baseWadf = new WebappDaoFactorySDB(rdfService, baseOms, config, ASSERTIONS_ONLY);
ctx.setAttribute("assertionsWebappDaoFactory",baseWadf); ModelAccess.on(ctx).setBaseWebappDaoFactory(baseWadf);
OntModelSelector inferenceOms = models.getInferenceOntModelSelector();
WebappDaoFactory infWadf = new WebappDaoFactorySDB(rdfService, inferenceOms, config, INFERENCES_ONLY);
ctx.setAttribute("deductionsWebappDaoFactory", infWadf);
OntModelSelector unionOms = models.getUnionOntModelSelector(); OntModelSelector unionOms = models.getUnionOntModelSelector();
WebappDaoFactory wadf = new WebappDaoFactorySDB(rdfService, unionOms, config); WebappDaoFactory wadf = new WebappDaoFactorySDB(rdfService, unionOms, config);
ctx.setAttribute("webappDaoFactory",wadf); ModelAccess.on(ctx).setWebappDaoFactory(FactoryID.UNION, wadf);
log.info("Model makers set up"); log.info("Model makers set up");

View file

@ -11,6 +11,7 @@ import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
@ -43,18 +44,20 @@ public class RunSparqlConstructs implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
try { try {
WebappDaoFactory wadf = (WebappDaoFactory) sce.getServletContext().getAttribute("webappDaoFactory"); ServletContext ctx = sce.getServletContext();
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
String namespace = (wadf != null && wadf.getDefaultNamespace() != null) String namespace = (wadf != null && wadf.getDefaultNamespace() != null)
? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE; ? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE;
OntModel baseOntModel = ModelAccess.on(sce.getServletContext()).getBaseOntModel(); OntModel baseOntModel = ModelAccess.on(ctx).getBaseOntModel();
Model anonModel = ModelFactory.createDefaultModel(); Model anonModel = ModelFactory.createDefaultModel();
Model namedModel = ModelFactory.createDefaultModel(); Model namedModel = ModelFactory.createDefaultModel();
Set<String> resourcePaths = sce.getServletContext().getResourcePaths(SPARQL_DIR); Set<String> resourcePaths = ctx.getResourcePaths(SPARQL_DIR);
for (String path : resourcePaths) { for (String path : resourcePaths) {
log.debug("Attempting to execute SPARQL at " + path); log.debug("Attempting to execute SPARQL at " + path);
File file = new File(sce.getServletContext().getRealPath(path)); File file = new File(ctx.getRealPath(path));
try { try {
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuffer fileContents = new StringBuffer(); StringBuffer fileContents = new StringBuffer();

View file

@ -23,6 +23,7 @@ import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector; import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
@ -55,7 +56,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
OntModelSelector inferencesOms = ModelAccess.on(ctx).getInferenceOntModelSelector(); OntModelSelector inferencesOms = ModelAccess.on(ctx).getInferenceOntModelSelector();
OntModelSelector unionOms = ModelAccess.on(ctx).getUnionOntModelSelector(); OntModelSelector unionOms = ModelAccess.on(ctx).getUnionOntModelSelector();
WebappDaoFactoryJena wadf = (WebappDaoFactoryJena) sce.getServletContext().getAttribute("webappDaoFactory"); WebappDaoFactoryJena wadf = (WebappDaoFactoryJena) ModelAccess.on(ctx).getWebappDaoFactory();
if (!assertionsOms.getTBoxModel().getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) { if (!assertionsOms.getTBoxModel().getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model"); log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");

View file

@ -99,7 +99,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setErrorLogFile(ctx.getRealPath(errorLogFileName)); settings.setErrorLogFile(ctx.getRealPath(errorLogFileName));
settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE)); settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE));
settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE)); settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE));
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory"); WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
settings.setDefaultNamespace(wadf.getDefaultNamespace()); settings.setDefaultNamespace(wadf.getDefaultNamespace());
settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getBaseOntModelSelector()); settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getBaseOntModelSelector());
settings.setInferenceOntModelSelector(ModelAccess.on(ctx).getInferenceOntModelSelector()); settings.setInferenceOntModelSelector(ModelAccess.on(ctx).getInferenceOntModelSelector());

View file

@ -22,6 +22,7 @@ import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
@ -99,8 +100,7 @@ public class UpdatePermissionSetUris implements ServletContextListener {
this.ctx = ctx; this.ctx = ctx;
this.stats = stats; this.stats = stats;
WebappDaoFactory wadf = (WebappDaoFactory) ctx WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
.getAttribute("webappDaoFactory");
userAccountsDao = wadf.getUserAccountsDao(); userAccountsDao = wadf.getUserAccountsDao();
} }

View file

@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet; import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/** /**
* Can we tell whether a user is logged in as root? * Can we tell whether a user is logged in as root?
@ -79,7 +80,7 @@ public class HasPermissionFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao); wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub(); ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf); ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub(); session = new HttpSessionStub();
session.setServletContext(ctx); session.setServletContext(ctx);

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser; import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/** /**
* Can we tell whether a user is logged in as root? * Can we tell whether a user is logged in as root?
@ -56,7 +57,7 @@ public class IsRootUserFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao); wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub(); ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf); ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub(); session = new HttpSessionStub();
session.setServletContext(ctx); session.setServletContext(ctx);

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser; import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/** /**
* The simplest of the IdentifierBundleFactory classes. * The simplest of the IdentifierBundleFactory classes.
@ -46,7 +47,7 @@ public class IsUserFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao); wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub(); ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf); ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub(); session = new HttpSessionStub();
session.setServletContext(ctx); session.setServletContext(ctx);

View file

@ -47,6 +47,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.AuthenticatorStub; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.AuthenticatorStub;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/** /**
*/ */
@ -147,7 +148,7 @@ public class AuthenticateTest extends AbstractTestClass {
webappDaoFactory.setIndividualDao(individualDao); webappDaoFactory.setIndividualDao(individualDao);
servletContext = new ServletContextStub(); servletContext = new ServletContextStub();
servletContext.setAttribute("webappDaoFactory", webappDaoFactory); ModelAccess.on(servletContext).setWebappDaoFactory(webappDaoFactory);
servletContext.setAttribute(AuthenticatorStub.FACTORY_ATTRIBUTE_NAME, servletContext.setAttribute(AuthenticatorStub.FACTORY_ATTRIBUTE_NAME,
authenticatorFactory); authenticatorFactory);

View file

@ -28,6 +28,7 @@ import stubs.javax.servlet.http.HttpSessionStub;
import stubs.org.apache.solr.client.solrj.SolrServerStub; import stubs.org.apache.solr.client.solrj.SolrServerStub;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
/** /**
@ -106,8 +107,7 @@ public class JsonServletTest extends AbstractTestClass {
resp = new HttpServletResponseStub(); resp = new HttpServletResponseStub();
wadf = new WebappDaoFactoryStub(); wadf = new WebappDaoFactoryStub();
req.setAttribute("webappDaoFactory", wadf); ModelAccess.on(ctx).setWebappDaoFactory(wadf);
ctx.setAttribute("webappDaoFactory", wadf);
vcDao = new VClassDaoStub(); vcDao = new VClassDaoStub();
wadf.setVClassDao(vcDao); wadf.setVClassDao(vcDao);

View file

@ -18,6 +18,7 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector; import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
@ -48,7 +49,7 @@ public class PageDataGetterUtilsTest extends AbstractTestClass{
@Test @Test
public void testGetPageDataGetterObjects() throws Exception{ public void testGetPageDataGetterObjects() throws Exception{
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() ); VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
vreq.setWebappDaoFactory(wdf); ModelAccess.on(vreq).setWebappDaoFactory(wdf);
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI); List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI);
Assert.assertNotNull(pdgList); Assert.assertNotNull(pdgList);
@ -58,7 +59,7 @@ public class PageDataGetterUtilsTest extends AbstractTestClass{
@Test @Test
public void testGetNonPageDataGetterObjects() throws Exception{ public void testGetNonPageDataGetterObjects() throws Exception{
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() ); VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
vreq.setWebappDaoFactory(wdf); ModelAccess.on(vreq).setWebappDaoFactory(wdf);
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI_2); List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI_2);
Assert.assertNotNull(pdgList); Assert.assertNotNull(pdgList);

View file

@ -25,6 +25,10 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub; import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub; import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.freemarker.cache.TemplateLoaderStub; import stubs.freemarker.cache.TemplateLoaderStub;
@ -36,6 +40,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
@ -123,7 +129,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
hreq.setSession(session); hreq.setSession(session);
vreq = new VitroRequest(hreq); vreq = new VitroRequest(hreq);
vreq.setWebappDaoFactory(wadf); ModelAccess.on(vreq).setWebappDaoFactory(wadf);
subject = new IndividualImpl(); subject = new IndividualImpl();
@ -273,6 +279,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test @Test
public void constructQueryNodeMissing() public void constructQueryNodeMissing()
throws InvalidConfigurationException { throws InvalidConfigurationException {
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, emptyOntModel());
op = buildOperation("constructQueryMissing"); op = buildOperation("constructQueryMissing");
optm = new NonCollatingOPTM(op, subject, vreq, true); optm = new NonCollatingOPTM(op, subject, vreq, true);
// Not an error. // Not an error.
@ -281,6 +288,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test @Test
public void constructQueryMultipleValues() public void constructQueryMultipleValues()
throws InvalidConfigurationException { throws InvalidConfigurationException {
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, emptyOntModel());
op = buildOperation("constructQueryMultiple"); op = buildOperation("constructQueryMultiple");
optm = new NonCollatingOPTM(op, subject, vreq, true); optm = new NonCollatingOPTM(op, subject, vreq, true);
assertConstructQueries("multiple construct queries", "ONE", "TWO", assertConstructQueries("multiple construct queries", "ONE", "TWO",
@ -367,6 +375,10 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
// Helper methods // Helper methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private OntModel emptyOntModel() {
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
}
/** /**
* Sets up an operation with name "foobar" and adds it to the * Sets up an operation with name "foobar" and adds it to the
* ObjectPropertyDaoStub. * ObjectPropertyDaoStub.

View file

@ -12,10 +12,11 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import stubs.javax.servlet.ServletContextStub;
/** /**
* A simple stand-in for the HttpSession, for use in unit tests. * A simple stand-in for the HttpSession, for use in unit tests.
*/ */
@SuppressWarnings("deprecation")
public class HttpSessionStub implements HttpSession { public class HttpSessionStub implements HttpSession {
private static final Log log = LogFactory.getLog(HttpSessionStub.class); private static final Log log = LogFactory.getLog(HttpSessionStub.class);
@ -49,8 +50,12 @@ public class HttpSessionStub implements HttpSession {
@Override @Override
public ServletContext getServletContext() { public ServletContext getServletContext() {
if (this.context == null) {
return new ServletContextStub();
} else {
return this.context; return this.context;
} }
}
@Override @Override
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {
@ -149,6 +154,7 @@ public class HttpSessionStub implements HttpSession {
"HttpSessionStub.putValue() not implemented."); "HttpSessionStub.putValue() not implemented.");
} }
@Override
public void removeValue(String arg0) { public void removeValue(String arg0) {
throw new RuntimeException( throw new RuntimeException(
"HttpSessionStub.removeValue() not implemented."); "HttpSessionStub.removeValue() not implemented.");