updates for rewriting page data getters as data getters and updating page controller, etc.

This commit is contained in:
hjkhjk54 2012-03-02 21:24:55 +00:00
parent cd64830dd5
commit 8afc9856cf
10 changed files with 67 additions and 42 deletions

View file

@ -2,6 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.List; import java.util.List;
@ -12,8 +13,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetter; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
public class HomePageController extends FreemarkerHttpServlet { public class HomePageController extends FreemarkerHttpServlet {
@ -23,10 +24,19 @@ public class HomePageController extends FreemarkerHttpServlet {
private static final String BODY_TEMPLATE = "home.ftl"; private static final String BODY_TEMPLATE = "home.ftl";
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) throws InstantiationException, IllegalAccessException, ClassNotFoundException { protected ResponseValues processRequest(VitroRequest vreq) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
List<PageDataGetter> dataGetters = PageDataGetterUtils.getPageDataGetterObjects(vreq, DisplayVocabulary.HOME_PAGE_URI);
List<DataGetter> dgList = DataGetterUtils.getDataGettersForPage(vreq.getDisplayModel(), DisplayVocabulary.HOME_PAGE_URI);
for( DataGetter dg : dgList){
Map<String,Object> moreData = dg.getData(getServletContext(),vreq,body);
if( moreData != null ){
body.putAll(moreData);
}
}
/*
for(PageDataGetter dataGetter: dataGetters) { for(PageDataGetter dataGetter: dataGetters) {
if( dataGetter != null ){ if( dataGetter != null ){
String uriOfPageInDisplayModel = "not defined"; String uriOfPageInDisplayModel = "not defined";
@ -36,7 +46,7 @@ public class HomePageController extends FreemarkerHttpServlet {
if(pageData != null) if(pageData != null)
body.putAll(pageData); body.putAll(pageData);
} }
} }*/
body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri=")); body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri="));
return new TemplateResponseValues(BODY_TEMPLATE, body); return new TemplateResponseValues(BODY_TEMPLATE, body);

View file

@ -11,6 +11,7 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
@ -26,8 +27,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils; import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils;
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.SelectDataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.SelectDataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetter; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
/* /*
* Custom controller for menu management. This will be replaced later once N3 Editing * Custom controller for menu management. This will be replaced later once N3 Editing
@ -114,7 +115,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//not a page already assigned a class group //not a page already assigned a class group
data.put("isClassGroupPage", false); data.put("isClassGroupPage", false);
data.put("includeAllClasses", false); data.put("includeAllClasses", false);
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext())); data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
data.put("selectedTemplateType", "default"); data.put("selectedTemplateType", "default");
// //
this.getMenuItemData(vreq, menuItem, data); this.getMenuItemData(vreq, menuItem, data);
@ -134,7 +135,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
//not a page already assigned a class group //not a page already assigned a class group
data.put("isClassGroupPage", false); data.put("isClassGroupPage", false);
data.put("includeAllClasses", false); data.put("includeAllClasses", false);
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext())); data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
data.put("selectedTemplateType", "default"); data.put("selectedTemplateType", "default");
//defaults to regular class group page //defaults to regular class group page
} }
@ -149,7 +150,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
data.put("menuItem", menuItem); data.put("menuItem", menuItem);
data.put("menuAction", "Edit"); data.put("menuAction", "Edit");
//Get All class groups //Get All class groups
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext())); data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
//Get data for menu item and associated page //Get data for menu item and associated page
this.getMenuItemData(vreq, menuItem, data); this.getMenuItemData(vreq, menuItem, data);
this.getPageData(vreq, data); this.getPageData(vreq, data);
@ -261,29 +262,33 @@ public class MenuManagementController extends FreemarkerHttpServlet {
while(dataGetterIt.hasNext()) { while(dataGetterIt.hasNext()) {
Statement dataGetterStmt = dataGetterIt.nextStatement(); Statement dataGetterStmt = dataGetterIt.nextStatement();
Resource dataGetter = dataGetterStmt.getResource(); Resource dataGetter = dataGetterStmt.getResource();
if(dataGetter != null) {
this.retrieveData(vreq, dataGetter.getURI(), data);
}
/*
//Get types of data getter //Get types of data getter
StmtIterator dataGetterTypes = writeModel.listStatements(dataGetter, RDF.type, (RDFNode) null); StmtIterator dataGetterTypes = writeModel.listStatements(dataGetter, RDF.type, (RDFNode) null);
while(dataGetterTypes.hasNext()) { while(dataGetterTypes.hasNext()) {
String dataGetterType = dataGetterTypes.nextStatement().getResource().getURI(); String dataGetterType = dataGetterTypes.nextStatement().getResource().getURI();
this.retrieveData(vreq, page, dataGetterType, data); this.retrieveData(vreq, dataGetterType, data);
} }*/
} }
} }
private void retrieveData(VitroRequest vreq, Resource page, String dataGetterType, Map<String, Object> templateData) { private void retrieveData(VitroRequest vreq, String dataGetterURI, Map<String, Object> templateData) {
//Data Getter type is now a class name //Data Getter type is now a class name
String className = PageDataGetterUtils.getClassNameFromUri(dataGetterType); Model displayModel = vreq.getDisplayModel();
try{ try{
String pageURI = page.getURI(); String className = DataGetterUtils.getJClassForDataGetterURI(displayModel, dataGetterURI);
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance(); //TODO: Change so that instantiation here occurs correctly <-- how should data getter be instantiated
DataGetter pg = DataGetterUtils.dataGetterForURI(vreq.getDisplayModel(), dataGetterURI);
Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI); //TODO: Check template data variable and what that is?
Map<String, Object> pageData = pg.getData(getServletContext(), vreq, templateData);
Map<String, Object> pageData = PageDataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext()); //Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
SelectDataGetterUtils.processAndRetrieveData(vreq, getServletContext(), pageData, className, templateData); SelectDataGetterUtils.processAndRetrieveData(vreq, getServletContext(), pageData, className, templateData);
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in instantiation page data getter for " + className, ex); log.error("Exception occurred in instantiation page data getter for " + dataGetterURI, ex);
} }

View file

@ -66,7 +66,8 @@ public class PageController extends FreemarkerHttpServlet{
return doNotFound(vreq); return doNotFound(vreq);
} }
executePageDataGetters( pageUri, vreq, getServletContext(), mapForTemplate ); //executePageDataGetters( pageUri, vreq, getServletContext(), mapForTemplate );
//these should all be data getters now
executeDataGetters( pageUri, vreq, getServletContext(), mapForTemplate); executeDataGetters( pageUri, vreq, getServletContext(), mapForTemplate);
mapForTemplate.putAll( getPageControllerValues( pageUri, vreq, getServletContext(), mapForTemplate)); mapForTemplate.putAll( getPageControllerValues( pageUri, vreq, getServletContext(), mapForTemplate));
@ -86,12 +87,12 @@ public class PageController extends FreemarkerHttpServlet{
} }
} }
} }
/*
private void executePageDataGetters(String pageUri, VitroRequest vreq, ServletContext context, Map<String, Object> mapForTemplate) private void executePageDataGetters(String pageUri, VitroRequest vreq, ServletContext context, Map<String, Object> mapForTemplate)
throws Exception{ throws Exception{
mapForTemplate.putAll( PageDataGetterUtils.getDataForPage(pageUri, vreq, context) ); mapForTemplate.putAll( DataGetterUtils.getDataForPage(pageUri, vreq, context) );
} }
*/
/** /**
* Add any additional values to the template variable map that are related to the page. * Add any additional values to the template variable map that are related to the page.
* For example, editing links. * For example, editing links.

View file

@ -73,6 +73,11 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
//actual pagej //actual pagej
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo(); EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
//will this forward to the appropriate controller
String queryString = vreq.getQueryString();
String redirectPage = vreq.getContextPath() + "/menuManagementController?" + queryString;
editConfiguration.setSkipToUrl(redirectPage);
/*
//Setting a custom test template for now //Setting a custom test template for now
//TODO: Where to get this custom template from? Should it be a predicate in display model somewhere? //TODO: Where to get this custom template from? Should it be a predicate in display model somewhere?
editConfiguration.setTemplate(this.template); editConfiguration.setTemplate(this.template);
@ -119,7 +124,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
this.associatePageData(vreq, editConfiguration, model); this.associatePageData(vreq, editConfiguration, model);
//don't need this here exactly //don't need this here exactly
//this.generateSelectForExisting(vreq, session, editConfiguration, subject, prop, wdf); //this.generateSelectForExisting(vreq, session, editConfiguration, subject, prop, wdf);
*/
return editConfiguration; return editConfiguration;
} }

View file

@ -38,15 +38,15 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateMo
* classGroupUri: uri of the classgroup associated with this page. * classGroupUri: uri of the classgroup associated with this page.
* vClassGroup: a data structure that is the classgroup associated with this page. * vClassGroup: a data structure that is the classgroup associated with this page.
*/ */
public class ClassGroupDataGetter extends DataGetterBase implements DataGetter{ public class ClassGroupPageData extends DataGetterBase implements DataGetter{
private static final Log log = LogFactory.getLog(ClassGroupDataGetter.class); private static final Log log = LogFactory.getLog(ClassGroupPageData.class);
String dataGetterURI; String dataGetterURI;
String classGroupUri; String classGroupUri;
/** /**
* Constructor with display model and data getter URI that will be called by reflection. * Constructor with display model and data getter URI that will be called by reflection.
*/ */
public ClassGroupDataGetter(Model displayModel, String dataGetterURI){ public ClassGroupPageData(Model displayModel, String dataGetterURI){
this.configure(displayModel,dataGetterURI); this.configure(displayModel,dataGetterURI);
} }

View file

@ -403,7 +403,7 @@ public class DataGetterUtils {
private static final String classGroupForDataGetterQuery = private static final String classGroupForDataGetterQuery =
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" +
"SELECT ?classGroupUri WHERE { \n" + "SELECT ?classGroupUri WHERE { \n" +
" ?dataGetterUri "+forClassGroupURI+" ?classGroupUri . \n" + " ?dataGetterURI "+forClassGroupURI+" ?classGroupUri . \n" +
"}"; "}";

View file

@ -41,8 +41,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData;
/* /*
* Handle processing of data retrieved from ClassGroupPage data getter to return to form template * Handle processing of data retrieved from ClassGroupPage data getter to return to form template
@ -59,16 +59,15 @@ public class ProcessClassGroup implements ProcessDataGetter{
templateData.put("includeAllClasses", true); templateData.put("includeAllClasses", true);
//Get the class group from VClassGroup //Get the class group from VClassGroup
PageDataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData); DataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
} }
//Process submission //Process submission
public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) { public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) {
ClassGroupPageData cpg = new ClassGroupPageData();
Model dgModel = ModelFactory.createDefaultModel(); Model dgModel = ModelFactory.createDefaultModel();
String dataGetterTypeUri = cpg.getType(); String dataGetterTypeUri = DataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
dgModel.add(dgModel.createStatement(dataGetterResource, dgModel.add(dgModel.createStatement(dataGetterResource,
RDF.type, RDF.type,
ResourceFactory.createResource(dataGetterTypeUri))); ResourceFactory.createResource(dataGetterTypeUri)));

View file

@ -41,8 +41,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter;
/* /*
* Handle processing of data retrieved from IndividualsForClasses data getter to return to form template * Handle processing of data retrieved from IndividualsForClasses data getter to return to form template
@ -59,7 +59,7 @@ public class ProcessIndividualsForClasses implements ProcessDataGetter {
populateIncludedClasses(pageData, templateData); populateIncludedClasses(pageData, templateData);
populateRestrictedClasses(pageData, templateData); populateRestrictedClasses(pageData, templateData);
//Also save the class group for display //Also save the class group for display
PageDataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData); DataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
} }
@ -98,7 +98,7 @@ public class ProcessIndividualsForClasses implements ProcessDataGetter {
} }
public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) { public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) {
String[] selectedClasses = vreq.getParameterValues("classInClassGroup"); String[] selectedClasses = vreq.getParameterValues("classInClassGroup");
String dataGetterTypeUri = new IndividualsForClassesDataGetter().getType(); String dataGetterTypeUri = DataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
Model dgModel = ModelFactory.createDefaultModel(); Model dgModel = ModelFactory.createDefaultModel();
dgModel.add(dgModel.createStatement(dataGetterResource, dgModel.add(dgModel.createStatement(dataGetterResource,
RDF.type, RDF.type,

View file

@ -40,8 +40,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter;
/* /*
* This class includes methods that help in selecting a data getter based on * This class includes methods that help in selecting a data getter based on

View file

@ -162,8 +162,12 @@ owl:topObjectProperty
"true"^^xsd:boolean . "true"^^xsd:boolean .
###Display model ###Display model
###Adding menu management customform annotation
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasElement> <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasElement>
a owl:ObjectProperty . a owl:ObjectProperty;
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#customEntryFormAnnot>
"edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.MenuEditingFormGenerator"^^xsd:string .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#excludeClass> <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#excludeClass>
a owl:ObjectProperty . a owl:ObjectProperty .
@ -184,3 +188,4 @@ owl:topObjectProperty
a owl:ObjectProperty . a owl:ObjectProperty .