updates for code cleanup, also fixed error in internalClassDataGetter introduced after previous update removing JSON Object as constructor for ProcessInternalClassDataGetter. Added space to sparql query for other ProcessDataGetter classes - although code was working without that.

This commit is contained in:
hjkhjk54 2012-06-26 17:48:50 +00:00
parent 8bd0990e85
commit 2a3181536c
10 changed files with 6 additions and 908 deletions

View file

@ -1,303 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
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.menuManagement.MenuManagementDataUtils;
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.SelectDataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
/*
* Custom controller for menu management. This will be replaced later once N3 Editing
* has been successfully refactored and integrated with menu management.
*/
public class MenuManagementController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(MenuManagementController.class);
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";
protected final static String CMD_PARAM = "cmd";
protected final static String EDIT_PARAM_VALUE = "edit";
protected final static String DELETE_PARAM_VALUE = "delete";
protected final static String ADD_PARAM_VALUE = "add";
//since forwarding from edit Request dispatch for now
protected final static String ITEM_PARAM = "objectUri";
public final static Actions REQUIRED_ACTIONS = SimplePermission.MANAGE_MENUS.ACTIONS;
@Override
protected Actions requiredActions(VitroRequest vreq) {
return REQUIRED_ACTIONS;
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
//Parameters should include the menu item being edited/added/removed/reordered
Map<String, Object> data = new HashMap<String,Object>();
this.initializeData(data, vreq);
//if no menu item passed, return empty data
//TODO: Check if exception needs to be thrown
String cmd = getCommand(vreq);
String template = EDIT_FORM;
if(cmd.equals(ADD_PARAM_VALUE)) {
processAddMenuItem(vreq, data);
} else if(cmd.equals(EDIT_PARAM_VALUE)) {
processEditMenuItem(vreq, data);
} else if(cmd.equals(DELETE_PARAM_VALUE)) {
processDeleteMenuItem(vreq, data);
template = DELETE_FORM;
} else {
//Throw some kind of error or do nothing
}
return new TemplateResponseValues(template, data);
}
//Certain parameters are always passed
private void initializeData(Map<String, Object> data, VitroRequest vreq) {
data.put("formUrls", vreq.getContextPath() + SUBMIT_FORM);
data.put("cancelUrl", vreq.getContextPath() + CANCEL_FORM);
MenuManagementDataUtils.includeRequiredSystemData(getServletContext(), data);
}
//Based on parameters, ascertain command
private String getCommand(VitroRequest vreq) {
String command = vreq.getParameter(CMD_PARAM);
if(command == null || command.isEmpty()) {
//Check if objectUri null, if exists then edit otherewise add
String objectUri = vreq.getParameter("objectUri");
if(objectUri == null || objectUri.isEmpty()) {
command = ADD_PARAM_VALUE;
} else {
command = EDIT_PARAM_VALUE;
}
}
return command;
}
private void processDeleteMenuItem(VitroRequest vreq , Map<String, Object> data) {
String menuItem = getMenuItem(vreq);
data.put("menuItem", menuItem);
data.put("menuAction", "Remove");
data.put("title", "Remove Menu Item");
//Generate empty values for fields
data.put("prettyUrl", "");
data.put("associatedPage", "");
data.put("associatedPageURI", "");
data.put("classGroup", new ArrayList<String>());
//not a page already assigned a class group
data.put("isClassGroupPage", false);
data.put("includeAllClasses", false);
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
data.put("selectedTemplateType", "default");
//
this.getMenuItemData(vreq, menuItem, data);
this.getPageData(vreq, data);
}
private void processAddMenuItem(VitroRequest vreq, Map<String, Object> data) {
data.put("title", "Add Menu Item");
data.put("menuAction", "Add");
//Generate empty values for fields
data.put("menuItem", "");
data.put("menuName", "");
data.put("prettyUrl", "");
data.put("associatedPage", "");
data.put("associatedPageURI", "");
data.put("classGroup", new ArrayList<String>());
//not a page already assigned a class group
data.put("isClassGroupPage", false);
data.put("includeAllClasses", false);
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
data.put("selectedTemplateType", "default");
//defaults to regular class group page
}
private void processEditMenuItem(VitroRequest vreq, Map<String, Object> data) {
if(!hasMenuItem(vreq)) {
return;
}
data.put("title", "Edit Menu Item");
//Get parameter for menu item
String menuItem = getMenuItem(vreq);
data.put("menuItem", menuItem);
data.put("menuAction", "Edit");
//Get All class groups
data.put("classGroups", DataGetterUtils.getClassGroups(getServletContext()));
//Get data for menu item and associated page
this.getMenuItemData(vreq, menuItem, data);
this.getPageData(vreq, data);
}
private String getMenuItem(VitroRequest vreq) {
return vreq.getParameter(ITEM_PARAM);
}
private boolean hasMenuItem(VitroRequest vreq) {
return (getMenuItem(vreq) != null && !getMenuItem(vreq).isEmpty());
}
/*
* Sparql queries and data
*/
private void getMenuItemData(VitroRequest vreq, String menuItem, Map<String, Object> data) {
OntModel writeModel = vreq.getWriteModel();
Individual item = writeModel.getIndividual(menuItem);
if(item != null) {
StmtIterator it = item.listProperties(DisplayVocabulary.LINK_TEXT);
if(it.hasNext()) {
String linkText = it.nextStatement().getLiteral().getString();
log.debug("Link text retrieved is " + linkText);
//stored as menu name
data.put("menuName", linkText);
}
StmtIterator pageIt = item.listProperties(DisplayVocabulary.TO_PAGE);
if(pageIt.hasNext()) {
Resource pageResource = pageIt.nextStatement().getResource();
String pageUri = pageResource.getURI();
log.debug("Page URI is " + pageUri);
data.put("page", pageUri);
}
}
}
//pretty-url, also type
private void getPageData(VitroRequest vreq, Map<String, Object> data) {
String pageUri = (String) data.get("page");
OntModel writeModel = vreq.getWriteModel();
Individual page = writeModel.getIndividual(pageUri);
if(page != null) {
StmtIterator urlMappingIt = page.listProperties(DisplayVocabulary.URL_MAPPING);
if(urlMappingIt.hasNext()) {
String urlMapping = urlMappingIt.nextStatement().getLiteral().getString();
log.debug("URL Mapping retrieved is " + urlMapping);
data.put("prettyUrl", urlMapping);
}
//If home page, then specify?
this.checkHomePage(writeModel, page, data);
//Check if custom template required and if so save the info,
this.getCustomTemplate(writeModel, page, data);
//retrieve information for page based on the data getter, with class group and individuals for classes getting different information
//the browse page does not have a "data getter"
this.getPageDataGetterInfo(vreq, writeModel, page, data);
//This is an all statement iterator
log.debug("Debug statements: all statements in model for debugger");
StmtIterator debugIt = writeModel.listStatements(page, null, (RDFNode) null);
while(debugIt.hasNext()) {
log.debug("Statement: " + debugIt.nextStatement().toString());
}
}
}
private void checkHomePage(OntModel writeModel, Individual page,
Map<String, Object> data) {
StmtIterator homePageIt = writeModel.listStatements(page, RDF.type, ResourceFactory.createResource(DisplayVocabulary.HOME_PAGE_TYPE));
if (homePageIt.hasNext()) {
data.put("isHomePage", true);
data.put("isClassGroupPage", false);
//Home Page does not have a "group" associated with
data.put("associatedPage", "");
data.put("associatedPageURI", "");
data.put("classGroup", new ArrayList<String>());
data.put("includeAllClasses", false);
}
}
//If custom template included, get that information
private void getCustomTemplate(OntModel writeModel, Individual page,
Map<String, Object> data) {
StmtIterator customTemplateIt = writeModel.listStatements(page, DisplayVocabulary.REQUIRES_BODY_TEMPLATE, (RDFNode) null);
if (customTemplateIt.hasNext()) {
String customTemplate = customTemplateIt.nextStatement().getLiteral().getString();
data.put("selectedTemplateType", "custom");
data.put("customTemplate", customTemplate);
} else {
data.put("selectedTemplateType", "default");
}
}
//Get data getter related info
//All items will have data getter except for Browse or Home page
//Home can be edited but not removed
private void getPageDataGetterInfo(VitroRequest vreq, OntModel writeModel, Resource page, Map<String, Object> data) {
//Alternative is to do this via sparql query
StmtIterator dataGetterIt = writeModel.listStatements(page, ResourceFactory.createProperty(DisplayVocabulary.HAS_DATA_GETTER), (RDFNode) null);
while(dataGetterIt.hasNext()) {
Statement dataGetterStmt = dataGetterIt.nextStatement();
Resource dataGetter = dataGetterStmt.getResource();
if(dataGetter != null) {
this.retrieveData(vreq, dataGetter.getURI(), data);
}
/*
//Get types of data getter
StmtIterator dataGetterTypes = writeModel.listStatements(dataGetter, RDF.type, (RDFNode) null);
while(dataGetterTypes.hasNext()) {
String dataGetterType = dataGetterTypes.nextStatement().getResource().getURI();
this.retrieveData(vreq, dataGetterType, data);
}*/
}
}
private void retrieveData(VitroRequest vreq, String dataGetterURI, Map<String, Object> templateData) {
//Data Getter type is now a class name
Model displayModel = vreq.getDisplayModel();
try{
String className = DataGetterUtils.getJClassForDataGetterURI(displayModel, dataGetterURI);
//TODO: Change so that instantiation here occurs correctly <-- how should data getter be instantiated
DataGetter pg = DataGetterUtils.dataGetterForURI(vreq, vreq.getDisplayModel(), dataGetterURI);
//TODO: Check template data variable and what that is?
Map<String, Object> pageData = pg.getData(templateData);
//Map<String, Object> pageInfo = vreq.getWebappDaoFactory().getPageDao().getPage(pageURI);
SelectDataGetterUtils.processAndRetrieveData(vreq, getServletContext(), pageData, className, templateData);
} catch(Exception ex) {
log.error("Exception occurred in instantiation page data getter for " + dataGetterURI, ex);
}
}
}

View file

@ -1,75 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.HashMap;
import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
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;
public class MenuN3EditController extends FreemarkerHttpServlet {
protected final static String N3MENU_FORM = "menuN3Edit.ftl";
protected final static String N3MENU_SUCCESS_RESULT = "menuN3Edit.ftl";
protected final static String N3MENU_ERROR_RESULT = "menuN3Edit.ftl";
protected final static String N3_PARAM = "navigationN3";
public final static Actions REQUIRED_ACTIONS = SimplePermission.MANAGE_MENUS.ACTIONS;
@Override
protected Actions requiredActions(VitroRequest vreq) {
return REQUIRED_ACTIONS;
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
String n3 = vreq.getParameter(N3_PARAM);
if( n3 != null && ! n3.isEmpty()){
return setNewMenu(vreq);
}else{
return showForm(vreq);
}
}
private ResponseValues showForm(VitroRequest vreq) {
Map<String,Object> data = new HashMap<String,Object>();
String menuN3;
try {
menuN3 = vreq.getWebappDaoFactory().getDisplayModelDao()
.getDisplayModel(getServletContext());
data.put("menuN3", menuN3);
data.put("cancelUrl", "/siteAdmin");
} catch (Exception e) {
data.put("errorMessage",e.getMessage());
}
return new TemplateResponseValues(N3MENU_FORM, data);
}
private ResponseValues setNewMenu(VitroRequest vreq) {
Map<String,Object> data = new HashMap<String,Object>();
String menuN3 = vreq.getParameter(N3_PARAM);
try {
vreq.getWebappDaoFactory().getDisplayModelDao()
.replaceDisplayModel(menuN3, getServletContext());
data.put("message", "success");
} catch (Exception e) {
data.put("errorMessage",e.getMessage());
}
if( data.containsKey("errorMessage"))
return new TemplateResponseValues(N3MENU_ERROR_RESULT,data);
else
return new TemplateResponseValues(N3MENU_SUCCESS_RESULT, data);
}
}

View file

@ -1,491 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
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;
import java.util.Map;
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.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
/**
* Generates the edit configuration for a default property form.
*
*/
public class MenuEditingFormGenerator implements EditConfigurationGenerator {
private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class);
private String template = "testMenuEdit.ftl";
//Set when processing
//private String subjectUriJson = null;
//private String predicateUriJson = null;
//private String objectUriJson = null;
//TODO: Check if above even needed or if we can process using regular uris
private String subjectUri = null;
private String predicateUri = null;
private String objectUri = null;
//whether or not this is an object or data prop
private boolean isObjectPropForm = false;
//from 'default data prop form'
private static HashMap<String,String> defaultsForXSDtypes;
static {
defaultsForXSDtypes = new HashMap<String,String>();
//defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","2001-01-01T12:00:00");
defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","#Unparseable datetime defaults to now");
}
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) {
//The actual N3 created here needs to include multiple levels from hasElement all the way down to the
//actual pagej
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
//will this forward to the appropriate controller
String queryString = vreq.getQueryString();
String redirectPage = vreq.getContextPath() + "/menuManagementController?" + queryString;
editConfiguration.setSkipToUrl(redirectPage);
/*
//Setting a custom test template for now
//TODO: Where to get this custom template from? Should it be a predicate in display model somewhere?
editConfiguration.setTemplate(this.template);
//process subject, predicate, object parameters
this.initProcessParameters(vreq, editConfiguration);
//Assumes this is a simple case of subject predicate var
editConfiguration.setN3Required(this.generateN3Required(vreq));
//n3 optional
editConfiguration.setN3Optional(this.generateN3Optional());
//Todo: what do new resources depend on here?
//In original form, these variables start off empty
editConfiguration.setNewResources(new HashMap<String, String>());
//In scope
this.setUrisAndLiteralsInScope(editConfiguration);
//on Form
this.setUrisAndLiteralsOnForm(editConfiguration);
editConfiguration.setFilesOnForm(new ArrayList<String>());
//Sparql queries
this.setSparqlQueries(editConfiguration);
//Set up fields
this.setFields(editConfiguration, vreq);
//set submission url
editConfiguration.setSubmitToUrl("/edit/process");
editConfiguration.putConfigInSession(editConfiguration, session);
//Here, retrieve model from
//Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
//Use special model instead
Individual subject = (Individual)vreq.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)vreq.getAttribute("predicate");
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
Model model = (Model) vreq.getWriteModel();
this.prepareForUpdate(vreq, editConfiguration, model, subject, prop, wdf);
this.associatePageData(vreq, editConfiguration, model);
//don't need this here exactly
//this.generateSelectForExisting(vreq, session, editConfiguration, subject, prop, wdf);
*/
return editConfiguration;
}
private void associatePageData(VitroRequest vreq,
EditConfigurationVTwo editConfiguration, Model model) {
vreq.setAttribute("formTitle", "Edit Menu Item");
//
}
//Initialize setup: process parameters
private void initProcessParameters(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
String formUrl = (String)vreq.getAttribute("formUrl");
String editKey = (String)vreq.getAttribute("editKey");
System.out.println("Form url is " + formUrl + " and editKey is " + editKey);
//this.subjectUriJson = (String)vreq.getAttribute("subjectUriJson");
//this.predicateUriJson = (String)vreq.getAttribute("predicateUriJson");
//this.objectUriJson = (String)vreq.getAttribute("objectUriJson");
//regular, non json version
this.subjectUri = (String)vreq.getAttribute("subjectUri");
this.predicateUri = (String)vreq.getAttribute("predicateUri");
this.objectUri = (String)vreq.getAttribute("objectUri");
//Get actual object uri as not concerned with json escaped version
//System.out.println("Object Uri is " + objectUri + " and json version is " + objectUriJson);
//Set up EditConfigurationVTwo object
editConfiguration.setFormUrl(formUrl);
editConfiguration.setEditKey(editKey);
editConfiguration.setUrlPatternToReturnTo("/individual");
//subject, predicate, objectVar
editConfiguration.setVarNameForSubject("subject");
editConfiguration.setSubjectUri(subjectUri);
editConfiguration.setVarNameForPredicate("predicate");
editConfiguration.setPredicateUri(predicateUri);
//this needs to be set for the editing to be triggered properly, otherwise the 'prepare' method
//pretends this is a data property editing statement and throws an error
//"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
//if(objectUri != null) {
//not concerned about remainder, can move into default obj prop form if required
this.isObjectPropForm = true;
this.processObjectPropForm(vreq, editConfiguration);
//} else {
// this.isObjectPropForm = false;
// this.processDataPropForm(vreq, editConfiguration);
//}
}
private void processObjectPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
editConfiguration.setVarNameForObject("objectVar");
editConfiguration.setObject(objectUri);
}
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
Integer dataHash = EditConfigurationUtils.getDataHash(vreq);
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
//ObjectUriJson is null, so should include data prop info here
//Use dataprop key info here instead
DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
//if( prop == null ) return doHelp(vreq, "In DefaultDataPropertyFormGenerator, could not find predicate " + predicateUri);
//Why are we setting attributes here again?
vreq.setAttribute("propertyName",prop.getPublicName());
Individual subject = (Individual)vreq.getAttribute("subject");
//if( subject == null ) return doHelp(vreq,"In DefaultDataPropertyFormGenerator, could not find subject " + subjectUri);
vreq.setAttribute("subjectName",subject.getName());
String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop);
//String rangeDatatypeUri = prop.getRangeDatatypeURI();
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
if( dps != null ){
log.debug("dataHash is " + dataHash);
String rangeDatatype = dps.getDatatypeURI();
if( rangeDatatype == null ){
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator");
vreq.setAttribute("rangeDatatypeUriJson","");
} else {
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in DefaultDataPropertyFormGenerator");
vreq.setAttribute("rangeDatatypeUriJson",rangeDatatype);
}
String rangeLang = dps.getLanguage();
if( rangeLang == null ) {
log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator");
vreq.setAttribute("rangeLangJson","");
}else{
log.debug("language attribute of ["+rangeLang+"] on data property statement in DefaultDataPropertyFormGenerator");
vreq.setAttribute("rangeLangJson", rangeLang);
}
} else {
log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+"; adding a new statement");
if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) {
String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri);
if( defaultVal == null )
vreq.setAttribute("rangeDefaultJson", "");
else
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
}
}
editConfiguration.setDatapropKey(dataHash);
}
//Get N3 required specifically for menu management
//?Is it necessarily separate
private List<String> generateN3Required(VitroRequest vreq) {
List<String> n3ForEdit = new ArrayList<String>();
String n3String = "?subject ?predicate ";
//n3ForEdit.add("?subject");
//n3ForEdit.add("?predicate");
//leaving check out for now
//if(this.isObjectPropForm) {
n3String += "?objectVar .";
//n3ForEdit.add("?objectVar");
//In this case, defaultMenu hasElement ?objectVar
//Now add Strings
//?objectVar hasPage ?page
n3ForEdit.add(n3String);
n3ForEdit.add("\n ?objectVar <" + DisplayVocabulary.ITEM_TO_PAGE + "> ?page .");
n3ForEdit.add("\n ?page <" + DisplayVocabulary.DISPLAY_NS+ "title> ?title .");
// } else {
// DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
// String localName = prop.getLocalName();
// String dataLiteral = localName + "Edited";
// n3String += "?"+dataLiteral;
// n3ForEdit.add(n3String);
// }
return n3ForEdit;
}
//Below: use to replace default obj prop form
//Handles both object and data property
/*
private List<String> generateN3Required(VitroRequest vreq) {
List<String> n3ForEdit = new ArrayList<String>();
n3ForEdit.add("?subject");
n3ForEdit.add("?predicate");
if(this.isObjectPropForm) {
n3ForEdit.add("?objectVar");
} else {
DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
String localName = prop.getLocalName();
String dataLiteral = localName + "Edited";
n3ForEdit.add("?"+dataLiteral);
}
return n3ForEdit;
}*/
private List<String> generateN3Optional() {
List<String> n3Inverse = new ArrayList<String>();
n3Inverse.add("?objectVar ?inverseProp ?subject . \n");
// n3Inverse.add("?page ?inversePage ?objectVar .");
//n3Inverse.add("?objectVar");
//n3Inverse.add("?inverseProp");
//n3Inverse.add("?subject");
return n3Inverse;
}
//Set queries
private String retrieveQueryForInverse () {
String queryForInverse = "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
+ " SELECT ?inverse_property "
+ " WHERE { ?inverse_property owl:inverseOf ?predicate } ";
return queryForInverse;
}
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) {
editConfiguration.setUrisInScope(new HashMap<String, List<String>>());
editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>());
}
//n3 should look as follows
//?subject ?predicate ?objectVar .
//?objectVar display:linkText ?name .
//?objectVar display:toPage ?page .
//?page rdf:type ?type . //multiple types possible
//?page display:title ?title .
//?page display:urlMapping ?mapping .
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration) {
List<String> urisOnForm = new ArrayList<String>();
urisOnForm.add("objectVar");
//Also adding page
urisOnForm.add("page");
editConfiguration.setUrisOnform(urisOnForm);
//let's just get title
List<String> literalsOnForm = new ArrayList<String>();
literalsOnForm.add("title");
editConfiguration.setLiteralsOnForm(literalsOnForm);
}
//This is for various items
private void setSparqlQueries(EditConfigurationVTwo editConfiguration) {
//Sparql queries defining retrieval of literals etc.
editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap<String, String>());
Map<String, String> urisInScope = new HashMap<String, String>();
urisInScope.put("inverseProp", this.retrieveQueryForInverse());
editConfiguration.setSparqlForAdditionalUrisInScope(urisInScope);
editConfiguration.setSparqlForExistingLiterals(generateSparqlForExistingLiterals());
editConfiguration.setSparqlForExistingUris(generateSparqlForExistingUris());
}
//Get page uri for object
private HashMap<String, String> generateSparqlForExistingUris() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("page", "SELECT ?page where {?objectVar <" + DisplayVocabulary.TO_PAGE + "> ?page . } ");
return map;
}
private HashMap<String, String> generateSparqlForExistingLiterals() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", "SELECT ?title where {?page <" + DisplayVocabulary.DISPLAY_NS + "title> ?title . } ");
//If this works then add below
//Title, URL Mapping, type
//map.put("type", "SELECT ?type where {?page <" + RDF.type.getURI() + "> ?type . } ");
//And then being able to generate the Class groups required
//Could just pass that back in
return map;
}
//Get all properties for a page?
//Just get the properties?
//Fields
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
//Field should be for page title and other associations (assuming this is what actually goes on the form)
FieldVTwo field = new FieldVTwo();
field.setName("title");
List<String> validators = new ArrayList<String>();
validators.add("nonempty");
field.setValidators(validators);
fields.put("title", field);
//Object Var Field
//Won't need this in our case
/*
FieldVTwo field = new FieldVTwo();
field.setName("objectVar");
field.setNewResource(false);
//queryForExisting is not being used anywhere in Field
//TODO: Check how validators will work
List<String> validators = new ArrayList<String>();
validators.add("nonempty");
field.setValidators(validators);
//subjectUri and subjectClassUri are not being used in Field
field.setOptionsType("INDIVIDUALS_VIA_OBJECT_PROPERTY");
field.setPredicateUri(this.predicateUri);
field.setObjectClassUri(null);
field.setRangeDatatypeUri(null);
field.setRangeLang(null);
field.setLiteralOptions(new ArrayList<List<String>>());
List<String> assertions = new ArrayList<String>();
assertions.add("?subject");
assertions.add("?predicate");
assertions.add("?objectVar");
assertions.add("?objectVar");
assertions.add("?inverseProp");
assertions.add("?subject");
field.setAssertions(assertions);
fields.put("objectVar", field);
*/
//Fields for us will actually be page specific
//TODO: Check why/how this method signature has changed
editConfiguration.setFields(fields);
}
//Based on whether new or existing object prepare for update
//TODO: Update for data property editing as well
private void prepareForUpdate(VitroRequest vreq, EditConfigurationVTwo editConfiguration, Model model, Individual subject, ObjectProperty prop, WebappDaoFactory wdf) {
String formTitle = " ";
String submitLabel = " ";
//this block is for an edit of an existing object property statement
if(vreq.getAttribute("object") != null) {
editConfiguration.prepareForObjPropUpdate(model);
formTitle = "Change entry for: <em>" + prop.getDomainPublic() + " </em>";
submitLabel = "save change";
} else {
editConfiguration.prepareForNonUpdate( model );
if ( prop.getOfferCreateNewOption() ) {
//Try to get the name of the class to select from
VClass classOfObjectFillers = null;
if( prop.getRangeVClassURI() == null ) {
// If property has no explicit range, try to get classes
List<VClass> classes = wdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(), prop.getURI());
if( classes == null || classes.size() == 0 || classes.get(0) == null ){
// If property has no explicit range, we will use e.g. owl:Thing.
// Typically an allValuesFrom restriction will come into play later.
classOfObjectFillers = wdf.getVClassDao().getTopConcept();
} else {
if( classes.size() > 1 )
log.debug("Found multiple classes when attempting to get range vclass.");
classOfObjectFillers = classes.get(0);
}
}else{
classOfObjectFillers = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI());
if( classOfObjectFillers == null )
classOfObjectFillers = wdf.getVClassDao().getTopConcept();
}
log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]");
formTitle = "Select an existing "+classOfObjectFillers.getName()+" for "+subject.getName();
submitLabel = "select existing";
} else {
formTitle = "Add an entry to: <em>"+prop.getDomainPublic()+"</em>";
submitLabel = "save entry";
}
}
vreq.setAttribute("formTitle", formTitle);
vreq.setAttribute("submitLabel", submitLabel);
}
//if existing object values, allow for selection from existing
private void generateSelectForExisting(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration, Individual subject, ObjectProperty prop, WebappDaoFactory wdf) {
if( prop.getSelectFromExisting() ){
// set ProhibitedFromSearch object so picklist doesn't show
// individuals from classes that should be hidden from list views
OntModel displayOntModel =
(OntModel) session.getServletContext()
.getAttribute(DISPLAY_ONT_MODEL);
if (displayOntModel != null) {
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
if( editConfiguration != null )
editConfiguration.setProhibitedFromSearch(pfs);
}
Map<String,String> rangeOptions = SelectListGeneratorVTwo.getOptions(editConfiguration, "objectVar" , wdf);
if( rangeOptions != null && rangeOptions.size() > 0 ) {
vreq.setAttribute("rangeOptionsExist", true);
vreq.setAttribute("rangeOptions.objectVar", rangeOptions);
} else {
vreq.setAttribute("rangeOptionsExist",false);
}
}
}
//Process additional data
//In this case
}

View file

@ -139,7 +139,7 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
protected String getExistingValuesClassGroup(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?classGroup WHERE {" +
String query = this.getSparqlPrefix() + " SELECT ?classGroup WHERE {" +
"<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" +
"}";
return query;

View file

@ -118,7 +118,7 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
protected String getExistingValuesSparqlQuery(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" +
String query = this.getSparqlPrefix() + " SELECT ?saveToVar ?htmlValue WHERE {" +
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" +
"<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" +
"}";

View file

@ -32,7 +32,6 @@ import net.sf.json.JSONSerializer;
//Returns the appropriate n3 for selection of classes from within class group
public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroupDataGetterN3 {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter";
int classCount = 0;
protected static String individualClassVarNameBase = "classesSelectedInClassGroup";
private Log log = LogFactory.getLog(ProcessIndividualsForClassesDataGetterN3.class);
@ -54,9 +53,7 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
protected List<String> addIndividualClassesN3(int counter) {
List<String> classN3 = new ArrayList<String>();
if(classCount > 0) {
classN3.add(generateIndividualClassN3(counter));
}
return classN3;
}
@ -96,15 +93,6 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
}
private List<String> getIndividualClassesVarNames(int counter) {
List<String> individualClassUris = new ArrayList<String>();
int i;
for(i = 0; i < classCount; i++) {
individualClassUris.add(getVarName(individualClassVarNameBase + counter, classCount));
}
return individualClassUris;
}
public List<FieldVTwo> retrieveFields(int counter) {
List<FieldVTwo> fields = super.retrieveFields(counter);

View file

@ -137,7 +137,7 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
//?dataGetter a SparqlDataGetter ; display:saveToVar ?saveToVar; display:queryModel ?queryModel;
//display:query ?query ..
protected String getExistingValuesSparqlQuery(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?query ?queryModel WHERE {" +
String query = this.getSparqlPrefix() + " SELECT ?saveToVar ?query ?queryModel WHERE {" +
"<" + dataGetterURI + "> display:query ?query . \n" +
"OPTIONAL {<" + dataGetterURI + "> display:saveToVar ?saveToVar .} \n" +
"OPTIONAL {<" + dataGetterURI + "> display:queryModel ?queryModel . }\n" +

View file

@ -184,9 +184,7 @@ rdf:type
###Adding menu management customform annotation
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasElement>
a owl:ObjectProperty;
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#customEntryFormAnnot>
"edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.MenuEditingFormGenerator"^^xsd:string .
a owl:ObjectProperty .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#excludeClass>
a owl:ObjectProperty .

View file

@ -200,24 +200,6 @@
<url-pattern>/sdbsetup</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MenuN3EditController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.MenuN3EditController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MenuN3EditController</servlet-name>
<url-pattern>/menuN3Editor</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MenuManagementController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.MenuManagementController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MenuManagementController</servlet-name>
<url-pattern>/menuManagementController</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MenuManagementEdit</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.MenuManagementEdit</servlet-class>

View file

@ -75,8 +75,7 @@
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />',
'<link rel="stylesheet" href="${urls.base}/css/menupage/pageList.css" />',
'<link rel="stylesheet" href="${urls.base}/css/menumanagement/menuManagement.css" />')}
'<link rel="stylesheet" href="${urls.base}/css/menupage/pageList.css" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>')}