updates for menu management

This commit is contained in:
hjkhjk54 2011-07-14 21:52:16 +00:00
parent 5f14a66774
commit 7e4cf9a5c7
11 changed files with 429 additions and 97 deletions

View file

@ -349,10 +349,16 @@ public class MenuManagementEdit extends VitroHttpServlet {
if(!internalClassSelected(vreq) && allClassesSelected(vreq)) {
dataGetterModel = getClassGroupDataGetter(vreq, dataGetterResource, addModel, displayModel);
} else {
dataGetterModel = getIndividualsForClassesDataGetter(vreq, dataGetterResource, addModel, displayModel);
dataGetterModel = getIndividualsForClassesDataGetter(vreq, dataGetterResource, addModel, displayModel, pageResource);
}
addModel.add(dataGetterModel);
//Also add special template to page
addModel.add(addModel.createStatement(pageResource,
DisplayVocabulary.REQUIRES_BODY_TEMPLATE,
addModel.createTypedLiteral(DisplayVocabulary.INTERNAL_CLASS_TEMPLATE)));
}
@ -369,12 +375,12 @@ public class MenuManagementEdit extends VitroHttpServlet {
}
private Model getIndividualsForClassesDataGetter(VitroRequest vreq, Resource dataGetterResource,
Model addModel, OntModel displayModel) {
Model addModel, OntModel displayModel, Resource pageResource) {
String[] selectedClasses = vreq.getParameterValues("classInClassGroup");
Model dgModel = ModelFactory.createDefaultModel();
dgModel.add(dgModel.createStatement(dataGetterResource,
RDF.type,
ResourceFactory.createResource(DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE)));
ResourceFactory.createResource(DisplayVocabulary.CLASSINDIVIDUALS_INTERNAL_TYPE)));
for(String classUri: selectedClasses) {
dgModel.add(dgModel.createStatement(
dataGetterResource,
@ -388,8 +394,8 @@ public class MenuManagementEdit extends VitroHttpServlet {
//The value should be the internal class uri
dgModel.add(dgModel.createStatement(
dataGetterResource,
ResourceFactory.createProperty(DisplayVocabulary.RESTRICT_RESULTS_BY),
ResourceFactory.createResource(internalClass)));
ResourceFactory.createProperty(DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL),
dgModel.createLiteral("true")));
}
return dgModel;
}

View file

@ -204,7 +204,8 @@ public class IndividualListController extends FreemarkerHttpServlet {
Map<String,Object> rvMap = new HashMap<String,Object>();
try{
// make query for multiple rdf types
SolrQuery query = getQuery(vclassURIs, alpha);
SolrQuery query = getQuery(vclassURIs, alpha);
log.debug("Executed solr query for " + vclassURIs.toString());
rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context);
List<Individual> individuals = (List<Individual>) rvMap.get("entities");
if (individuals == null)

View file

@ -242,7 +242,7 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet
//Get current internal class
private String retrieveCurrentInternalClass() {
String internalClassUri = "";
OntModel mainModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
Model mainModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel();;
StmtIterator internalIt = mainModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null);

View file

@ -276,7 +276,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
String dataGetterType = dataGetterTypes.nextStatement().getResource().getURI();
if(dataGetterType.equals(DisplayVocabulary.CLASSGROUP_PAGE_TYPE)) {
this.retrieveClassGroupPage(writeModel, dataGetter, data);
} else if(dataGetterType.equals(DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE)) {
} else if(dataGetterType.equals(DisplayVocabulary.CLASSINDIVIDUALS_INTERNAL_TYPE)) {
this.retrieveIndividualsForClassesPage(writeModel, dataGetter, data);
} else {
//Not sure what to do here
@ -286,13 +286,14 @@ public class MenuManagementController extends FreemarkerHttpServlet {
}
//Based on institutional internal page and not general individualsForClasses
private void retrieveIndividualsForClassesPage(OntModel writeModel,
Resource dataGetter, Map<String, Object> data) {
data.put("isIndividualsForClassesPage", true);
data.put("isClassGroupPage", false);
data.put("includeAllClasses", false);
//Get the classes and put them here
this.getClassesForDataGetter(writeModel, dataGetter, data);
this.getClassesForInternalDataGetter(writeModel, dataGetter, data);
//Also save the class group for display
this.getClassGroupForDataGetter(writeModel, dataGetter, data);
this.checkIfPageInternal(writeModel, data);
@ -301,12 +302,10 @@ public class MenuManagementController extends FreemarkerHttpServlet {
private void checkIfPageInternal(OntModel writeModel,
Map<String, Object> data) {
if(data.containsKey("internalClass") && data.containsKey("restrictClasses")) {
List<String> restrictClasses = (List<String>)data.get("restrictClasses");
String internalClass = (String) data.get("internalClass");
if(restrictClasses.contains(internalClass)) {
data.put("pageInternalOnly", true);
}
//if internal class exists, and data getter indicates page is internal
if(data.containsKey("internalClass") && data.containsKey("isInternal")) {
data.put("pageInternalOnly", true);
}
}
@ -324,7 +323,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//Instead of returning vclasses, just returning class Uris as vclasses appear to need their own template
//to show up correctly
private void getClassesForDataGetter(OntModel writeModel, Resource dataGetter,
private void getClassesForInternalDataGetter(OntModel writeModel, Resource dataGetter,
Map<String, Object> data) {
@ -344,22 +343,20 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//This checks whether restrict classes returned and include institutional internal class
//TODO: Create separate method to get restricted classes
//Get restrict classes - specifically internal class
List<String> restrictClassUris = new ArrayList<String>();
StmtIterator restrictClassesIt = writeModel.listStatements(dataGetter,
ResourceFactory.createProperty(DisplayVocabulary.RESTRICT_RESULTS_BY),
(RDFNode) null);
while(restrictClassesIt.hasNext()) {
String restrictClassUri = restrictClassesIt.nextStatement().getResource().getURI();
restrictClassUris.add(restrictClassUri);
}
data.put("restrictClasses", restrictClassUris);
StmtIterator internalIt = writeModel.listStatements(dataGetter,
ResourceFactory.createProperty(DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL),
(RDFNode) null);
if(internalIt.hasNext()) {
data.put("isInternal", internalIt.nextStatement().getLiteral().getString());
}
}
//Check whether any classes exist with internal class restrictions
private void checkInstitutionalInternalClass(Map<String, Object> data) {
//TODO: replace with more generic ModelContext retrieval method
OntModel mainModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
StmtIterator internalIt = mainModel.listStatements(null, ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), (RDFNode) null);
//List<String> internalClasses = new ArrayList<String>();

View file

@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.BrowseDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.InternalClassesDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.DataGetterUtils;
/**
* Controller for getting data for pages defined in the display model.
@ -140,9 +141,10 @@ public class PageController extends FreemarkerHttpServlet{
getPageDataGetterMap(context).put(cgpd.getType(), cgpd);
BrowseDataGetter bdg = new BrowseDataGetter();
getPageDataGetterMap(context).put(bdg.getType(), bdg);
//TODO: Check if can include by type here
IndividualsForClassesDataGetter cidg = new IndividualsForClassesDataGetter();
getPageDataGetterMap(context).put(cidg.getType(), cidg);
InternalClassesDataGetter internalCdg = new InternalClassesDataGetter();
getPageDataGetterMap(context).put(internalCdg.getType(), internalCdg);
}
}

View file

@ -120,6 +120,7 @@ public class DisplayVocabulary {
//URL for menu management
public static final String PROCESS_MENU_MANAGEMENT_URL = "/processEditDisplayModel";
public static final String REORDER_MENU_URL = PROCESS_MENU_MANAGEMENT_URL + "?cmd=Reorder&" + SWITCH_TO_DISPLAY_MODEL + "=true";
public static final String INTERNAL_CLASS_TEMPLATE = "menupage--individualsforclasses.ftl";
/* URIs for some individuals in the dispaly ontology */

View file

@ -22,9 +22,9 @@ public interface PageDao {
String getHomePageUri();
String getClassGroupPage(String pageUri);
Map<String, List<String>> getClassIntersections(String pageUri);
Map<String, List<String>> getClassesAndRestrictionsForPage(String pageUri);
Map<String, Object> getClassesAndCheckInternal(String pageUri);
}

View file

@ -43,6 +43,8 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
static protected Query classIntersectionPageQuery;
static protected Query individualsForClassesQuery;
static protected Query individualsForClassesRestrictedQuery;
static protected Query institutionalInternalClassQuery;
static protected Query individualsForClassesInternalQuery;
static final String prefixes =
@ -100,17 +102,7 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
" ?dg rdf:type <" + DisplayVocabulary.CLASSGROUP_PAGE_TYPE + ">. \n" +
" ?dg <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" +
"} \n" ;
static final protected String classIntersectionPageQueryString =
prefixes + "\n" +
"SELECT ?classIntersection ?label ?class ?WHERE { ?pageUri <" + DisplayVocabulary.HAS_CLASS_INTERSECTION + "> ?classIntersection . \n " +
" ?classIntersection <" + DisplayVocabulary.CLASS_INTERSECTION + "> ?class . \n "+
" ?classIntersection rdfs:label ?label . \n" +
"}";
//prefixes + "\n" +
//"SELECT ?classIntersection WHERE { ?pageUri <" + DisplayVocabulary.CLASS_INTERSECTION + "> ?classIntersection . }";
//Query to get what classes are to be employed on the page
static final protected String individualsForClassesDataGetterQueryString =
prefixes + "\n" +
@ -122,14 +114,30 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
"} \n" ;
//Given a data getter, check if results are to be restricted by class
//Also possible to merge these two into the same query
static final protected String individualsForClassesRestrictedQueryString =
prefixes + "\n" +
"SELECT ?restrictClass WHERE {\n" +
" ?dg <"+ DisplayVocabulary.RESTRICT_RESULTS_BY + "> ?restrictClass .\n" +
"} \n" ;
// " ?pageUri display:hasDataGetter ?dg .\n"+
//Is this data getter using internal class
static final protected String institutionalInternalClassQueryString =
prefixes + "\n" +
"SELECT ?restrictByInternalClass WHERE {\n" +
" ?dg <"+ DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL + "> ?restrictsByInternalClass .\n" +
"} \n" ;
//Query to get classes employed on internal class page
//Query to get what classes are to be employed on the page
static final protected String individualsForClassesInternalQueryString =
prefixes + "\n" +
"SELECT ?dg ?class ?isInternal WHERE {\n" +
" ?pageUri display:hasDataGetter ?dg .\n"+
" ?dg rdf:type <" + DisplayVocabulary.CLASSINDIVIDUALS_INTERNAL_TYPE + ">. \n" +
" ?dg <" + DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS + "> ?class . \n" +
" ?dg <"+ DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL + "> ?isInternal .\n" +
"} \n" ;
static{
try{
@ -167,14 +175,7 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
}catch(Throwable th){
log.error("could not create SPARQL query for classGroupPageQuery " + th.getMessage());
log.error(classGroupPageQueryString);
}
try{
classIntersectionPageQuery=QueryFactory.create(classIntersectionPageQueryString);
}catch(Throwable th){
log.error("could not create SPARQL query for classIntersectionPageQuery " + th.getMessage());
log.error(classIntersectionPageQueryString);
}
}
try{
individualsForClassesQuery=QueryFactory.create(individualsForClassesDataGetterQueryString);
}catch(Throwable th){
@ -188,6 +189,23 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
log.error("could not create SPARQL query for individualsForClassesRestrictedQuery " + th.getMessage());
log.error(individualsForClassesDataGetterQueryString);
}
//Check if data getter uses internal class
try{
institutionalInternalClassQuery=QueryFactory.create(institutionalInternalClassQueryString);
}catch(Throwable th){
log.error("could not create SPARQL query for institutionalInternalClassQuery " + th.getMessage());
log.error(institutionalInternalClassQueryString);
}
//Check which classes set for page and whether or not page should only have internal classes
try{
individualsForClassesInternalQuery = QueryFactory.create(individualsForClassesInternalQueryString);
}catch(Throwable th){
log.error("could not create SPARQL query for individualsForClassesInternalQuery " + th.getMessage());
log.error(individualsForClassesInternalQueryString);
}
}
public PageDaoJena(WebappDaoFactoryJena wadf) {
@ -350,52 +368,6 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
}
}
/**
* Get the set of intersections for page - each intersection has a label and includes names of the classes for class intersection. Multiple classes possible.
*/
public Map<String, List<String>> getClassIntersections(String pageUri) {
Map<String, List<String>> classIntersectionsMap = new HashMap<String, List<String>>();
QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add("pageUri", ResourceFactory.createResource(pageUri));
Model displayModel = getOntModelSelector().getDisplayModel();
displayModel.enterCriticalSection(false);
try{
QueryExecution qexec = QueryExecutionFactory.create( classIntersectionPageQuery, displayModel , initialBindings);
try{
//Assuming unique labels or could use URI itself?
//TODO: Review whether to use labels or URIs
ResultSet resultSet = qexec.execSelect();
while(resultSet.hasNext()){
QuerySolution soln = resultSet.next();
//Results format should be ?page hasClassIntersection <a>. <a> intersectsWithClass ?c; <a> intersects With Class ?e.
String intersectionLabel = nodeToString(soln.get("label"));
//first time encountering label, set up
if(!classIntersectionsMap.containsKey(intersectionLabel)) {
classIntersectionsMap.put(intersectionLabel, new ArrayList<String>());
}
List<String> classes = classIntersectionsMap.get(intersectionLabel);
classes.add(nodeToString(soln.get("class")));
//classIntersections.add( nodeToString(soln.get("classIntersection")) );
}
if( classIntersectionsMap.size() == 0 ){
log.debug("No class intersections info defined in display model for "+ pageUri);
return null;
}
return classIntersectionsMap;
}finally{
qexec.close();
}
}finally{
displayModel.leaveCriticalSection();
}
}
/*
* Get the classes for which to get individuals returned. This should return a list of class uris.
@ -448,6 +420,44 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
}
}
//Get classes for page along with whether or not internal class
public Map<String, Object> getClassesAndCheckInternal(String pageUri) {
Map<String, Object> classesAndRestrictions = new HashMap<String, Object>();
QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add("pageUri", ResourceFactory.createResource(pageUri));
List<String> classes = new ArrayList<String>();
Model displayModel = getOntModelSelector().getDisplayModel();
displayModel.enterCriticalSection(false);
try{
QueryExecution qexec = QueryExecutionFactory.create( individualsForClassesInternalQuery, displayModel , initialBindings);
try{
ResultSet resultSet = qexec.execSelect();
while(resultSet.hasNext()){
QuerySolution soln = resultSet.next();
String dg = nodeToString(soln.get("dg"));
classes.add(nodeToString(soln.get("class")));
String isInternal = nodeToString(soln.get("isInternal"));
if(isInternal != null && !isInternal.isEmpty()) {
log.debug("Internal value is "+ isInternal);
//Retrieve and add internal class
classesAndRestrictions.put("isInternal", isInternal);
}
}
if( classes.size() == 0 ){
log.debug("No classes defined in display model for "+ pageUri);
return null;
}
classesAndRestrictions.put("classes", classes);
return classesAndRestrictions;
}finally{
qexec.close();
}
}finally{
displayModel.leaveCriticalSection();
}
}