updates for rewriting page data getters as data getters and updating page controller, etc.
This commit is contained in:
parent
cd64830dd5
commit
8afc9856cf
10 changed files with 67 additions and 42 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetter;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
||||
|
||||
public class HomePageController extends FreemarkerHttpServlet {
|
||||
|
||||
|
@ -23,10 +24,19 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
private static final String BODY_TEMPLATE = "home.ftl";
|
||||
|
||||
@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>();
|
||||
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) {
|
||||
if( dataGetter != null ){
|
||||
String uriOfPageInDisplayModel = "not defined";
|
||||
|
@ -36,7 +46,7 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
if(pageData != null)
|
||||
body.putAll(pageData);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri="));
|
||||
|
||||
return new TemplateResponseValues(BODY_TEMPLATE, body);
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.hp.hpl.jena.ontology.Individual;
|
||||
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.Resource;
|
||||
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.utils.menuManagement.MenuManagementDataUtils;
|
||||
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.pageDataGetter.PageDataGetter;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||
|
||||
/*
|
||||
* 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
|
||||
data.put("isClassGroupPage", false);
|
||||
data.put("includeAllClasses", false);
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("selectedTemplateType", "default");
|
||||
//
|
||||
this.getMenuItemData(vreq, menuItem, data);
|
||||
|
@ -134,7 +135,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
|||
//not a page already assigned a class group
|
||||
data.put("isClassGroupPage", false);
|
||||
data.put("includeAllClasses", false);
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("selectedTemplateType", "default");
|
||||
//defaults to regular class group page
|
||||
}
|
||||
|
@ -149,7 +150,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
|||
data.put("menuItem", menuItem);
|
||||
data.put("menuAction", "Edit");
|
||||
//Get All class groups
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
//Get data for menu item and associated page
|
||||
this.getMenuItemData(vreq, menuItem, data);
|
||||
this.getPageData(vreq, data);
|
||||
|
@ -261,29 +262,33 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
|||
while(dataGetterIt.hasNext()) {
|
||||
Statement dataGetterStmt = dataGetterIt.nextStatement();
|
||||
Resource dataGetter = dataGetterStmt.getResource();
|
||||
if(dataGetter != null) {
|
||||
this.retrieveData(vreq, dataGetter.getURI(), data);
|
||||
}
|
||||
/*
|
||||
//Get types of data getter
|
||||
StmtIterator dataGetterTypes = writeModel.listStatements(dataGetter, RDF.type, (RDFNode) null);
|
||||
while(dataGetterTypes.hasNext()) {
|
||||
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
|
||||
String className = PageDataGetterUtils.getClassNameFromUri(dataGetterType);
|
||||
Model displayModel = vreq.getDisplayModel();
|
||||
try{
|
||||
String pageURI = page.getURI();
|
||||
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
||||
|
||||
Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
|
||||
|
||||
Map<String, Object> pageData = PageDataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext());
|
||||
String className = DataGetterUtils.getJClassForDataGetterURI(displayModel, dataGetterURI);
|
||||
//TODO: Change so that instantiation here occurs correctly <-- how should data getter be instantiated
|
||||
DataGetter pg = DataGetterUtils.dataGetterForURI(vreq.getDisplayModel(), dataGetterURI);
|
||||
//TODO: Check template data variable and what that is?
|
||||
Map<String, Object> pageData = pg.getData(getServletContext(), vreq, templateData);
|
||||
//Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
|
||||
SelectDataGetterUtils.processAndRetrieveData(vreq, getServletContext(), pageData, className, templateData);
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ public class PageController extends FreemarkerHttpServlet{
|
|||
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);
|
||||
|
||||
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)
|
||||
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.
|
||||
* For example, editing links.
|
||||
|
|
|
@ -73,6 +73,11 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
|||
//actual pagej
|
||||
|
||||
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
|
||||
//TODO: Where to get this custom template from? Should it be a predicate in display model somewhere?
|
||||
editConfiguration.setTemplate(this.template);
|
||||
|
@ -119,7 +124,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
|||
this.associatePageData(vreq, editConfiguration, model);
|
||||
//don't need this here exactly
|
||||
//this.generateSelectForExisting(vreq, session, editConfiguration, subject, prop, wdf);
|
||||
|
||||
*/
|
||||
return editConfiguration;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,15 +38,15 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateMo
|
|||
* classGroupUri: uri of 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 classGroupUri;
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ public class DataGetterUtils {
|
|||
private static final String classGroupForDataGetterQuery =
|
||||
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" +
|
||||
"SELECT ?classGroupUri WHERE { \n" +
|
||||
" ?dataGetterUri "+forClassGroupURI+" ?classGroupUri . \n" +
|
||||
" ?dataGetterURI "+forClassGroupURI+" ?classGroupUri . \n" +
|
||||
"}";
|
||||
|
||||
|
||||
|
|
|
@ -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.WebappDaoFactory;
|
||||
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.pageDataGetter.PageDataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
//Get the class group from VClassGroup
|
||||
PageDataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
||||
DataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
||||
}
|
||||
|
||||
|
||||
//Process submission
|
||||
|
||||
public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) {
|
||||
ClassGroupPageData cpg = new ClassGroupPageData();
|
||||
Model dgModel = ModelFactory.createDefaultModel();
|
||||
String dataGetterTypeUri = cpg.getType();
|
||||
String dataGetterTypeUri = DataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
||||
dgModel.add(dgModel.createStatement(dataGetterResource,
|
||||
RDF.type,
|
||||
ResourceFactory.createResource(dataGetterTypeUri)));
|
||||
|
|
|
@ -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.WebappDaoFactory;
|
||||
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.pageDataGetter.IndividualsForClassesDataGetter;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
populateRestrictedClasses(pageData, templateData);
|
||||
//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) {
|
||||
String[] selectedClasses = vreq.getParameterValues("classInClassGroup");
|
||||
String dataGetterTypeUri = new IndividualsForClassesDataGetter().getType();
|
||||
String dataGetterTypeUri = DataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
||||
Model dgModel = ModelFactory.createDefaultModel();
|
||||
dgModel.add(dgModel.createStatement(dataGetterResource,
|
||||
RDF.type,
|
||||
|
|
|
@ -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.WebappDaoFactory;
|
||||
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.pageDataGetter.IndividualsForClassesDataGetter;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter;
|
||||
|
||||
/*
|
||||
* This class includes methods that help in selecting a data getter based on
|
||||
|
|
|
@ -162,8 +162,12 @@ owl:topObjectProperty
|
|||
"true"^^xsd:boolean .
|
||||
|
||||
###Display model
|
||||
|
||||
###Adding menu management customform annotation
|
||||
<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>
|
||||
a owl:ObjectProperty .
|
||||
|
@ -183,4 +187,5 @@ owl:topObjectProperty
|
|||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#restrictResultsByClass>
|
||||
a owl:ObjectProperty .
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue