diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java index 190768a83..0d6c88651 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java @@ -436,15 +436,15 @@ public class EditConfigurationVTwo { } public void setN3Required(String ... n3RequiredStrs){ - this.n3Required = Arrays.asList( n3RequiredStrs ); + this.n3Required = new ArrayList(Arrays.asList( n3RequiredStrs )); //using ArrayList to allow list to be resized } //these methods allow strings to be added to the n3 required list and not just for the list to be set - public void addN3Required(List n3Required) { - this.n3Required.addAll(n3Required); + public void addN3Required(List n3RequiredInput) { + this.n3Required.addAll(n3RequiredInput); } - public void addN3Required(String ... n3RequiredStrs) { - this.n3Required.addAll(Arrays.asList( n3RequiredStrs )); + public void addN3Required(String ... n3RequiredStrsInput) { + this.n3Required.addAll(Arrays.asList( n3RequiredStrsInput )); } /** return a copy of the value so that the configuration is not modified by external code. * @return @@ -458,7 +458,7 @@ public class EditConfigurationVTwo { } public void setN3Optional(String ... n3Strs){ - this.n3Optional = Arrays.asList( n3Strs ); + this.n3Optional = new ArrayList(Arrays.asList( n3Strs )); //using ArrayList to allow list to be resized } public void addN3Optional(List n3Optional) { @@ -501,7 +501,7 @@ public class EditConfigurationVTwo { } public void setUrisOnForm(String ... strs){ - this.urisOnform = Arrays.asList( strs ); + this.urisOnform = new ArrayList(Arrays.asList( strs )); //using ArrayList to allow resizing } //This doesn't overwrite or set but adds to existing list public void addUrisOnForm(List urisOnform) { @@ -530,7 +530,7 @@ public class EditConfigurationVTwo { } public void setLiteralsOnForm(String ... strs){ - this.literalsOnForm = Arrays.asList( strs ); + this.literalsOnForm = new ArrayList(Arrays.asList( strs ));//using ArrayList to allow resizing } public void addLiteralsOnForm(List literalsOnForm) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java index 0919ce4e2..4514ba5c1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpSession; import com.hp.hpl.jena.ontology.OntModel; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; 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; @@ -27,7 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataU public class ManagePageGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator{ private String template = "pageManagement.ftl"; - + public static final String defaultDisplayNs = DisplayVocabulary.NAMESPACE.getURI() + "n"; @Override public EditConfigurationVTwo getEditConfiguration( VitroRequest vreq, HttpSession session) { EditConfigurationVTwo conf = new EditConfigurationVTwo(); @@ -71,7 +72,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen private void setUrisAndLiteralsOnForm(EditConfigurationVTwo conf, VitroRequest vreq) { conf.setUrisOnForm(new String[]{"page", "menuItem"}); //new resources: should this be on form for new - should be for existing - conf.setLiteralsOnForm(new String[]{"pageTitle", "urlMapping", "linkText", "menuPosition", "menuLinkText", "bodyTemplate", "pageContentUnit"}); //page content unit = data getter JSON object + conf.setLiteralsOnForm(new String[]{"pageName", "prettyUrl", "menuPosition", "menuLinkText", "customTemplate", "pageContentUnit"}); //page content unit = data getter JSON object } @@ -88,12 +89,12 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen private void setN3Optional(EditConfigurationVTwo conf) { //body template is not required, and a given page may or may not be a menu item, but should linked to menu if menu item - conf.setN3Optional(Arrays.asList(prefixes + pageBodyTemplateN3, - prefixes + menuItemN3 + menuN3)); + conf.setN3Optional(new ArrayList(Arrays.asList(prefixes + pageBodyTemplateN3, + prefixes + menuItemN3 + menuN3))); } private void setN3Required(EditConfigurationVTwo conf) { - conf.setN3Required(Arrays.asList(prefixes + pageN3)); + conf.setN3Required(new ArrayList(Arrays.asList(prefixes + pageN3))); } @@ -103,24 +104,31 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen //Optional fields for page include body template //required, therefore nonempty - FieldVTwo titleField = new FieldVTwo().setName("pageTitle"). + FieldVTwo titleField = new FieldVTwo().setName("pageName"). setValidators(Arrays.asList("nonempty")); conf.addField(titleField); - FieldVTwo urlField = new FieldVTwo().setName("urlMapping").setValidators(Arrays.asList("nonempty")); + FieldVTwo urlField = new FieldVTwo().setName("prettyUrl").setValidators(Arrays.asList("nonempty")); conf.addField(urlField); //optional: body template - FieldVTwo bodyTemplateField = new FieldVTwo().setName("bodyTemplate"); + FieldVTwo bodyTemplateField = new FieldVTwo().setName("customTemplate"); conf.addField(bodyTemplateField); //For menu item, these are optional b/c they depend on menu item - FieldVTwo menuItemLinkTextField = new FieldVTwo().setName("linkText"); + FieldVTwo menuItemLinkTextField = new FieldVTwo().setName("menuLinkText"); conf.addField(menuItemLinkTextField); FieldVTwo menuItemPositionField = new FieldVTwo().setName("menuPosition"); conf.addField(menuItemPositionField); + + //The actual page content information is stored in this field, and then + //interpreted using the preprocessor + FieldVTwo pageContentUnitField = new FieldVTwo().setName("pageContentUnit"); + conf.addField(pageContentUnitField); + + //For existing values, will need to include fields here } @@ -152,7 +160,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen } else { //For the case of an existing page - //Page title pageTitle or page hasDataGetter dataGetter + //Page title pageName or page hasDataGetter dataGetter editConfiguration.setUrlPatternToReturnTo("/individual"); editConfiguration.setEntityToReturnTo(subjectUri); } @@ -182,8 +190,8 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen //In the case where this is a new page, need to ensure page gets a new private void setNewResources(EditConfigurationVTwo conf) { //null makes default namespace be triggered - conf.addNewResource("page", DEFAULT_NS_FOR_NEW_RESOURCE); - conf.addNewResource("menuItem", DEFAULT_NS_FOR_NEW_RESOURCE); + conf.addNewResource("page", defaultDisplayNs); + conf.addNewResource("menuItem", defaultDisplayNs); } @@ -255,7 +263,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen data.put("menuAction", "Add"); //Generate empty values for fields data.put("menuItem", ""); - data.put("menuName", ""); + data.put("pageName", ""); data.put("prettyUrl", ""); data.put("associatedPage", ""); data.put("associatedPageURI", ""); @@ -275,15 +283,15 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen "@prefix rdfs: . \n"; final static String pageN3 = "?page a display:Page ; \n" + - "display:title ?pageTitle ;\n" + - "display:urlMapping ?urlMapping ."; + "display:title ?pageName ;\n" + + "display:urlMapping ?prettyUrl ."; //"display:hasDataGetter ?pageDataGetter ."; //A page may also require a body template so we can get that here as well //That would be optional - final static String pageBodyTemplateN3 = "?page display:requiresBodyTemplate ?bodyTemplate ."; + final static String pageBodyTemplateN3 = "?page display:requiresBodyTemplate ?customTemplate ."; //Menu position is added dynamically at end by default and can be changed on reordering page final static String menuItemN3 = "?menuItem a display:NavigationElement ; \n" + @@ -297,8 +305,8 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen final static String menuN3 = "display:DefaultMenu display:hasElement ?menuItem ."; //These are public static methods that can be used in the preprocessor - public final static String getDataGetterN3(int numberDataGetter) { - return prefixes + "?page display:hasDataGetter ?dataGetter" + numberDataGetter + "."; + public final static String getDataGetterN3(String dataGetterVar) { + return prefixes + "?page display:hasDataGetter " + dataGetterVar + "."; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java index 6c71ff934..694fc7322 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java @@ -3,6 +3,8 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,11 +15,14 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; + +import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo; 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.MultiValueEditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManagePageGenerator; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3Utils; import net.sf.json.JSONObject; @@ -78,7 +83,7 @@ public class ManagePagePreprocessor extends int counter = 0; for(JSONObject jsonObject:pageContentUnitsJSON) { String dataGetterClass = getDataGetterClass(jsonObject); - ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject); + ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass); //Add n3 required addN3Required(pn, counter); //Add N3 Optional as well @@ -87,14 +92,23 @@ public class ManagePagePreprocessor extends addLiteralsAndUrisOnForm(pn, counter); // Add fields addFields(pn, counter); + //Add new resources - data getters need to be new resources + addNewResources(pn, counter); //Add input values to submission addInputsToSubmission(pn, counter, jsonObject); counter++; } - - - + } + + + private void addNewResources(ProcessDataGetterN3 pn, int counter) { + // TODO Auto-generated method stub + List newResources = pn.getNewResources(counter); + for(String newResource:newResources) { + editConfiguration.addNewResource(newResource, ManagePageGenerator.defaultDisplayNs); + } + } private void convertToJson() { @@ -193,13 +207,29 @@ public class ManagePagePreprocessor extends //This will overwrite the original with the set of new n3 required private void addN3Required(ProcessDataGetterN3 pn, int counter) { //Use the process utils to figure out what class required to retrieve the N3 required - editConfiguration.addN3Required(pn.retrieveN3Required(counter)); + List requiredList = pn.retrieveN3Required(counter); + //Add connection between data getter and page + requiredList.addAll(getPageToDataGetterN3(pn, counter)); + if(requiredList != null) { + editConfiguration.addN3Required(requiredList); + } + } + private List getPageToDataGetterN3( + ProcessDataGetterN3 pn, int counter) { + String dataGetterVar = pn.getDataGetterVar(counter); + //Put this method in the generator but can be put elsewhere + String pageToDataGetterN3 = ManagePageGenerator.getDataGetterN3(dataGetterVar); + return Arrays.asList(pageToDataGetterN3); } + //Add n3 optional private void addN3Optional(ProcessDataGetterN3 pn, int counter) { - editConfiguration.addN3Optional(pn.retrieveN3Optional(counter)); + List optionalList = pn.retrieveN3Optional(counter); + if(optionalList != null) { + editConfiguration.addN3Optional(optionalList); + } } private String[] convertDelimitedStringToArray(String inputString) { @@ -224,11 +254,21 @@ public class ManagePagePreprocessor extends //Each JSON Object will indicate the type of the data getter within it private String getDataGetterClass(JSONObject jsonObject) { - return jsonObject.getString("dataGetterClass"); + String javaURI = jsonObject.getString("dataGetterClass"); + return getQualifiedDataGetterName(javaURI); } - + //Get rid of java: in front of class name + private String getQualifiedDataGetterName(String dataGetterTypeURI) { + String javaURI = "java:"; + + if(dataGetterTypeURI.startsWith(javaURI)) { + int beginIndex = javaURI.length(); + return dataGetterTypeURI.substring(beginIndex); + } + return dataGetterTypeURI; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java index 912f8722b..a69417d4c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java @@ -20,5 +20,7 @@ public interface ProcessDataGetterN3 { public List getLiteralVarNamesBase(); public List getUriVarNamesBase(); public String getVarName(String base, int counter); + public String getDataGetterVar(int counter); + public List getNewResources(int counter); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Utils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Utils.java index d28adce91..ff4a96daf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Utils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Utils.java @@ -32,13 +32,15 @@ public class ProcessDataGetterN3Utils { return map; } - public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, JSONObject jsonObject) { + public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass) { HashMap map = getDataGetterTypeToProcessorMap(); + // if(map.containsKey(dataGetterClass)) { String processorClass = map.get(dataGetterClass); try { Class clz = Class.forName(processorClass); - ProcessDataGetterN3 pn = (ProcessDataGetterN3) clz.getConstructor(JSONObject.class).newInstance(jsonObject); + //Don't actually need to pass in json object since that includes the actual submission values + ProcessDataGetterN3 pn = (ProcessDataGetterN3) clz.getConstructor().newInstance(); return pn; } catch(Exception ex) { log.error("Exception occurred in trying to get processor class for n3 for " + dataGetterClass, ex); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java index 57f9c0aed..37b1d6c43 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java @@ -15,31 +15,33 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; //Returns the appropriate n3 based on data getter -public class ProcessSparqlDataGetterN3 implements ProcessDataGetterN3 { +public class ProcessSparqlDataGetterN3 implements ProcessDataGetterN3 { private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter"; - private JSONObject jsonObject = null; - public ProcessSparqlDataGetterN3(JSONObject inputJsonObject) { - jsonObject = inputJsonObject; + public ProcessSparqlDataGetterN3(){ + } //Pass in variable that represents the counter //TODO: ensure correct model returned + //We shouldn't use the ACTUAL values here but generate the n3 required public List retrieveN3Required(int counter) { String dataGetterVar = getDataGetterVar(counter); String n3 = dataGetterVar + " a <" + classType + ">; \n" + - "display:queryModel <" + jsonObject.getString("queryModel") + ">; \n" + - "display:saveToVar '" + jsonObject.getString("saveToVar") + "'; \n" + - "display:query \"\"\"" + jsonObject.getString("query") + "\"\"\" ."; - return Arrays.asList(getPrefixes() + n3); + "display:queryModel " + getN3VarName("queryModel", counter) + "; \n" + + "display:saveToVar " + getN3VarName("saveToVar", counter) + "; \n" + + "display:query " + getN3VarName("query", counter) + " ."; + List requiredList = new ArrayList(); + requiredList.add(getPrefixes() + n3); + return requiredList; } public List retrieveN3Optional(int counter) { return null; } - - private String getDataGetterVar(int counter) { - return "dataGetter" + counter; + //placeholder so need "?" in front of the variable + public String getDataGetterVar(int counter) { + return "?dataGetter" + counter; } private String getPrefixes() { @@ -85,7 +87,8 @@ public class ProcessSparqlDataGetterN3 implements ProcessDataGetterN3 { for(String varName: allFieldsBase) { fields.add(new FieldVTwo().setName(getVarName(varName, counter))); } */ - + //For existing data getters + //fields.add(new FieldVTwo().setName(getVarName("dataGetter", counter))); fields.add(new FieldVTwo().setName(getVarName("queryModel", counter))); fields.add(new FieldVTwo().setName(getVarName("saveToVar", counter))); fields.add(new FieldVTwo().setName(getVarName("query", counter))); @@ -94,9 +97,10 @@ public class ProcessSparqlDataGetterN3 implements ProcessDataGetterN3 { } public List getLiteralVarNamesBase() { - return Arrays.asList("savetoVar", "query"); + return Arrays.asList("saveToVar", "query"); } + //these are for the fields ON the form public List getUriVarNamesBase() { return Arrays.asList("queryModel"); } @@ -105,6 +109,18 @@ public class ProcessSparqlDataGetterN3 implements ProcessDataGetterN3 { return base + counter; } + //For use within n3 strings, need a "?" + public String getN3VarName(String base, int counter) { + return "?" + getVarName(base, counter); + } + + //Return name of new resources + public List getNewResources(int counter) { + //Each data getter requires a new resource + List newResources = new ArrayList(); + newResources.add("dataGetter" + counter); + return newResources; + } } diff --git a/webapp/web/js/menupage/pageManagementUtils.js b/webapp/web/js/menupage/pageManagementUtils.js index ecee84e15..8ccb35a2d 100644 --- a/webapp/web/js/menupage/pageManagementUtils.js +++ b/webapp/web/js/menupage/pageManagementUtils.js @@ -199,7 +199,7 @@ var pageManagementUtils = { if (validationError == "") { //Create the appropriate json objects pageManagementUtils.createPageContentForSubmission(); - $(this).submit(); + return true; } else{ $('#error-alert').removeClass('hidden'); $('#error-alert p').html(validationError); @@ -433,7 +433,7 @@ var pageManagementUtils = { var validationError = ""; // Check menu name - if ($('input[type=text][name=menuName]').val() == "") { + if ($('input[type=text][name=pageName]').val() == "") { validationError += "You must supply a name
"; } // Check pretty url diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl index a33d9e4ca..fbe48bed9 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl @@ -4,14 +4,12 @@ <#assign menuAction = pageData.menuAction /> <#assign classGroup = pageData.classGroup /> <#assign classGroups = pageData.classGroups /> - +<#assign pageName = "" /> <#assign selectedTemplateType = "default" /> -<#assign menuItem = ""/> -<#assign menuName = ""/> <#assign prettyUrl = ""/> <#assign associatedPage = ""/> <#assign associatedPageURI = ""/> - +<#assign menuItem = ""/> <#assign isClassGroupPage = false/> <#assign includeAllClasses = false/> @@ -32,10 +30,10 @@ <#--class group section has associated page uri, but that depends on editing a current page or if one is selected later-->
<#--form method="POST" action="${formUrls}" role="${menuAction} menu item"--> -
+ - +

Add Page