UAdapting VitroRequestPrep to use a WebappDaoFactory for a different model based on parameter - additional changes still expected.

This commit is contained in:
hjkhjk54 2011-05-25 16:05:18 +00:00
parent b8c058384f
commit ff35554bf8
2 changed files with 60 additions and 3 deletions

View file

@ -33,6 +33,7 @@ import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
@ -61,6 +62,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyGroupDaoJena;
public class WebappDaoFactoryJena implements WebappDaoFactory {
@ -631,4 +633,31 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
}
}
//Method for using special model for webapp dao factory, such as display model
//This is still in flux, am checking in to allow others to experiment
public void setSpecialDataModel(OntModel specialModel, OntModel specialTboxModel) {
WebappDaoFactoryJena specialWadfj = new WebappDaoFactoryJena(specialModel);
entityWebappDao = specialWadfj.getIndividualDao();
keys2EntsDao = specialWadfj.getKeys2EntsDao();
keywordDao = specialWadfj.getKeywordDao();
linksDao = specialWadfj.getLinksDao();
linktypeDao = specialWadfj.getLinktypeDao();
vClassGroupDao = specialWadfj.getVClassGroupDao();
//To allow for testing, add a property group, this will allow
//the unassigned group method section to be executed and main Image to be assigned to that group
//otherwise the dummy group does not allow for the unassigned group to be executed
propertyGroupDao = specialWadfj.getPropertyGroupDao();
PropertyGroup pgtest = new edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup();
pgtest.setName("testname");
pgtest.setDisplayRank(1);
propertyGroupDao.insertNewPropertyGroup(pgtest);
//?Simple ont model selector uses submodels - unsure if relevant here
//|| ontModelSelector instanceof SimpleOntModelSelector
if(ontModelSelector instanceof OntModelSelectorImpl ) {
OntModelSelectorImpl omsImpl = (OntModelSelectorImpl) ontModelSelector;
omsImpl.setTBoxModel(specialTboxModel);
}
}
}

View file

@ -18,11 +18,15 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
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.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
@ -30,7 +34,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HideFromDisplayByPolicyFilter;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import org.apache.commons.dbcp.BasicDataSource;
/**
* This sets up several objects in the Request scope for each
* incoming HTTP request. This is done in a Filter so
@ -122,6 +127,8 @@ public class VitroRequestPrep implements Filter {
log.debug("Found a WebappDaoFactory in the session and using it for this request");
}
checkForSpecialWDF(vreq, wdf);
VitroFilters filters = null;
filters = getFiltersFromContextFilterFactory(req, wdf);
@ -191,5 +198,26 @@ public class VitroRequestPrep implements Filter {
// Nothing to do.
}
//check if special model - this is for enabling the use of a different model for menu management
private void checkForSpecialWDF(VitroRequest vreq, WebappDaoFactory wadf) {
if(vreq.getParameter("test") != null) {
if(wadf instanceof WebappDaoFactoryJena) {
WebappDaoFactoryJena wadfj = (WebappDaoFactoryJena) wadf;
OntModel testDisplayModel = (OntModel) _context.getAttribute("displayOntModel");
//Hardcoding tbox model uri for now
String tboxModelUri = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX";
BasicDataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_context);
//Model dbPlainModel = JenaDataSourceSetupBase.makeDBModelFromConfigurationProperties(tboxModelUri, OntModelSpec.OWL_MEM, _context);
String dbType = ConfigurationProperties.getBean(_context).getProperty( // database type
"VitroConnection.DataSource.dbtype", "MySQL");
com.hp.hpl.jena.rdf.model.Model displayTboxModel = JenaDataSourceSetupBase.makeDBModel(bds, tboxModelUri, OntModelSpec.OWL_MEM, JenaDataSourceSetupBase.TripleStoreType.RDB, dbType, _context);
System.out.println("Checking what the display tbox model is returning");
displayTboxModel.write(System.out, "N3");
OntModel displayTboxOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, displayTboxModel);
wadfj.setSpecialDataModel(testDisplayModel, displayTboxOntModel);
}
}
}
}