Working on model switching. Change editRequestDispatch to stop it from always forwarding if there was a display model edit parameter. Chagned URLs for menu edit controllers. Added non-page data getters. Added SPARQL data getter.
This commit is contained in:
parent
9ce168f7c9
commit
0aabb7908b
38 changed files with 790 additions and 198 deletions
|
@ -41,7 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.DataGetterUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ public class JsonServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
// Map given to process method includes the actual individuals returned from the search
|
// Map given to process method includes the actual individuals returned from the search
|
||||||
public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
|
public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
|
||||||
JSONObject rObj = DataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
|
JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
|
||||||
return rObj;
|
return rObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,11 +534,11 @@ public class JsonServlet extends VitroHttpServlet {
|
||||||
String pageUri = vreq.getParameter("pageUri");
|
String pageUri = vreq.getParameter("pageUri");
|
||||||
if(pageUri != null && !pageUri.isEmpty()) {
|
if(pageUri != null && !pageUri.isEmpty()) {
|
||||||
ServletContext context = getServletContext();
|
ServletContext context = getServletContext();
|
||||||
Map<String,Object> data = DataGetterUtils.getDataForPage(pageUri, vreq, context);
|
Map<String,Object> data = PageDataGetterUtils.getDataForPage(pageUri, vreq, context);
|
||||||
//Convert to json version based on type of page
|
//Convert to json version based on type of page
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
//Convert to json version based on type of page
|
//Convert to json version based on type of page
|
||||||
rObj = DataGetterUtils.covertDataToJSONForPage(pageUri, data, vreq, context);
|
rObj = PageDataGetterUtils.covertDataToJSONForPage(pageUri, data, vreq, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,16 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
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.OntModel;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
@ -15,7 +21,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
||||||
|
|
||||||
public class VitroRequest extends HttpServletRequestWrapper {
|
public class VitroRequest extends HttpServletRequestWrapper {
|
||||||
|
final static Log log = LogFactory.getLog(VitroRequest.class);
|
||||||
|
|
||||||
//Attribute in case of special model editing such as display model editing
|
//Attribute in case of special model editing such as display model editing
|
||||||
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
|
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
|
||||||
|
|
||||||
|
@ -139,6 +146,35 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
||||||
return jenaOntModel;
|
return jenaOntModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the display and editing configuration model
|
||||||
|
public OntModel getDisplayModel(){
|
||||||
|
//bdc34: I have no idea what the correct way to get this model is
|
||||||
|
|
||||||
|
//try from the request
|
||||||
|
if( _req.getAttribute("displayOntModel") != null ){
|
||||||
|
return (OntModel) _req.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
|
|
||||||
|
//try from the session
|
||||||
|
} else {
|
||||||
|
HttpSession session = _req.getSession(false);
|
||||||
|
if( session != null ){
|
||||||
|
if( session.getAttribute(DISPLAY_ONT_MODEL) != null ){
|
||||||
|
return (OntModel) session.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
|
|
||||||
|
//try from the context
|
||||||
|
}else{
|
||||||
|
if( session.getServletContext().getAttribute(DISPLAY_ONT_MODEL) != null){
|
||||||
|
return (OntModel)session.getServletContext().getAttribute(DISPLAY_ONT_MODEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//nothing worked, could not find display model
|
||||||
|
log.error("No display model could be found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationBean getAppBean(){
|
public ApplicationBean getAppBean(){
|
||||||
//return (ApplicationBean) getAttribute("appBean");
|
//return (ApplicationBean) getAttribute("appBean");
|
||||||
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
|
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
|
||||||
|
|
|
@ -30,7 +30,7 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.SelectDataGetterUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.SelectDataGetterUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Process edits from display model editing, so form should submit to this page which should
|
*Process edits from display model editing, so form should submit to this page which should
|
||||||
|
|
|
@ -215,7 +215,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subclasses will override
|
// Subclasses will override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res
|
||||||
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.pageDataGetter.PageDataGetter;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.DataGetterUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||||
|
|
||||||
public class HomePageController extends FreemarkerHttpServlet {
|
public class HomePageController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class HomePageController extends FreemarkerHttpServlet {
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
List<PageDataGetter> dataGetters = DataGetterUtils.getDataGetterObjects(vreq, DisplayVocabulary.HOME_PAGE_URI);
|
List<PageDataGetter> dataGetters = PageDataGetterUtils.getDataGetterObjects(vreq, DisplayVocabulary.HOME_PAGE_URI);
|
||||||
for(PageDataGetter dataGetter: dataGetters) {
|
for(PageDataGetter dataGetter: dataGetters) {
|
||||||
if( dataGetter != null ){
|
if( dataGetter != null ){
|
||||||
String uriOfPageInDisplayModel = "not defined";
|
String uriOfPageInDisplayModel = "not defined";
|
||||||
|
|
|
@ -24,10 +24,10 @@ 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.DataGetterUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.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.pageDataGetter.PageDataGetter;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.SelectDataGetterUtils;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
|
@ -35,7 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.SelectDataGetterUti
|
||||||
*/
|
*/
|
||||||
public class MenuManagementController extends FreemarkerHttpServlet {
|
public class MenuManagementController extends FreemarkerHttpServlet {
|
||||||
private static final Log log = LogFactory.getLog(MenuManagementController.class);
|
private static final Log log = LogFactory.getLog(MenuManagementController.class);
|
||||||
protected final static String SUBMIT_FORM = "/processEditDisplayModel";
|
protected final static String SUBMIT_FORM = "/menuManagementEdit";
|
||||||
protected final static String CANCEL_FORM = "/individual?uri=http%3A%2F%2Fvitro.mannlib.cornell.edu%2Fontologies%2Fdisplay%2F1.1%23DefaultMenu&switchToDisplayModel=true";
|
protected final static String CANCEL_FORM = "/individual?uri=http%3A%2F%2Fvitro.mannlib.cornell.edu%2Fontologies%2Fdisplay%2F1.1%23DefaultMenu&switchToDisplayModel=true";
|
||||||
protected final static String DELETE_FORM = "menuManagement-remove.ftl";
|
protected final static String DELETE_FORM = "menuManagement-remove.ftl";
|
||||||
protected final static String EDIT_FORM = "menuManagement.ftl";
|
protected final static String EDIT_FORM = "menuManagement.ftl";
|
||||||
|
@ -114,7 +114,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", DataGetterUtils.getClassGroups(getServletContext()));
|
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||||
data.put("selectedTemplateType", "default");
|
data.put("selectedTemplateType", "default");
|
||||||
//
|
//
|
||||||
this.getMenuItemData(vreq, menuItem, data);
|
this.getMenuItemData(vreq, menuItem, data);
|
||||||
|
@ -134,7 +134,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", DataGetterUtils.getClassGroups(getServletContext()));
|
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||||
data.put("selectedTemplateType", "default");
|
data.put("selectedTemplateType", "default");
|
||||||
//defaults to regular class group page
|
//defaults to regular class group page
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,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", DataGetterUtils.getClassGroups(getServletContext()));
|
data.put("classGroups", PageDataGetterUtils.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);
|
||||||
|
@ -273,13 +273,14 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
private void retrieveData(VitroRequest vreq, Resource page, String dataGetterType, Map<String, Object> templateData) {
|
private void retrieveData(VitroRequest vreq, Resource page, String dataGetterType, Map<String, Object> templateData) {
|
||||||
//Data Getter type is now a class name
|
//Data Getter type is now a class name
|
||||||
String className = DataGetterUtils.getClassNameFromUri(dataGetterType);
|
String className = PageDataGetterUtils.getClassNameFromUri(dataGetterType);
|
||||||
try{
|
try{
|
||||||
String pageURI = page.getURI();
|
String pageURI = page.getURI();
|
||||||
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
||||||
Map<String, Object> pageInfo = DataGetterUtils.getMapForPage( vreq, pageURI );
|
|
||||||
|
Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
|
||||||
|
|
||||||
Map<String, Object> pageData = DataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext());
|
Map<String, Object> pageData = PageDataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext());
|
||||||
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 " + className, ex);
|
||||||
|
|
|
@ -4,11 +4,14 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -16,71 +19,90 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||||
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.utils.pageDataGetter.DataGetterUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||||
/**
|
/**
|
||||||
* Controller for getting data for pages defined in the display model.
|
* Controller for getting data for pages defined in the display model.
|
||||||
*
|
*
|
||||||
* This controller passes these variables to the template:
|
* This controller passes these variables to the template:
|
||||||
* page: a map with information about the page from the display model.
|
* page: a map with information about the page from the display model.
|
||||||
*
|
* pageUri: the URI of the page that identifies the page in the model
|
||||||
|
* (note that this is not the URL address of the page).
|
||||||
|
*
|
||||||
* See implementations of PageDataGetter for more variables.
|
* See implementations of PageDataGetter for more variables.
|
||||||
*/
|
*/
|
||||||
public class PageController extends FreemarkerHttpServlet{
|
public class PageController extends FreemarkerHttpServlet{
|
||||||
private static final Log log = LogFactory.getLog(PageController.class);
|
private static final Log log = LogFactory.getLog(PageController.class);
|
||||||
|
|
||||||
protected final static String DEFAULT_TITLE = "Page";
|
protected final static String DEFAULT_TITLE = "Page";
|
||||||
protected final static String DEFAULT_BODY_TEMPLATE = "menupage.ftl";
|
protected final static String DEFAULT_BODY_TEMPLATE = "emptyPage.ftl";
|
||||||
|
|
||||||
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
||||||
try {
|
|
||||||
// get URL without hostname or servlet context
|
Map<String,Object> mapForTemplate = new HashMap<String,Object>();
|
||||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
Map<String,Object>page;
|
||||||
|
|
||||||
Map<String,Object> mapForTemplate = new HashMap<String,Object>();
|
//figure out what page we are trying to get
|
||||||
String pageUri = "";
|
String pageUri = getPageUri( vreq );
|
||||||
Map<String,Object>page;
|
if( StringUtils.isEmpty( pageUri ) )
|
||||||
try {
|
return doNoPageSpecified(vreq);
|
||||||
pageUri = getPageUri( vreq , url );
|
else
|
||||||
page = DataGetterUtils.getMapForPage( vreq, pageUri );
|
mapForTemplate.put("pageUri", pageUri);
|
||||||
mapForTemplate.put( "page", page);
|
|
||||||
if( page.containsKey("title") ){
|
//try to get the page RDF from the model
|
||||||
mapForTemplate.put("title", page.get("title"));
|
try{
|
||||||
}
|
page = vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
||||||
|
mapForTemplate.put( "page", page);
|
||||||
} catch (Throwable th) {
|
if( page.containsKey("title") ){
|
||||||
return doNotFound(vreq);
|
mapForTemplate.put("title", page.get("title"));
|
||||||
}
|
}
|
||||||
|
}catch( Throwable th){
|
||||||
try{
|
return doNotFound(vreq);
|
||||||
mapForTemplate.putAll( DataGetterUtils.getDataForPage(pageUri, vreq, getServletContext()) );
|
|
||||||
} catch( Throwable th){
|
|
||||||
log.error(th,th);
|
|
||||||
return doError(vreq);
|
|
||||||
}
|
|
||||||
//set default in case doesn't exist for data getter
|
|
||||||
if(!mapForTemplate.containsKey("dataServiceUrlIndividualsByVClass")) {
|
|
||||||
mapForTemplate.put("dataServiceUrlIndividualsByVClass", UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId="));
|
|
||||||
}
|
|
||||||
ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate);
|
|
||||||
return rv;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error(e, e);
|
|
||||||
return new ExceptionResponseValues(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executePageDataGetters( pageUri, vreq, getServletContext(), mapForTemplate );
|
||||||
|
executeDataGetters( pageUri, vreq, getServletContext(), mapForTemplate);
|
||||||
|
|
||||||
|
ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void executeDataGetters(String pageUri, VitroRequest vreq, ServletContext context, Map<String, Object> mapForTemplate)
|
||||||
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||||
|
List<DataGetter> dgList = DataGetterUtils.getDataGettersForPage(vreq.getDisplayModel(), pageUri);
|
||||||
|
|
||||||
|
for( DataGetter dg : dgList){
|
||||||
|
Map<String,Object> moreData = dg.getData(context,vreq,mapForTemplate);
|
||||||
|
if( moreData != null ){
|
||||||
|
mapForTemplate.putAll(moreData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executePageDataGetters(String pageUri, VitroRequest vreq, ServletContext context, Map<String, Object> mapForTemplate) {
|
||||||
|
mapForTemplate.putAll( PageDataGetterUtils.getDataForPage(pageUri, vreq, context) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getTemplate(Map<String, Object> mapForTemplate) {
|
private String getTemplate(Map<String, Object> mapForTemplate) {
|
||||||
|
//first try to get the body template from the display model RDF
|
||||||
if( mapForTemplate.containsKey("page") ){
|
if( mapForTemplate.containsKey("page") ){
|
||||||
Map page = (Map) mapForTemplate.get("page");
|
Map page = (Map) mapForTemplate.get("page");
|
||||||
if( page != null && page.containsKey("bodyTemplate"))
|
if( page != null && page.containsKey("bodyTemplate")){
|
||||||
return (String) page.get("bodyTemplate");
|
return (String) page.get("bodyTemplate");
|
||||||
else
|
}
|
||||||
return DEFAULT_BODY_TEMPLATE;
|
}
|
||||||
}else
|
//next, try to get body template from the data getter values
|
||||||
return DEFAULT_BODY_TEMPLATE;
|
if( mapForTemplate.containsKey("bodyTemplate") ){
|
||||||
|
return (String) mapForTemplate.get("bodyTemplate");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Nothing? then use a default empty page
|
||||||
|
return DEFAULT_BODY_TEMPLATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +110,7 @@ public class PageController extends FreemarkerHttpServlet{
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("title","Page could not be created");
|
body.put("title","Page could not be created");
|
||||||
body.put("errorMessage", "There was an error while creating the page, please check the logs.");
|
body.put("errorMessage", "There was an error while creating the page, please check the logs.");
|
||||||
return new TemplateResponseValues(Template.TITLED_ERROR_MESSAGE.toString(), body, HttpServletResponse.SC_NOT_FOUND);
|
return new TemplateResponseValues(Template.TITLED_ERROR_MESSAGE.toString(), body, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseValues doNotFound(VitroRequest vreq) {
|
private ResponseValues doNotFound(VitroRequest vreq) {
|
||||||
|
@ -99,18 +121,26 @@ public class PageController extends FreemarkerHttpServlet{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ResponseValues doNoPageSpecified(VitroRequest vreq) {
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
body.put("title","No page URI specified");
|
||||||
|
body.put("errorMessage", "Could not generate page beacause it was unclear what page was being requested. A URL mapping may be missing.");
|
||||||
|
return new TemplateResponseValues(Template.TITLED_ERROR_MESSAGE.toString(), body, HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the page URI from the request. The page must be defined in the display model.
|
* Gets the page URI from the request. The page must be defined in the display model.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private String getPageUri(VitroRequest vreq, String url) throws Exception {
|
private String getPageUri(VitroRequest vreq) throws Exception {
|
||||||
//check if there is a page URI in the request. This would have
|
// get URL without hostname or servlet context
|
||||||
//been added by a servlet Filter.
|
//bdc34: why are we getting this?
|
||||||
String pageURI = (String) vreq.getAttribute("pageURI");
|
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||||
if( pageURI != null && ! pageURI.isEmpty() )
|
|
||||||
return pageURI;
|
// Check if there is a page URI in the request.
|
||||||
else
|
// This would have been added by a servlet Filter.
|
||||||
throw new Exception("no page found for " + vreq.getRequestURI() );
|
String pageURI = (String) vreq.getAttribute("pageURI");
|
||||||
|
return pageURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
|
|
||||||
static protected Query pageQuery;
|
static protected Query pageQuery;
|
||||||
static protected Query pageTypeQuery;
|
static protected Query pageTypeQuery;
|
||||||
static protected Query pageDataGettersQuery;
|
static protected Query pageDataGetterTypeQuery;
|
||||||
|
static protected Query dataGetterURIsQuery;
|
||||||
static protected Query pageMappingsQuery;
|
static protected Query pageMappingsQuery;
|
||||||
static protected Query homePageUriQuery;
|
static protected Query homePageUriQuery;
|
||||||
static protected Query classGroupPageQuery;
|
static protected Query classGroupPageQuery;
|
||||||
|
@ -46,7 +47,7 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
static protected Query individualsForClassesRestrictedQuery;
|
static protected Query individualsForClassesRestrictedQuery;
|
||||||
static protected Query institutionalInternalClassQuery;
|
static protected Query institutionalInternalClassQuery;
|
||||||
static protected Query individualsForClassesInternalQuery;
|
static protected Query individualsForClassesInternalQuery;
|
||||||
static protected Query dataGetterClassQuery;
|
static protected Query dataGetterClassQuery;
|
||||||
|
|
||||||
static final String prefixes =
|
static final String prefixes =
|
||||||
"PREFIX rdf: <" + VitroVocabulary.RDF +"> \n" +
|
"PREFIX rdf: <" + VitroVocabulary.RDF +"> \n" +
|
||||||
|
@ -70,13 +71,21 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
" ?pageUri rdf:type ?type .\n"+
|
" ?pageUri rdf:type ?type .\n"+
|
||||||
"} \n" ;
|
"} \n" ;
|
||||||
|
|
||||||
//Get data getters
|
//Get data getter types
|
||||||
static final protected String pageDataGettersQueryString =
|
static final protected String pageDataGetterTypesQueryString =
|
||||||
prefixes + "\n" +
|
prefixes + "\n" +
|
||||||
"SELECT ?dataGetter WHERE {\n" +
|
"SELECT ?dataGetterType WHERE {\n" +
|
||||||
" ?pageUri display:hasDataGetter ?dg .\n"+
|
" ?pageUri display:hasDataGetter ?dg .\n"+
|
||||||
" ?dg rdf:type ?dataGetter . \n" +
|
" ?dg rdf:type ?dataGetterType . \n" +
|
||||||
"} \n" ;
|
"} \n" ;
|
||||||
|
|
||||||
|
//Get data getter URIs
|
||||||
|
static final protected String dataGetterURIsQueryString =
|
||||||
|
prefixes + "\n" +
|
||||||
|
"SELECT ?dg WHERE {\n" +
|
||||||
|
" ?pageUri display:hasDataGetter ?dg .\n"+
|
||||||
|
"}" ;
|
||||||
|
|
||||||
static final protected String pageMappingsQueryString =
|
static final protected String pageMappingsQueryString =
|
||||||
prefixes + "\n" +
|
prefixes + "\n" +
|
||||||
"SELECT ?pageUri ?urlMapping WHERE {\n" +
|
"SELECT ?pageUri ?urlMapping WHERE {\n" +
|
||||||
|
@ -155,11 +164,17 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
log.error(pageTypeQueryString);
|
log.error(pageTypeQueryString);
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
pageDataGettersQuery = QueryFactory.create(pageDataGettersQueryString);
|
pageDataGetterTypeQuery = QueryFactory.create(pageDataGetterTypesQueryString);
|
||||||
}catch(Throwable th){
|
}catch(Throwable th){
|
||||||
log.error("could not create SPARQL query for pageTypeQuery " + th.getMessage());
|
log.error("could not create SPARQL query for pageTypeQuery " + th.getMessage());
|
||||||
log.error(pageDataGettersQueryString);
|
log.error(pageDataGetterTypesQueryString);
|
||||||
}
|
}
|
||||||
|
try{
|
||||||
|
dataGetterURIsQuery = QueryFactory.create(dataGetterURIsQueryString);
|
||||||
|
}catch(Throwable th){
|
||||||
|
log.error("could not create SPARQL query for dataGetterURIsQuery " + th.getMessage());
|
||||||
|
log.error(dataGetterURIsQueryString);
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
pageMappingsQuery=QueryFactory.create(pageMappingsQueryString);
|
pageMappingsQuery=QueryFactory.create(pageMappingsQueryString);
|
||||||
}catch(Throwable th){
|
}catch(Throwable th){
|
||||||
|
@ -279,30 +294,36 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
log.debug("multiple results found for " + pageUri + " using only the first.");
|
log.debug("multiple results found for " + pageUri + " using only the first.");
|
||||||
Map<String,Object> pageData = list.get(0);
|
Map<String,Object> pageData = list.get(0);
|
||||||
|
|
||||||
//now get the rdf:types for the page
|
//now get the rdf:types for the data getters for the page
|
||||||
//Changing to get the data getters for the page (already know that it's a page type)
|
List<String> dataGetterTypes = new ArrayList<String>();
|
||||||
List<String> dataGetters = new ArrayList<String>();
|
|
||||||
displayModel.enterCriticalSection(false);
|
displayModel.enterCriticalSection(false);
|
||||||
try{
|
try{
|
||||||
QueryExecution qexec = QueryExecutionFactory.create(pageDataGettersQuery, displayModel, initialBindings);
|
QueryExecution qexec = QueryExecutionFactory.create(pageDataGetterTypeQuery, displayModel, initialBindings);
|
||||||
try{
|
try{
|
||||||
ResultSet rs = qexec.execSelect();
|
ResultSet rs = qexec.execSelect();
|
||||||
while(rs.hasNext()){
|
while(rs.hasNext()){
|
||||||
QuerySolution soln = rs.next();
|
QuerySolution soln = rs.next();
|
||||||
dataGetters.add( nodeToString( soln.get("dataGetter" ) ));
|
dataGetterTypes.add( nodeToString( soln.get("dataGetterType" ) ));
|
||||||
}
|
}
|
||||||
}finally{
|
}finally{ qexec.close(); }
|
||||||
qexec.close();
|
}finally{ displayModel.leaveCriticalSection(); }
|
||||||
}
|
pageData.put("dataGetterTypes", dataGetterTypes);
|
||||||
}finally{
|
|
||||||
displayModel.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( list == null )
|
//now get URIs of DataGetters for page.
|
||||||
log.error("could not get data getters for page " + pageUri);
|
List<String> dataGetterURIs = new ArrayList<String>();
|
||||||
else
|
displayModel.enterCriticalSection(false);
|
||||||
pageData.put("dataGetters", dataGetters);
|
try{
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(dataGetterURIsQuery, displayModel, initialBindings);
|
||||||
|
try{
|
||||||
|
ResultSet rs = qexec.execSelect();
|
||||||
|
while(rs.hasNext()){
|
||||||
|
QuerySolution soln = rs.next();
|
||||||
|
dataGetterURIs.add( nodeToString( soln.get("dg" ) ));
|
||||||
|
}
|
||||||
|
}finally{ qexec.close(); }
|
||||||
|
}finally{ displayModel.leaveCriticalSection(); }
|
||||||
|
|
||||||
|
pageData.put("dataGetterURIs", dataGetterURIs);
|
||||||
return pageData;
|
return pageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,12 @@ public class EditConfigurationUtils {
|
||||||
//DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
//DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||||
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||||
DataProperty dataProp = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
DataProperty dataProp = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||||
return dataProp;
|
if( dataProp != null )
|
||||||
|
return dataProp;
|
||||||
|
else{
|
||||||
|
//when editing the display model, unfitlering wdf doesn't seem to have the needed properties.
|
||||||
|
return wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get url without context - used for edit configuration object
|
//get url without context - used for edit configuration object
|
||||||
|
|
|
@ -56,6 +56,10 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||||
//This used to get the model from the servlet context
|
//This used to get the model from the servlet context
|
||||||
// Model model = (Model) getServletContext().getAttribute("jenaOntModel");
|
// Model model = (Model) getServletContext().getAttribute("jenaOntModel");
|
||||||
|
|
||||||
|
//PROBLEM: this is returning the jenaOntModel
|
||||||
|
// but we want the current abox model which might have
|
||||||
|
// been set to the display model or something.
|
||||||
Model model = vreq.getJenaOntModel();
|
Model model = vreq.getJenaOntModel();
|
||||||
|
|
||||||
if( editConfig.getSubjectUri() == null)
|
if( editConfig.getSubjectUri() == null)
|
||||||
|
|
|
@ -44,12 +44,14 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
||||||
String predicateUri = vreq.getParameter("predicateUri");
|
String predicateUri = vreq.getParameter("predicateUri");
|
||||||
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||||
DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||||
|
|
||||||
|
dataproperty = vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||||
if( dataproperty == null) {
|
if( dataproperty == null) {
|
||||||
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
||||||
// This is controlled by the Jena layer, so we can't change the behavior.
|
// This is controlled by the Jena layer, so we can't change the behavior.
|
||||||
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
||||||
log.error("Could not find data property '"+predicateUri+"' in model");
|
log.error("Could not find data property '"+predicateUri+"' in model");
|
||||||
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
throw new Error("Could not find DataProperty in model: " + predicateUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -460,7 +462,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
//TODO: Check how model is retrieved
|
//TODO: Check how model is retrieved
|
||||||
OntModel displayOntModel =
|
OntModel displayOntModel =
|
||||||
(OntModel) session.getServletContext()
|
(OntModel) session.getServletContext()
|
||||||
.getAttribute("displayOntModel");
|
.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
if (displayOntModel != null) {
|
if (displayOntModel != null) {
|
||||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -463,7 +465,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
||||||
// individuals from classes that should be hidden from list views
|
// individuals from classes that should be hidden from list views
|
||||||
OntModel displayOntModel =
|
OntModel displayOntModel =
|
||||||
(OntModel) session.getServletContext()
|
(OntModel) session.getServletContext()
|
||||||
.getAttribute("displayOntModel");
|
.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
if (displayOntModel != null) {
|
if (displayOntModel != null) {
|
||||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||||
|
|
|
@ -13,6 +13,8 @@ import javax.servlet.http.HttpSession;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
@ -34,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmis
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.EditConfigurationTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.EditConfigurationTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.MultiValueEditSubmissionTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.MultiValueEditSubmissionTemplateModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This servlet is intended to handle all requests to create a form for use
|
* This servlet is intended to handle all requests to create a form for use
|
||||||
* by the N3 editing system. It will examine the request parameters, determine
|
* by the N3 editing system. It will examine the request parameters, determine
|
||||||
|
@ -130,15 +133,19 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
private boolean isMenuMode(VitroRequest vreq) {
|
private boolean isMenuMode(VitroRequest vreq) {
|
||||||
//Check if special model, in which case forward
|
//Check if special model, in which case forward
|
||||||
return(vreq.getParameter("switchToDisplayModel") != null);
|
//bdc34: the EditRequestDispatchController cannot hijack
|
||||||
|
// all edits to the display model and force them into /editDisplayModel .
|
||||||
|
// Consider changing URLs used on special menu form to point to /editMenu or something.
|
||||||
|
//return(vreq.getParameter("switchToDisplayModel") != null);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseValues redirectToMenuEdit(VitroRequest vreq) {
|
private ResponseValues redirectToMenuEdit(VitroRequest vreq) {
|
||||||
String queryString = vreq.getQueryString();
|
throw new RuntimeException("The EditRequestDispatchController cannot hijack"+
|
||||||
String redirectPage = vreq.getContextPath() + "/editDisplayModel?" + queryString;
|
"all edits to the display model and force them into /editDisplayModel ."+
|
||||||
return new DirectRedirectResponseValues(redirectPage, HttpServletResponse.SC_SEE_OTHER);
|
" Consider changing URLs used on special menu form to point to /editDisplayModel");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiValueEditSubmission getMultiValueSubmission(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
private MultiValueEditSubmission getMultiValueSubmission(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||||
return EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig);
|
return EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig);
|
||||||
}
|
}
|
||||||
|
@ -169,58 +176,72 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Additional forwards.. should they be processed here to see which form should be forwarded to
|
/**
|
||||||
//e.g. default add individual form etc. and additional scenarios
|
* Determine the java class name to use for the EditConfigurationGenerator.
|
||||||
//TODO: Check if additional scenarios should be checked here
|
*
|
||||||
|
* Forwarding should NOT be done here. If an EditConfiguration needs to
|
||||||
|
* forward to a URL use editConfig.getSkipToUrl(). Also consider using a skip predicate annotation.
|
||||||
|
*/
|
||||||
private String processEditConfGeneratorName(VitroRequest vreq) {
|
private String processEditConfGeneratorName(VitroRequest vreq) {
|
||||||
|
String editConfGeneratorName = null;
|
||||||
//Handle deletion before any of the other cases
|
|
||||||
if(isDeleteForm(vreq)) {
|
String predicateUri = getPredicateUri(vreq);
|
||||||
return DEFAULT_DELETE_FORM;
|
|
||||||
}
|
// *** handle the case where the form is specified as a request parameter ***
|
||||||
|
|
||||||
//use default object property form if nothing else works
|
|
||||||
//or default data property form if the predicate in this case is data property
|
|
||||||
String editConfGeneratorName = DEFAULT_OBJ_FORM;
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
String predicateUri = getPredicateUri(vreq);
|
|
||||||
Property prop = getPropertyByUri(predicateUri, wdf);
|
|
||||||
//If we want to have data property custom form, we need to consider that as well
|
|
||||||
if(isDataProperty( prop , wdf )){
|
|
||||||
editConfGeneratorName = DEFAULT_DATA_FORM;
|
|
||||||
}
|
|
||||||
// *** handle the case where the form is specified as a request parameter ***
|
|
||||||
String formParam = getFormParam(vreq);
|
String formParam = getFormParam(vreq);
|
||||||
if( formParam != null && !formParam.isEmpty() ){
|
if( formParam != null && !formParam.isEmpty() ){
|
||||||
|
// please, always do this case first.
|
||||||
//form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation.
|
//form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation.
|
||||||
return formParam;
|
editConfGeneratorName = formParam;
|
||||||
|
|
||||||
|
// *** do magic cmd=delete
|
||||||
|
}else if(isDeleteForm(vreq)) {
|
||||||
|
//TODO: cmd=delete would be better if it was moved to the the EditConfigurationGenerator that uses it.
|
||||||
|
return DEFAULT_DELETE_FORM;
|
||||||
|
|
||||||
|
// *** check for a predicate URI in the request
|
||||||
|
}else if( predicateUri != null && !predicateUri.isEmpty() ){
|
||||||
|
Property prop = getProperty( predicateUri, vreq);
|
||||||
|
if( prop != null && prop.getCustomEntryForm() != null ){
|
||||||
|
//there is a custom form, great! let's use it.
|
||||||
|
editConfGeneratorName = prop.getCustomEntryForm();
|
||||||
|
|
||||||
|
}else if( RDFS.label.getURI().equals( predicateUri ) ) {
|
||||||
|
// set RDFS_LABLE_FORM after a custom entry form on the property
|
||||||
|
// so that there is a chance that rdfs:label could have a configurable
|
||||||
|
// custom form it the future
|
||||||
|
editConfGeneratorName = RDFS_LABEL_FORM;
|
||||||
|
|
||||||
|
}else if( isDataProperty(prop) ){
|
||||||
|
editConfGeneratorName = DEFAULT_DATA_FORM;
|
||||||
|
}else{
|
||||||
|
editConfGeneratorName = DEFAULT_OBJ_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// *** default to the object property form when there is nothing
|
||||||
|
}else{
|
||||||
|
editConfGeneratorName = DEFAULT_OBJ_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( isVitroLabel(predicateUri) ) { //in case of data property
|
if( editConfGeneratorName == null )
|
||||||
return RDFS_LABEL_FORM;
|
log.error("problem: editConfGeneratorName is null but " +
|
||||||
}
|
"processEditConfGeneratorName() should never return null.");
|
||||||
|
|
||||||
//now if there is a custom form, for either data or object property, that form will be used
|
|
||||||
String customForm = prop.getCustomEntryForm();
|
|
||||||
if(customForm != null && !customForm.trim().isEmpty()) {
|
|
||||||
editConfGeneratorName = customForm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
log.debug("generator name is " + editConfGeneratorName);
|
log.debug("generator name is " + editConfGeneratorName);
|
||||||
return editConfGeneratorName;
|
return editConfGeneratorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCustomForm(String predicateUri, WebappDaoFactory wdf) {
|
private Property getProperty(String predicateUri, VitroRequest vreq) {
|
||||||
Property prop = getPropertyByUri(predicateUri, wdf);
|
|
||||||
return prop.getCustomEntryForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Property getPropertyByUri(String predicateUri, WebappDaoFactory wdf) {
|
|
||||||
Property p = null;
|
Property p = null;
|
||||||
p = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
try{
|
||||||
if(p == null) {
|
p = vreq.getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||||
p = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
if(p == null) {
|
||||||
|
p = vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||||
|
}
|
||||||
|
}catch( Throwable th){
|
||||||
|
//ignore problems
|
||||||
|
log.debug("Not really a problem if we cannot get a property because we "+
|
||||||
|
"might be editing arbritrary RDF", th);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -229,16 +250,8 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
return predicateUri.equals(VitroVocabulary.LABEL);
|
return predicateUri.equals(VitroVocabulary.LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDataProperty(Property prop, WebappDaoFactory wdf) {
|
private boolean isDataProperty( Property prop ) {
|
||||||
if( prop != null && prop instanceof DataProperty ){
|
return ( prop != null && prop instanceof DataProperty );
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(prop.getURI());
|
|
||||||
if( dataProp != null )
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -345,12 +358,9 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
private EditConfigurationVTwo makeEditConfigurationVTwo(
|
private EditConfigurationVTwo makeEditConfigurationVTwo(
|
||||||
String editConfGeneratorName, VitroRequest vreq, HttpSession session) {
|
String editConfGeneratorName, VitroRequest vreq, HttpSession session) {
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.filters;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.controller.VitroRequest.SPECIAL_WRITE_MODEL;
|
import static edu.cornell.mannlib.vitro.webapp.controller.VitroRequest.SPECIAL_WRITE_MODEL;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.CONTEXT_DISPLAY_TBOX;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.CONTEXT_DISPLAY_TBOX;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SWITCH_TO_DISPLAY_MODEL;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SWITCH_TO_DISPLAY_MODEL;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM;
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM;
|
||||||
|
@ -229,7 +230,7 @@ public class VitroRequestPrep implements Filter {
|
||||||
|
|
||||||
// If they asked for the display model, give it to them.
|
// If they asked for the display model, give it to them.
|
||||||
if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) {
|
if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) {
|
||||||
OntModel mainOntModel = (OntModel)_context.getAttribute("displayOntModel");
|
OntModel mainOntModel = (OntModel)_context.getAttribute( DISPLAY_ONT_MODEL);
|
||||||
OntModel tboxOntModel = (OntModel) _context.getAttribute(CONTEXT_DISPLAY_TBOX);
|
OntModel tboxOntModel = (OntModel) _context.getAttribute(CONTEXT_DISPLAY_TBOX);
|
||||||
setSpecialWriteModel(vreq, mainOntModel);
|
setSpecialWriteModel(vreq, mainOntModel);
|
||||||
return createNewWebappDaoFactory(wadf, mainOntModel, tboxOntModel, null);
|
return createNewWebappDaoFactory(wadf, mainOntModel, tboxOntModel, null);
|
||||||
|
@ -294,6 +295,9 @@ public class VitroRequestPrep implements Filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSpecialWriteModel(VitroRequest vreq, OntModel mainOntModel) {
|
private void setSpecialWriteModel(VitroRequest vreq, OntModel mainOntModel) {
|
||||||
|
//bdc34: not clear where the special model needs to be set.
|
||||||
|
vreq.setAttribute("jenaOntModel", mainOntModel);
|
||||||
|
|
||||||
if (mainOntModel != null) {
|
if (mainOntModel != null) {
|
||||||
vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel);
|
vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -94,7 +96,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
unionOms.setUserAccountsModel(userAccountsModel);
|
unionOms.setUserAccountsModel(userAccountsModel);
|
||||||
|
|
||||||
OntModel displayModel = ontModelFromContextAttribute(
|
OntModel displayModel = ontModelFromContextAttribute(
|
||||||
ctx,"displayOntModel");
|
ctx,DISPLAY_ONT_MODEL);
|
||||||
baseOms.setDisplayModel(displayModel);
|
baseOms.setDisplayModel(displayModel);
|
||||||
inferenceOms.setDisplayModel(displayModel);
|
inferenceOms.setDisplayModel(displayModel);
|
||||||
unionOms.setDisplayModel(displayModel);
|
unionOms.setDisplayModel(displayModel);
|
||||||
|
|
|
@ -132,8 +132,8 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
static final String JENA_DISPLAY_TBOX_MODEL =
|
static final String JENA_DISPLAY_TBOX_MODEL =
|
||||||
DisplayVocabulary.DISPLAY_TBOX_MODEL_URI;
|
DisplayVocabulary.DISPLAY_TBOX_MODEL_URI;
|
||||||
static final String JENA_DISPLAY_DISPLAY_MODEL =
|
static final String JENA_DISPLAY_DISPLAY_MODEL =
|
||||||
DisplayVocabulary.DISPLAY_DISPLAY_MODEL_URI;
|
DisplayVocabulary.DISPLAY_DISPLAY_MODEL_URI;
|
||||||
|
|
||||||
// use OWL models with no reasoning
|
// use OWL models with no reasoning
|
||||||
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
@ -78,7 +80,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
OntModel displayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel displayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
displayModel.add(displayDbModel);
|
displayModel.add(displayDbModel);
|
||||||
displayModel.getBaseModel().register(new ModelSynchronizer(displayDbModel));
|
displayModel.getBaseModel().register(new ModelSynchronizer(displayDbModel));
|
||||||
ctx.setAttribute("displayOntModel", displayModel);
|
ctx.setAttribute(DISPLAY_ONT_MODEL, displayModel);
|
||||||
|
|
||||||
//at each startup load all RDF files from directory to sub-models of display model
|
//at each startup load all RDF files from directory to sub-models of display model
|
||||||
initializeDisplayLoadedAtStartup(ctx, displayModel);
|
initializeDisplayLoadedAtStartup(ctx, displayModel);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -130,7 +132,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doMigrateDisplayModel(ServletContext ctx) {
|
private void doMigrateDisplayModel(ServletContext ctx) {
|
||||||
Object o = ctx.getAttribute("displayOntModel");
|
Object o = ctx.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
if (!(o instanceof OntModel)) {
|
if (!(o instanceof OntModel)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to get data based on configurations in RDF. These are useful for pages bug not specific to pages.
|
||||||
|
* Consider using this interface when you need data based on RDF configuration.
|
||||||
|
*
|
||||||
|
* The main difference between this and PageDataGetter is that these are configured not based on page URI
|
||||||
|
* but on DataGetter URI. This allows a configuration of a DataGetter to be used in multiple situations.
|
||||||
|
* The DataGetter is not passed information about what page it might be associated with.
|
||||||
|
*
|
||||||
|
* Using this interface is preferred over PageDataGetter because then the DataGetter can be associated with
|
||||||
|
* things other than pages.
|
||||||
|
*/
|
||||||
|
public interface DataGetter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get data. Throwing an Exception is acceptable.
|
||||||
|
*
|
||||||
|
* @param context - servlet context to get state from
|
||||||
|
* @param vreq - request to get state from
|
||||||
|
* @param valueMap - any values already generated by data getters or the controller.
|
||||||
|
* @return data to add to valueMap. Should not be null.
|
||||||
|
*/
|
||||||
|
Map<String,Object> getData(ServletContext context, VitroRequest vreq, Map<String, Object> valueMap );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the DataGetter for a specific Resource.
|
||||||
|
*
|
||||||
|
* In order to create and configure instances of classes that implement this interface,
|
||||||
|
* we need a constructor like method. But interfaces cannot define constructors. A
|
||||||
|
* method like this is not ideal. Maybe this should be moved to a factory.
|
||||||
|
*
|
||||||
|
* To create an instance of a class that implements this interface, instantiate an object
|
||||||
|
* of the class, then call this method. If there are any problems calling configure, consider
|
||||||
|
* the object useless.
|
||||||
|
*
|
||||||
|
* @param displayModel - source of configuration info for resource with dataGetterURI
|
||||||
|
* @param dataGetterURI - URI of resource to use to configure this object.
|
||||||
|
*/
|
||||||
|
void configure(Model displayModel, String dataGetterURI);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||||
|
|
||||||
|
public class DataGetterUtils {
|
||||||
|
|
||||||
|
final static Log log = LogFactory.getLog(DataGetterUtils.class);
|
||||||
|
|
||||||
|
public static List<DataGetter> getDataGettersForPage( Model displayModel, String pageURI)
|
||||||
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException{
|
||||||
|
//get data getter uris for pageURI
|
||||||
|
List<String> dgUris = getDataGetterURIsForPageURI( displayModel, pageURI);
|
||||||
|
|
||||||
|
List<DataGetter> dgList = new ArrayList<DataGetter>();
|
||||||
|
for( String dgURI: dgUris){
|
||||||
|
DataGetter dg =dataGetterForURI(displayModel, dgURI) ;
|
||||||
|
if( dg != null )
|
||||||
|
dgList.add(dg);
|
||||||
|
}
|
||||||
|
return dgList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May return null.
|
||||||
|
*/
|
||||||
|
public static DataGetter dataGetterForURI(Model displayModel, String dataGetterURI) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||||
|
|
||||||
|
//get java class for dataGetterURI
|
||||||
|
String dgClassName = getJClassForDataGetterURI(displayModel, dataGetterURI);
|
||||||
|
|
||||||
|
//construct class
|
||||||
|
Object obj = Class.forName(dgClassName).newInstance();
|
||||||
|
|
||||||
|
if( !(obj instanceof DataGetter) ){
|
||||||
|
log.debug("For <" + dataGetterURI + "> the class " +
|
||||||
|
"for its rdf:type " + dgClassName + " does not implement the interface DataGetter.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataGetter dg = (DataGetter)obj;
|
||||||
|
dg.configure(displayModel, dataGetterURI);
|
||||||
|
return dg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getJClassForDataGetterURI(Model displayModel, String dataGetterURI) throws IllegalAccessException {
|
||||||
|
String query = prefixes +
|
||||||
|
"SELECT ?type WHERE { ?dgURI rdf:type ?type } ";
|
||||||
|
Query dgTypeQuery = QueryFactory.create(query);
|
||||||
|
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add("dgURI", ResourceFactory.createResource( dataGetterURI ));
|
||||||
|
|
||||||
|
List<String> types = new ArrayList<String>();
|
||||||
|
displayModel.enterCriticalSection(false);
|
||||||
|
try{
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(dgTypeQuery,displayModel,initialBindings );
|
||||||
|
try{
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.nextSolution();
|
||||||
|
Resource type = soln.getResource("type");
|
||||||
|
if( type != null && type.getURI() != null){
|
||||||
|
types.add( PageDataGetterUtils.getClassNameFromUri( type.getURI() ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally{ qexec.close(); }
|
||||||
|
}finally{ displayModel.leaveCriticalSection(); }
|
||||||
|
|
||||||
|
|
||||||
|
return chooseType( types, displayModel, dataGetterURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static List<String> getDataGetterURIsForPageURI(Model displayModel, String pageURI) {
|
||||||
|
String query = prefixes +
|
||||||
|
"SELECT ?dataGetter WHERE { ?pageURI display:hasDataGetter ?dataGetter }";
|
||||||
|
Query dgForPageQuery = QueryFactory.create(query);
|
||||||
|
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add("pageURI", ResourceFactory.createResource( pageURI ));
|
||||||
|
|
||||||
|
List<String> dgURIs = new ArrayList<String>();
|
||||||
|
displayModel.enterCriticalSection(false);
|
||||||
|
try{
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(dgForPageQuery,displayModel,initialBindings );
|
||||||
|
try{
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.nextSolution();
|
||||||
|
Resource dg = soln.getResource("dataGetter");
|
||||||
|
if( dg != null && dg.getURI() != null){
|
||||||
|
dgURIs.add( dg.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally{ qexec.close(); }
|
||||||
|
}finally{ displayModel.leaveCriticalSection(); }
|
||||||
|
|
||||||
|
return dgURIs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String chooseType(List<String> types, Model displayModel, String dataGetterURI) throws IllegalAccessException {
|
||||||
|
//currently just get the first one that is not owl:Thing
|
||||||
|
for(String type : types){
|
||||||
|
if( ! StringUtils.isEmpty( type ) && !type.equals( OWL.Thing.getURI() ))
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
throw new IllegalAccessException("No useful type defined for <" + dataGetterURI + ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
static final String prefixes =
|
||||||
|
"PREFIX rdf: <" + VitroVocabulary.RDF +"> \n" +
|
||||||
|
"PREFIX rdfs: <" + VitroVocabulary.RDFS +"> \n" +
|
||||||
|
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" +
|
||||||
|
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,224 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
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;
|
||||||
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
|
|
||||||
|
public class SparqlQueryDataGetter implements DataGetter{
|
||||||
|
String pageUri;
|
||||||
|
String query;
|
||||||
|
String saveToVar;
|
||||||
|
String modelUri;
|
||||||
|
|
||||||
|
final static Log log = LogFactory.getLog(SparqlQueryDataGetter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getData(ServletContext context, VitroRequest vreq, Map<String, Object> pageData) {
|
||||||
|
if( pageUri == null )
|
||||||
|
throw new IllegalAccessError("configure() must be called before getData()");
|
||||||
|
|
||||||
|
return doQuery( vreq.getParameterMap(),getModelToRunQueryOn(context, vreq ));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(Model model, String dataGetterURI) {
|
||||||
|
if( model == null )
|
||||||
|
throw new IllegalArgumentException("Display Model may not be null.");
|
||||||
|
if( dataGetterURI == null )
|
||||||
|
throw new IllegalArgumentException("PageUri may not be null.");
|
||||||
|
|
||||||
|
this.pageUri = dataGetterURI;
|
||||||
|
|
||||||
|
QuerySolutionMap initBindings = new QuerySolutionMap();
|
||||||
|
initBindings.add("pageUri", ResourceFactory.createResource(this.pageUri));
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
Query query = QueryFactory.create(pageQuery) ;
|
||||||
|
model.enterCriticalSection(Lock.READ);
|
||||||
|
try{
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(query, model, initBindings) ;
|
||||||
|
ResultSet res = qexec.execSelect();
|
||||||
|
try{
|
||||||
|
while( res.hasNext() ){
|
||||||
|
count++;
|
||||||
|
QuerySolution soln = res.next();
|
||||||
|
|
||||||
|
//query is not OPTIONAL
|
||||||
|
Literal value = soln.getLiteral("query");
|
||||||
|
if( query == null )
|
||||||
|
log.error("no query defined for page " + this.pageUri);
|
||||||
|
else
|
||||||
|
this.query = value.getLexicalForm();
|
||||||
|
|
||||||
|
//model is OPTIONAL
|
||||||
|
RDFNode node = soln.getResource("model");
|
||||||
|
if( node != null && node.isURIResource() ){
|
||||||
|
this.modelUri = node.asResource().getURI();
|
||||||
|
}else if( node != null && node.isLiteral() ){
|
||||||
|
this.modelUri = node.asLiteral().getLexicalForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
//saveToVar is OPTIONAL
|
||||||
|
node = soln.getResource("saveToVar");
|
||||||
|
if( node != null && node.isLiteral() ){
|
||||||
|
this.saveToVar= node.asLiteral().getLexicalForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally{ qexec.close(); }
|
||||||
|
}finally{ model.leaveCriticalSection(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do the query and return a result. This is in its own method
|
||||||
|
* to make testing easy.
|
||||||
|
*/
|
||||||
|
private Map<String, Object> doQuery(Map<String, String[]>parameterMap, Model queryModel){
|
||||||
|
|
||||||
|
if( this.query == null ){
|
||||||
|
log.error("no SPARQL query defined for page " + this.pageUri);
|
||||||
|
//TODO: return an error message?
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
try{
|
||||||
|
query = QueryFactory.create( this.query );
|
||||||
|
}catch(Exception ex){
|
||||||
|
//TODO: return an error message?
|
||||||
|
log.error( "for page " + this.pageUri, ex );
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
//build query bindings
|
||||||
|
QuerySolutionMap initialBindings = createBindings( parameterMap);
|
||||||
|
|
||||||
|
//execute query
|
||||||
|
List<Map<String,String>> results = executeQuery( query, queryModel, initialBindings);
|
||||||
|
|
||||||
|
//put results in page data, what key to use for results?
|
||||||
|
Map<String, Object> rmap = new HashMap<String,Object>();
|
||||||
|
rmap.put(this.saveToVar, results);
|
||||||
|
return rmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, String>> executeQuery(Query query, Model model,
|
||||||
|
QuerySolutionMap initialBindings) {
|
||||||
|
|
||||||
|
List<Map<String,String>> rows = new ArrayList<Map<String,String>>();
|
||||||
|
|
||||||
|
model.enterCriticalSection(Lock.READ);
|
||||||
|
try{
|
||||||
|
QueryExecution qexec= QueryExecutionFactory.create(query, model,initialBindings );
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
try{
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.nextSolution();
|
||||||
|
rows.add( toRow( soln ) );
|
||||||
|
}
|
||||||
|
}finally{ qexec.close(); }
|
||||||
|
}finally{ model.leaveCriticalSection(); }
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a row from a QuerySolution to a Map<String,String>
|
||||||
|
*/
|
||||||
|
private Map<String, String> toRow(QuerySolution soln) {
|
||||||
|
HashMap<String,String> row = new HashMap<String,String>();
|
||||||
|
Iterator<String> varNames = soln.varNames();
|
||||||
|
while( varNames.hasNext()){
|
||||||
|
String varname = varNames.next();
|
||||||
|
row.put(varname, toCell( soln.get(varname)));
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toCell(RDFNode rdfNode) {
|
||||||
|
if( rdfNode == null){
|
||||||
|
return "";
|
||||||
|
}else if( rdfNode.canAs( Literal.class )){
|
||||||
|
return ((Literal)rdfNode.as(Literal.class)).getLexicalForm();
|
||||||
|
}else if( rdfNode.isResource() ){
|
||||||
|
Resource resource = (Resource)rdfNode;
|
||||||
|
if( ! resource.isAnon() ){
|
||||||
|
return resource.getURI();
|
||||||
|
}else{
|
||||||
|
return resource.getId().getLabelString();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return rdfNode.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Model getModelToRunQueryOn(ServletContext context, VitroRequest vreq ) {
|
||||||
|
//just use JenaOntModel for now. in the future specify the
|
||||||
|
//query model from the DataGetter's RDF configuration.
|
||||||
|
return vreq.getJenaOntModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model getDisplayModel(VitroRequest vreq, ServletContext context) {
|
||||||
|
return vreq.getDisplayModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuerySolutionMap createBindings(Map<String, String[]>parameterMap) {
|
||||||
|
|
||||||
|
QuerySolutionMap initBindings = new QuerySolutionMap();
|
||||||
|
initBindings.add("pageUri", ResourceFactory.createResource(pageUri));
|
||||||
|
|
||||||
|
//could have bindings from HTTP parameters
|
||||||
|
for( String var : parameterMap.keySet() ) {
|
||||||
|
|
||||||
|
String[] values = parameterMap.get(var);
|
||||||
|
if( values != null && values.length == 1 ){
|
||||||
|
//what do do when we don't want a Resource?
|
||||||
|
initBindings.add(var, ResourceFactory.createResource(values[0]) );
|
||||||
|
}else if( values.length > 1){
|
||||||
|
log.error("more than 1 http parameter for " + var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return initBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String queryPropertyURI = "<" + DisplayVocabulary.QUERY + ">";
|
||||||
|
private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">";
|
||||||
|
private static final String queryModelPropertyURI= "<" + DisplayVocabulary.QUERY_MODEL+ ">";
|
||||||
|
|
||||||
|
private static final String pageQuery =
|
||||||
|
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" +
|
||||||
|
"SELECT ?query ?saveToVar ?model WHERE { \n" +
|
||||||
|
" ?pageUri "+queryPropertyURI+" ?query . \n" +
|
||||||
|
" OPTIONAL{ ?pageUri "+saveToVarPropertyURI+" ?saveToVar } \n " +
|
||||||
|
" OPTIONAL{ ?pageUri "+queryModelPropertyURI+" ?queryModel } \n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -41,6 +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.pageDataGetter.PageDataGetterUtils;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
|
@ -57,7 +59,7 @@ 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
|
||||||
DataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
PageDataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -41,6 +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.pageDataGetter.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
|
||||||
|
@ -57,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
|
||||||
DataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
PageDataGetterUtils.getClassGroupForDataGetter(context, pageData, templateData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -40,6 +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.pageDataGetter.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
|
|
@ -73,7 +73,12 @@ public class ClassGroupPageData implements PageDataGetter{
|
||||||
log.debug("Class " + v.getName() + " - " + v.getURI() + " has " + v.getEntityCount() + " entities");
|
log.debug("Class " + v.getName() + " - " + v.getURI() + " has " + v.getEntityCount() + " entities");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.put("vClassGroup", group); //may put null
|
data.put("vClassGroup", group); //may put null
|
||||||
|
|
||||||
|
//This page level data getters tries to set its own template,
|
||||||
|
// not all of the data getters need to do this.
|
||||||
|
data.put("bodyTemplate", "page-classgroup.ftl");
|
||||||
|
|
||||||
//Also add data service url
|
//Also add data service url
|
||||||
//Hardcoding for now, need a more dynamic way of doing this
|
//Hardcoding for now, need a more dynamic way of doing this
|
||||||
data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl());
|
data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl());
|
||||||
|
@ -121,7 +126,7 @@ public class ClassGroupPageData implements PageDataGetter{
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType(){
|
public String getType(){
|
||||||
return DataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
return PageDataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get data servuice
|
//Get data servuice
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
||||||
for(VClass r: restrictClasses) {
|
for(VClass r: restrictClasses) {
|
||||||
classUris.add(r.getURI());
|
classUris.add(r.getURI());
|
||||||
}
|
}
|
||||||
long count = DataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
|
long count = PageDataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
|
||||||
return new Long(count).intValue();
|
return new Long(count).intValue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType(){
|
public String getType(){
|
||||||
return DataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
return PageDataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get data servuice
|
//Get data servuice
|
||||||
|
@ -287,7 +287,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
||||||
* For processig of JSONObject
|
* For processig of JSONObject
|
||||||
*/
|
*/
|
||||||
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
|
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
|
||||||
JSONObject rObj = DataGetterUtils.processVclassResultsJSON(map, vreq, true);
|
JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, true);
|
||||||
return rObj;
|
return rObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -31,13 +32,14 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
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;
|
||||||
|
|
||||||
public class DataGetterUtils {
|
public class PageDataGetterUtils {
|
||||||
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
||||||
private static final Log log = LogFactory.getLog(DataGetterUtils.class);
|
private static final Log log = LogFactory.getLog(PageDataGetterUtils.class);
|
||||||
|
|
||||||
public static Map<String,Object> getDataForPage(String pageUri, VitroRequest vreq, ServletContext context) {
|
public static Map<String,Object> getDataForPage(String pageUri, VitroRequest vreq, ServletContext context) {
|
||||||
//Based on page type get the appropriate data getter
|
//Based on page type get the appropriate data getter
|
||||||
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
Map<String, Object> page = vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
||||||
|
|
||||||
Map<String,Object> data = new HashMap<String,Object>();
|
Map<String,Object> data = new HashMap<String,Object>();
|
||||||
List<PageDataGetter> dataGetters = getDataGetterObjects(vreq, pageUri);
|
List<PageDataGetter> dataGetters = getDataGetterObjects(vreq, pageUri);
|
||||||
for(PageDataGetter getter: dataGetters) {
|
for(PageDataGetter getter: dataGetters) {
|
||||||
|
@ -60,7 +62,8 @@ public class DataGetterUtils {
|
||||||
*/
|
*/
|
||||||
public static JSONObject covertDataToJSONForPage(String pageUri, Map<String, Object> data, VitroRequest vreq, ServletContext context) {
|
public static JSONObject covertDataToJSONForPage(String pageUri, Map<String, Object> data, VitroRequest vreq, ServletContext context) {
|
||||||
//Based on page type get the appropriate data getter
|
//Based on page type get the appropriate data getter
|
||||||
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
Map<String, Object> page = vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
||||||
|
|
||||||
//Get types associated with page
|
//Get types associated with page
|
||||||
JSONObject rObj = null;
|
JSONObject rObj = null;
|
||||||
List<String> types = (List<String>)page.get("types");
|
List<String> types = (List<String>)page.get("types");
|
||||||
|
@ -86,13 +89,6 @@ public class DataGetterUtils {
|
||||||
}
|
}
|
||||||
return rObj;
|
return rObj;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Returns map with all page attributes from display model
|
|
||||||
*/
|
|
||||||
public static Map<String, Object> getMapForPage(VitroRequest vreq, String pageUri) {
|
|
||||||
//do a query to the display model for attributes of this page.
|
|
||||||
return vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String,Object> getAdditionalData(
|
public static Map<String,Object> getAdditionalData(
|
||||||
String pageUri, String dataGetterName, Map<String, Object> page, VitroRequest vreq, PageDataGetter getter, ServletContext context) {
|
String pageUri, String dataGetterName, Map<String, Object> page, VitroRequest vreq, PageDataGetter getter, ServletContext context) {
|
||||||
|
@ -124,12 +120,11 @@ public class DataGetterUtils {
|
||||||
|
|
||||||
for(String dgClassName: dataGetterClassNames) {
|
for(String dgClassName: dataGetterClassNames) {
|
||||||
String className = getClassNameFromUri(dgClassName);
|
String className = getClassNameFromUri(dgClassName);
|
||||||
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
Object obj = Class.forName(className).newInstance();
|
||||||
if(pg != null) {
|
if(obj != null && obj instanceof PageDataGetter) {
|
||||||
|
PageDataGetter pg = (PageDataGetter) obj;
|
||||||
dataGetterObjects.add(pg);
|
dataGetterObjects.add(pg);
|
||||||
} else {
|
}
|
||||||
log.error("Data getter does not exist for " + className);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex) {
|
catch(Exception ex) {
|
||||||
|
@ -140,7 +135,7 @@ public class DataGetterUtils {
|
||||||
|
|
||||||
//Class uris returned include "java:" and to instantiate object need to remove java: portion
|
//Class uris returned include "java:" and to instantiate object need to remove java: portion
|
||||||
public static String getClassNameFromUri(String dataGetterClassUri) {
|
public static String getClassNameFromUri(String dataGetterClassUri) {
|
||||||
if(dataGetterClassUri.contains("java:")) {
|
if( !StringUtils.isEmpty(dataGetterClassUri) && dataGetterClassUri.contains("java:")) {
|
||||||
String[] splitArray = dataGetterClassUri.split("java:");
|
String[] splitArray = dataGetterClassUri.split("java:");
|
||||||
if(splitArray.length > 1) {
|
if(splitArray.length > 1) {
|
||||||
return splitArray[1];
|
return splitArray[1];
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.jsptags;
|
package edu.cornell.mannlib.vitro.webapp.web.jsptags;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
@ -444,7 +445,7 @@ public class InputElementFormattingTag extends TagSupport {
|
||||||
// individuals from classes that should be hidden from list views
|
// individuals from classes that should be hidden from list views
|
||||||
OntModel displayOntModel =
|
OntModel displayOntModel =
|
||||||
(OntModel) pageContext.getServletContext()
|
(OntModel) pageContext.getServletContext()
|
||||||
.getAttribute("displayOntModel");
|
.getAttribute(DISPLAY_ONT_MODEL);
|
||||||
if (displayOntModel != null) {
|
if (displayOntModel != null) {
|
||||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||||
|
|
|
@ -215,7 +215,7 @@
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>MenuManagementController</servlet-name>
|
<servlet-name>MenuManagementController</servlet-name>
|
||||||
<url-pattern>/editDisplayModel</url-pattern>
|
<url-pattern>/menuManagementController</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
@ -224,7 +224,7 @@
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>MenuManagementEdit</servlet-name>
|
<servlet-name>MenuManagementEdit</servlet-name>
|
||||||
<url-pattern>/processEditDisplayModel</url-pattern>
|
<url-pattern>/menuManagementEdit</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>Display Admin and configuration</h2>
|
||||||
|
|
||||||
|
<#if errorMessage??>
|
||||||
|
<div id="errorAlert">
|
||||||
|
<img src="../images/iconAlert.png" alert="Error alert icon" height="31" width="32">
|
||||||
|
<p>${errorMessage}</p>
|
||||||
|
</div>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if message??>
|
||||||
|
<p>${message}</p>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li> Some link to a display config and amdin page </li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
<#assign hasElement = propertyGroups.pullProperty("${namespaces.display}hasElement")!>
|
<#assign hasElement = propertyGroups.pullProperty("${namespaces.display}hasElement")!>
|
||||||
|
|
||||||
|
<#assign addNewMenuItemUrl = "${urls.base}/menuManagementController?cmd=add" >
|
||||||
|
|
||||||
<#if hasElement?has_content>
|
<#if hasElement?has_content>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var menuItemData = [];
|
var menuItemData = [];
|
||||||
|
@ -22,9 +24,8 @@
|
||||||
|
|
||||||
<#-- Link to add a new menu item -->
|
<#-- Link to add a new menu item -->
|
||||||
<#if editable>
|
<#if editable>
|
||||||
<#assign addUrl = hasElement.addUrl>
|
<#if addNewMenuItemUrl?has_content>
|
||||||
<#if addUrl?has_content>
|
<p><a class="add-hasElement green button" href="${addNewMenuItemUrl}" title="Add new menu item">Add menu item</a></p>
|
||||||
<p><a class="add-hasElement green button" href="${addUrl}" title="Add new menu item">Add menu item</a></p>
|
|
||||||
|
|
||||||
<p class="note">Refresh page after reordering menu items</p>
|
<p class="note">Refresh page after reordering menu items</p>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<div>
|
||||||
|
<p>This page is not yet configured.</p>
|
||||||
|
|
||||||
|
<p>Implement a <a href="${urls.base}/display?uri=${page.pageUri?url}&switchToDisplayModel=1">link</a> to configure this page if the user has permission.</p>
|
||||||
|
|
||||||
|
</div>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#include "menupage-checkForData.ftl">
|
||||||
|
|
||||||
|
<#if !noData>
|
||||||
|
<section id="menupage-intro" role="region">
|
||||||
|
<h2>${page.title}</h2>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<#include "menupage-browse.ftl">
|
||||||
|
|
||||||
|
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/menupage/menupage.css" />')}
|
||||||
|
|
||||||
|
<#include "menupage-scripts.ftl">
|
||||||
|
<#else>
|
||||||
|
${noDataNotification}
|
||||||
|
</#if>
|
|
@ -6,7 +6,7 @@
|
||||||
is also used to generate the property statement during a deletion.
|
is also used to generate the property statement during a deletion.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
${statement.linkText}
|
${statement.linkText} (Add URLs to Menu Controllers here?)
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
menuItemData.push({
|
menuItemData.push({
|
||||||
|
|
Loading…
Add table
Reference in a new issue