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.SelectListGenerator;
|
||||
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;
|
||||
|
||||
|
@ -284,7 +284,7 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
|
||||
// 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{
|
||||
JSONObject rObj = DataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
|
||||
JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
|
||||
return rObj;
|
||||
}
|
||||
|
||||
|
@ -534,11 +534,11 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
String pageUri = vreq.getParameter("pageUri");
|
||||
if(pageUri != null && !pageUri.isEmpty()) {
|
||||
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
|
||||
if(data != null) {
|
||||
//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;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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.query.Dataset;
|
||||
|
@ -15,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
||||
|
||||
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
|
||||
public static final String SPECIAL_WRITE_MODEL = "specialWriteModel";
|
||||
|
@ -139,6 +146,35 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
|||
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(){
|
||||
//return (ApplicationBean) getAttribute("appBean");
|
||||
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.dao.DisplayVocabulary;
|
||||
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
|
||||
|
|
|
@ -215,7 +215,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
// Subclasses will override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
||||
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.dao.DisplayVocabulary;
|
||||
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 {
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
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) {
|
||||
if( dataGetter != null ){
|
||||
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.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.DataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.MenuManagementDataUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.SelectDataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||
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
|
||||
|
@ -35,7 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.SelectDataGetterUti
|
|||
*/
|
||||
public class MenuManagementController extends FreemarkerHttpServlet {
|
||||
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 DELETE_FORM = "menuManagement-remove.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
|
||||
data.put("isClassGroupPage", false);
|
||||
data.put("includeAllClasses", false);
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("selectedTemplateType", "default");
|
||||
//
|
||||
this.getMenuItemData(vreq, menuItem, data);
|
||||
|
@ -134,7 +134,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
|||
//not a page already assigned a class group
|
||||
data.put("isClassGroupPage", false);
|
||||
data.put("includeAllClasses", false);
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("selectedTemplateType", "default");
|
||||
//defaults to regular class group page
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class MenuManagementController extends FreemarkerHttpServlet {
|
|||
data.put("menuItem", menuItem);
|
||||
data.put("menuAction", "Edit");
|
||||
//Get All class groups
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
|
||||
data.put("classGroups", PageDataGetterUtils.getClassGroups(getServletContext()));
|
||||
//Get data for menu item and associated page
|
||||
this.getMenuItemData(vreq, menuItem, 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) {
|
||||
//Data Getter type is now a class name
|
||||
String className = DataGetterUtils.getClassNameFromUri(dataGetterType);
|
||||
String className = PageDataGetterUtils.getClassNameFromUri(dataGetterType);
|
||||
try{
|
||||
String pageURI = page.getURI();
|
||||
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
||||
Map<String, Object> pageInfo = DataGetterUtils.getMapForPage( vreq, pageURI );
|
||||
|
||||
Map<String, Object> pageData = DataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext());
|
||||
Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
|
||||
|
||||
Map<String, Object> pageData = PageDataGetterUtils.getAdditionalData(pageURI, dataGetterType, pageInfo, vreq, pg, getServletContext());
|
||||
SelectDataGetterUtils.processAndRetrieveData(vreq, getServletContext(), pageData, className, templateData);
|
||||
} catch(Exception 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.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -16,12 +19,16 @@ 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.ResponseValues;
|
||||
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.
|
||||
*
|
||||
* This controller passes these variables to the template:
|
||||
* 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.
|
||||
*/
|
||||
|
@ -29,57 +36,72 @@ public class PageController extends FreemarkerHttpServlet{
|
|||
private static final Log log = LogFactory.getLog(PageController.class);
|
||||
|
||||
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";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
try {
|
||||
// get URL without hostname or servlet context
|
||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
||||
|
||||
Map<String,Object> mapForTemplate = new HashMap<String,Object>();
|
||||
String pageUri = "";
|
||||
Map<String,Object>page;
|
||||
try {
|
||||
pageUri = getPageUri( vreq , url );
|
||||
page = DataGetterUtils.getMapForPage( vreq, pageUri );
|
||||
|
||||
//figure out what page we are trying to get
|
||||
String pageUri = getPageUri( vreq );
|
||||
if( StringUtils.isEmpty( pageUri ) )
|
||||
return doNoPageSpecified(vreq);
|
||||
else
|
||||
mapForTemplate.put("pageUri", pageUri);
|
||||
|
||||
//try to get the page RDF from the model
|
||||
try{
|
||||
page = vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
||||
mapForTemplate.put( "page", page);
|
||||
if( page.containsKey("title") ){
|
||||
mapForTemplate.put("title", page.get("title"));
|
||||
}
|
||||
|
||||
} catch (Throwable th) {
|
||||
}catch( Throwable th){
|
||||
return doNotFound(vreq);
|
||||
}
|
||||
|
||||
try{
|
||||
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="));
|
||||
}
|
||||
executePageDataGetters( pageUri, vreq, getServletContext(), mapForTemplate );
|
||||
executeDataGetters( pageUri, vreq, getServletContext(), mapForTemplate);
|
||||
|
||||
ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate);
|
||||
return rv;
|
||||
} catch (Throwable e) {
|
||||
log.error(e, e);
|
||||
return new ExceptionResponseValues(e);
|
||||
}
|
||||
|
||||
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) {
|
||||
//first try to get the body template from the display model RDF
|
||||
if( mapForTemplate.containsKey("page") ){
|
||||
Map page = (Map) mapForTemplate.get("page");
|
||||
if( page != null && page.containsKey("bodyTemplate"))
|
||||
if( page != null && page.containsKey("bodyTemplate")){
|
||||
return (String) page.get("bodyTemplate");
|
||||
else
|
||||
return DEFAULT_BODY_TEMPLATE;
|
||||
}else
|
||||
}
|
||||
}
|
||||
//next, try to get body template from the data getter values
|
||||
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>();
|
||||
body.put("title","Page could not be created");
|
||||
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) {
|
||||
|
@ -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.
|
||||
* @throws Exception
|
||||
*/
|
||||
private String getPageUri(VitroRequest vreq, String url) throws Exception {
|
||||
//check if there is a page URI in the request. This would have
|
||||
//been added by a servlet Filter.
|
||||
private String getPageUri(VitroRequest vreq) throws Exception {
|
||||
// get URL without hostname or servlet context
|
||||
//bdc34: why are we getting this?
|
||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||
|
||||
// Check if there is a page URI in the request.
|
||||
// This would have been added by a servlet Filter.
|
||||
String pageURI = (String) vreq.getAttribute("pageURI");
|
||||
if( pageURI != null && ! pageURI.isEmpty() )
|
||||
return pageURI;
|
||||
else
|
||||
throw new Exception("no page found for " + vreq.getRequestURI() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
|||
|
||||
static protected Query pageQuery;
|
||||
static protected Query pageTypeQuery;
|
||||
static protected Query pageDataGettersQuery;
|
||||
static protected Query pageDataGetterTypeQuery;
|
||||
static protected Query dataGetterURIsQuery;
|
||||
static protected Query pageMappingsQuery;
|
||||
static protected Query homePageUriQuery;
|
||||
static protected Query classGroupPageQuery;
|
||||
|
@ -70,13 +71,21 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
|||
" ?pageUri rdf:type ?type .\n"+
|
||||
"} \n" ;
|
||||
|
||||
//Get data getters
|
||||
static final protected String pageDataGettersQueryString =
|
||||
//Get data getter types
|
||||
static final protected String pageDataGetterTypesQueryString =
|
||||
prefixes + "\n" +
|
||||
"SELECT ?dataGetter WHERE {\n" +
|
||||
"SELECT ?dataGetterType WHERE {\n" +
|
||||
" ?pageUri display:hasDataGetter ?dg .\n"+
|
||||
" ?dg rdf:type ?dataGetter . \n" +
|
||||
" ?dg rdf:type ?dataGetterType . \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 =
|
||||
prefixes + "\n" +
|
||||
"SELECT ?pageUri ?urlMapping WHERE {\n" +
|
||||
|
@ -155,10 +164,16 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
|||
log.error(pageTypeQueryString);
|
||||
}
|
||||
try{
|
||||
pageDataGettersQuery = QueryFactory.create(pageDataGettersQueryString);
|
||||
pageDataGetterTypeQuery = QueryFactory.create(pageDataGetterTypesQueryString);
|
||||
}catch(Throwable th){
|
||||
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{
|
||||
pageMappingsQuery=QueryFactory.create(pageMappingsQueryString);
|
||||
|
@ -279,30 +294,36 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
|||
log.debug("multiple results found for " + pageUri + " using only the first.");
|
||||
Map<String,Object> pageData = list.get(0);
|
||||
|
||||
//now get the rdf:types for the page
|
||||
//Changing to get the data getters for the page (already know that it's a page type)
|
||||
List<String> dataGetters = new ArrayList<String>();
|
||||
//now get the rdf:types for the data getters for the page
|
||||
List<String> dataGetterTypes = new ArrayList<String>();
|
||||
displayModel.enterCriticalSection(false);
|
||||
try{
|
||||
QueryExecution qexec = QueryExecutionFactory.create(pageDataGettersQuery, displayModel, initialBindings);
|
||||
QueryExecution qexec = QueryExecutionFactory.create(pageDataGetterTypeQuery, displayModel, initialBindings);
|
||||
try{
|
||||
ResultSet rs = qexec.execSelect();
|
||||
while(rs.hasNext()){
|
||||
QuerySolution soln = rs.next();
|
||||
dataGetters.add( nodeToString( soln.get("dataGetter" ) ));
|
||||
}
|
||||
}finally{
|
||||
qexec.close();
|
||||
}
|
||||
}finally{
|
||||
displayModel.leaveCriticalSection();
|
||||
dataGetterTypes.add( nodeToString( soln.get("dataGetterType" ) ));
|
||||
}
|
||||
}finally{ qexec.close(); }
|
||||
}finally{ displayModel.leaveCriticalSection(); }
|
||||
pageData.put("dataGetterTypes", dataGetterTypes);
|
||||
|
||||
if( list == null )
|
||||
log.error("could not get data getters for page " + pageUri);
|
||||
else
|
||||
pageData.put("dataGetters", dataGetters);
|
||||
//now get URIs of DataGetters for page.
|
||||
List<String> dataGetterURIs = new ArrayList<String>();
|
||||
displayModel.enterCriticalSection(false);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,12 @@ public class EditConfigurationUtils {
|
|||
//DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
DataProperty dataProp = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||
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
|
||||
|
|
|
@ -56,6 +56,10 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
|||
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||
//This used to get the model from the servlet context
|
||||
// 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();
|
||||
|
||||
if( editConfig.getSubjectUri() == null)
|
||||
|
|
|
@ -44,12 +44,14 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
|||
String predicateUri = vreq.getParameter("predicateUri");
|
||||
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||
|
||||
dataproperty = vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||
if( dataproperty == null) {
|
||||
// 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.
|
||||
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
||||
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;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -460,7 +462,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
|||
//TODO: Check how model is retrieved
|
||||
OntModel displayOntModel =
|
||||
(OntModel) session.getServletContext()
|
||||
.getAttribute("displayOntModel");
|
||||
.getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (displayOntModel != null) {
|
||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -463,7 +465,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
|||
// individuals from classes that should be hidden from list views
|
||||
OntModel displayOntModel =
|
||||
(OntModel) session.getServletContext()
|
||||
.getAttribute("displayOntModel");
|
||||
.getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (displayOntModel != null) {
|
||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||
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.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
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.web.templatemodels.edit.EditConfigurationTemplateModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.MultiValueEditSubmissionTemplateModel;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -130,15 +133,19 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
|||
|
||||
private boolean isMenuMode(VitroRequest vreq) {
|
||||
//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) {
|
||||
String queryString = vreq.getQueryString();
|
||||
String redirectPage = vreq.getContextPath() + "/editDisplayModel?" + queryString;
|
||||
return new DirectRedirectResponseValues(redirectPage, HttpServletResponse.SC_SEE_OTHER);
|
||||
|
||||
throw new RuntimeException("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 /editDisplayModel");
|
||||
}
|
||||
|
||||
private MultiValueEditSubmission getMultiValueSubmission(VitroRequest vreq, EditConfigurationVTwo 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
|
||||
//TODO: Check if additional scenarios should be checked here
|
||||
/**
|
||||
* Determine the java class name to use for the EditConfigurationGenerator.
|
||||
*
|
||||
* 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) {
|
||||
String editConfGeneratorName = null;
|
||||
|
||||
//Handle deletion before any of the other cases
|
||||
if(isDeleteForm(vreq)) {
|
||||
return DEFAULT_DELETE_FORM;
|
||||
}
|
||||
|
||||
//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);
|
||||
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.
|
||||
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;
|
||||
}
|
||||
|
||||
if( isVitroLabel(predicateUri) ) { //in case of data property
|
||||
return RDFS_LABEL_FORM;
|
||||
}
|
||||
|
||||
//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;
|
||||
// *** default to the object property form when there is nothing
|
||||
}else{
|
||||
editConfGeneratorName = DEFAULT_OBJ_FORM;
|
||||
}
|
||||
|
||||
if( editConfGeneratorName == null )
|
||||
log.error("problem: editConfGeneratorName is null but " +
|
||||
"processEditConfGeneratorName() should never return null.");
|
||||
|
||||
log.debug("generator name is " + editConfGeneratorName);
|
||||
return editConfGeneratorName;
|
||||
}
|
||||
|
||||
private String getCustomForm(String predicateUri, WebappDaoFactory wdf) {
|
||||
Property prop = getPropertyByUri(predicateUri, wdf);
|
||||
return prop.getCustomEntryForm();
|
||||
}
|
||||
|
||||
private Property getPropertyByUri(String predicateUri, WebappDaoFactory wdf) {
|
||||
private Property getProperty(String predicateUri, VitroRequest vreq) {
|
||||
Property p = null;
|
||||
p = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
try{
|
||||
p = vreq.getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
if(p == null) {
|
||||
p = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||
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;
|
||||
}
|
||||
|
@ -229,16 +250,8 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
|||
return predicateUri.equals(VitroVocabulary.LABEL);
|
||||
}
|
||||
|
||||
private boolean isDataProperty(Property prop, WebappDaoFactory wdf) {
|
||||
if( prop != null && prop instanceof DataProperty ){
|
||||
return true;
|
||||
}else{
|
||||
DataProperty dataProp = wdf.getDataPropertyDao().getDataPropertyByURI(prop.getURI());
|
||||
if( dataProp != null )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private boolean isDataProperty( Property prop ) {
|
||||
return ( prop != null && prop instanceof DataProperty );
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,12 +358,9 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
private EditConfigurationVTwo makeEditConfigurationVTwo(
|
||||
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.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.USE_DISPLAY_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 (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);
|
||||
setSpecialWriteModel(vreq, mainOntModel);
|
||||
return createNewWebappDaoFactory(wadf, mainOntModel, tboxOntModel, null);
|
||||
|
@ -294,6 +295,9 @@ public class VitroRequestPrep implements Filter {
|
|||
}
|
||||
|
||||
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) {
|
||||
vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -94,7 +96,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase
|
|||
unionOms.setUserAccountsModel(userAccountsModel);
|
||||
|
||||
OntModel displayModel = ontModelFromContextAttribute(
|
||||
ctx,"displayOntModel");
|
||||
ctx,DISPLAY_ONT_MODEL);
|
||||
baseOms.setDisplayModel(displayModel);
|
||||
inferenceOms.setDisplayModel(displayModel);
|
||||
unionOms.setDisplayModel(displayModel);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
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.FileOutputStream;
|
||||
|
||||
|
@ -78,7 +80,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
|||
OntModel displayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||
displayModel.add(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
|
||||
initializeDisplayLoadedAtStartup(ctx, displayModel);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
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.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -130,7 +132,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
}
|
||||
|
||||
private void doMigrateDisplayModel(ServletContext ctx) {
|
||||
Object o = ctx.getAttribute("displayOntModel");
|
||||
Object o = ctx.getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (!(o instanceof OntModel)) {
|
||||
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$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
|
@ -1,6 +1,6 @@
|
|||
/* $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.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.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
//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$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* $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.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.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
populateRestrictedClasses(pageData, templateData);
|
||||
//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$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.menuManagement;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
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.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter;
|
||||
|
||||
/*
|
||||
* This class includes methods that help in selecting a data getter based on
|
|
@ -74,6 +74,11 @@ public class ClassGroupPageData implements PageDataGetter{
|
|||
}
|
||||
}
|
||||
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
|
||||
//Hardcoding for now, need a more dynamic way of doing this
|
||||
data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl());
|
||||
|
@ -121,7 +126,7 @@ public class ClassGroupPageData implements PageDataGetter{
|
|||
}
|
||||
|
||||
public String getType(){
|
||||
return DataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
||||
return PageDataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
||||
}
|
||||
|
||||
//Get data servuice
|
||||
|
|
|
@ -147,7 +147,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
|||
for(VClass r: restrictClasses) {
|
||||
classUris.add(r.getURI());
|
||||
}
|
||||
long count = DataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
|
||||
long count = PageDataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
|
||||
return new Long(count).intValue();
|
||||
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
|||
}
|
||||
|
||||
public String getType(){
|
||||
return DataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
||||
return PageDataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
||||
}
|
||||
|
||||
//Get data servuice
|
||||
|
@ -287,7 +287,7 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
|
|||
* For processig of JSONObject
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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.jena.VClassGroupCache;
|
||||
|
||||
public class DataGetterUtils {
|
||||
public class PageDataGetterUtils {
|
||||
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) {
|
||||
//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>();
|
||||
List<PageDataGetter> dataGetters = getDataGetterObjects(vreq, pageUri);
|
||||
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) {
|
||||
//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
|
||||
JSONObject rObj = null;
|
||||
List<String> types = (List<String>)page.get("types");
|
||||
|
@ -86,13 +89,6 @@ public class DataGetterUtils {
|
|||
}
|
||||
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(
|
||||
String pageUri, String dataGetterName, Map<String, Object> page, VitroRequest vreq, PageDataGetter getter, ServletContext context) {
|
||||
|
@ -124,11 +120,10 @@ public class DataGetterUtils {
|
|||
|
||||
for(String dgClassName: dataGetterClassNames) {
|
||||
String className = getClassNameFromUri(dgClassName);
|
||||
PageDataGetter pg = (PageDataGetter) Class.forName(className).newInstance();
|
||||
if(pg != null) {
|
||||
Object obj = Class.forName(className).newInstance();
|
||||
if(obj != null && obj instanceof PageDataGetter) {
|
||||
PageDataGetter pg = (PageDataGetter) obj;
|
||||
dataGetterObjects.add(pg);
|
||||
} else {
|
||||
log.error("Data getter does not exist for " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +135,7 @@ public class DataGetterUtils {
|
|||
|
||||
//Class uris returned include "java:" and to instantiate object need to remove java: portion
|
||||
public static String getClassNameFromUri(String dataGetterClassUri) {
|
||||
if(dataGetterClassUri.contains("java:")) {
|
||||
if( !StringUtils.isEmpty(dataGetterClassUri) && dataGetterClassUri.contains("java:")) {
|
||||
String[] splitArray = dataGetterClassUri.split("java:");
|
||||
if(splitArray.length > 1) {
|
||||
return splitArray[1];
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
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.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
|
@ -444,7 +445,7 @@ public class InputElementFormattingTag extends TagSupport {
|
|||
// individuals from classes that should be hidden from list views
|
||||
OntModel displayOntModel =
|
||||
(OntModel) pageContext.getServletContext()
|
||||
.getAttribute("displayOntModel");
|
||||
.getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (displayOntModel != null) {
|
||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||
|
|
|
@ -215,7 +215,7 @@
|
|||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>MenuManagementController</servlet-name>
|
||||
<url-pattern>/editDisplayModel</url-pattern>
|
||||
<url-pattern>/menuManagementController</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
|
@ -224,7 +224,7 @@
|
|||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>MenuManagementEdit</servlet-name>
|
||||
<url-pattern>/processEditDisplayModel</url-pattern>
|
||||
<url-pattern>/menuManagementEdit</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<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 addNewMenuItemUrl = "${urls.base}/menuManagementController?cmd=add" >
|
||||
|
||||
<#if hasElement?has_content>
|
||||
<script type="text/javascript">
|
||||
var menuItemData = [];
|
||||
|
@ -22,9 +24,8 @@
|
|||
|
||||
<#-- Link to add a new menu item -->
|
||||
<#if editable>
|
||||
<#assign addUrl = hasElement.addUrl>
|
||||
<#if addUrl?has_content>
|
||||
<p><a class="add-hasElement green button" href="${addUrl}" title="Add new menu item">Add menu item</a></p>
|
||||
<#if addNewMenuItemUrl?has_content>
|
||||
<p><a class="add-hasElement green button" href="${addNewMenuItemUrl}" title="Add new menu item">Add menu item</a></p>
|
||||
|
||||
<p class="note">Refresh page after reordering menu items</p>
|
||||
</#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.
|
||||
-->
|
||||
|
||||
${statement.linkText}
|
||||
${statement.linkText} (Add URLs to Menu Controllers here?)
|
||||
|
||||
<script type="text/javascript">
|
||||
menuItemData.push({
|
||||
|
|
Loading…
Add table
Reference in a new issue