VIVO-317 Provide an un-language-filtered WebappDaoFactory

Store it in VitroRequest. See that it matches the model-switching of the usual WebappDaoFactory.
This commit is contained in:
j2blake 2013-10-07 15:17:43 -04:00
parent 0837552f6e
commit 6dc8094827
3 changed files with 35 additions and 14 deletions

View file

@ -215,5 +215,11 @@ public class VitroRequest extends HttpServletRequestWrapper {
return (OntModel) getAttribute("languageNeutralUnionFullModel");
}
public void setLanguageNeutralWebappDaoFactory(WebappDaoFactory wadf) {
setAttribute("languageNeutralWebappDaoFactory", wadf);
}
public WebappDaoFactory getLanguageNeutralWebappDaoFactory() {
return (WebappDaoFactory) getAttribute("languageNeutralWebappDaoFactory");
}
}

View file

@ -42,6 +42,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HideFromDisplayByPolicyFilter;
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.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SpecialBulkUpdateHandlerGraph;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
@ -143,10 +145,13 @@ public class RequestModelsPrep implements Filter {
setRawModels(vreq, dataset);
// We need access to the language-ignorant version of this model.
// Grab it before it gets wrapped in language awareness.
// We need access to some language-neutral items - either because we need to see all
// contents regardless of language, or because we need to see the blank nodes that
// are removed during language filtering.
vreq.setLanguageNeutralUnionFullModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_FULL));
vreq.setLanguageNeutralWebappDaoFactory(new WebappDaoFactorySDB(
rdfService, createLanguageNeutralOntModelSelector(vreq), createWadfConfig(vreq)));
wrapModelsWithLanguageAwareness(vreq);
setWebappDaoFactories(vreq, rdfService);
@ -229,6 +234,19 @@ public class RequestModelsPrep implements Filter {
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, unionModel);
}
/** Create an OntModelSelector that will hold the un-language-filtered models. */
private OntModelSelector createLanguageNeutralOntModelSelector(
VitroRequest vreq) {
OntModelSelectorImpl oms = new OntModelSelectorImpl();
oms.setABoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_ABOX));
oms.setTBoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_TBOX));
oms.setFullModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_FULL));
oms.setApplicationMetadataModel(ModelAccess.on(vreq).getOntModel(ModelID.APPLICATION_METADATA));
oms.setDisplayModel(ModelAccess.on(vreq).getOntModel(ModelID.DISPLAY));
oms.setUserAccountsModel(ModelAccess.on(vreq).getOntModel(ModelID.USER_ACCOUNTS));
return oms;
}
private void wrapModelsWithLanguageAwareness(VitroRequest vreq) {
wrapModelWithLanguageAwareness(vreq, ModelID.DISPLAY);
wrapModelWithLanguageAwareness(vreq, ModelID.APPLICATION_METADATA);
@ -271,6 +289,10 @@ public class RequestModelsPrep implements Filter {
// a different version if requested by parameters
WebappDaoFactory switchedWadf = new ModelSwitcher()
.checkForModelSwitching(vreq, wadf);
// Switch the language-neutral one also.
vreq.setLanguageNeutralWebappDaoFactory(new ModelSwitcher()
.checkForModelSwitching(vreq,
vreq.getLanguageNeutralWebappDaoFactory()));
HideFromDisplayByPolicyFilter filter = new HideFromDisplayByPolicyFilter(
RequestIdentifiers.getIdBundleForRequest(vreq),

View file

@ -20,7 +20,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
@ -159,7 +158,6 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
}
@SuppressWarnings("unchecked")
protected void sort(List<Property> propertyList) {
try {
Collections.sort(propertyList, new PropertyRanker(vreq));
@ -177,14 +175,9 @@ public class GroupedPropertyList extends BaseTemplateModel {
// DataPropertyDao.getAllPossibleDatapropsForIndividual(). The comparable method for object properties
// is defined using PropertyInstance rather than ObjectProperty.
// Getting WebappDaoFactory from the session because we can't have the filtering
// that gets applied to the request. This breaks blank node structures in the
// restrictions that determine applicable properties.
WebappDaoFactory wadf = ModelAccess.on(vreq.getSession().getServletContext()).getWebappDaoFactory();
//Allowing model switching for display model
if(vreq.getAttribute("specialWriteModel") != null) {
wadf = ModelAccess.on(vreq).getWebappDaoFactory();
}
// Getting Language-neutral WebappDaoFactory because the language-filtering
// breaks blank node structures in the restrictions that determine applicable properties.
WebappDaoFactory wadf = vreq.getLanguageNeutralWebappDaoFactory();
PropertyInstanceDao piDao = wadf.getPropertyInstanceDao();
Collection<PropertyInstance> allPropInstColl = piDao