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 5476b29ba..6bef8be20 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 @@ -25,9 +25,11 @@ 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.JSON; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; - +import net.sf.json.util.JSONUtils; public class ManagePagePreprocessor extends BaseEditSubmissionPreprocessorVTwo { @@ -83,7 +85,7 @@ public class ManagePagePreprocessor extends int counter = 0; for(JSONObject jsonObject:pageContentUnitsJSON) { String dataGetterClass = getDataGetterClass(jsonObject); - ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass); + ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject); //Add n3 required addN3Required(pn, counter); //Add N3 Optional as well @@ -136,23 +138,52 @@ public class ManagePagePreprocessor extends List uriLabels = pn.getUriVarNamesBase(); for(String literalLabel:literalLabels) { - //TODO: Deal with multiple submission values - //This retrieves the value for this particular json object - String literalValue = jsonObject.getString(literalLabel); - //Var names will depend on which data getter object this is on the page, so depends on counter + List literalValues = new ArrayList(); + Object jsonValue = jsonObject.get(literalLabel); + //Var names will depend on which data getter object this is on the page, so depends on counter String submissionLiteralName = pn.getVarName(literalLabel, counter); + //Single value + if(jsonValue instanceof String) { + //TODO: Deal with multiple submission values + //This retrieves the value for this particular json object + literalValues.add(jsonObject.getString(literalLabel)); + } else if(jsonValue instanceof JSONArray) { + JSONArray values = jsonObject.getJSONArray(literalLabel); + literalValues = (List) JSONSerializer.toJava(values); + } //This adds literal, connecting the field with - submission.addLiteralToForm(editConfiguration, editConfiguration.getField(submissionLiteralName), submissionLiteralName, new String[]{literalValue}); + submission.addLiteralToForm(editConfiguration, + editConfiguration.getField(submissionLiteralName), + submissionLiteralName, + (String[])literalValues.toArray()); } for(String uriLabel:uriLabels) { - //TODO: Deal with multiple submission values - //This retrieves the value for this particular json object - String uriValue = jsonObject.getString(uriLabel); - //Var names will depend on which data getter object this is on the page, so depends on counter + List uriValues = new ArrayList(); + Object jsonValue = jsonObject.get(uriLabel); + //Var names will depend on which data getter object this is on the page, so depends on counter String submissionUriName = pn.getVarName(uriLabel, counter); - //This adds literal, connecting the field with - submission.addLiteralToForm(editConfiguration, editConfiguration.getField(submissionUriName), submissionUriName, new String[]{uriValue}); + //if single value, then, add to values + if(jsonValue instanceof String) { + //Var names will depend on which data getter object this is on the page, so depends on counter + //This retrieves the value for this particular json object and adds to list + uriValues.add(jsonObject.getString(uriLabel)); + + } else if(jsonValue instanceof JSONArray) { + //multiple values + JSONArray values = jsonObject.getJSONArray(uriLabel); + uriValues = (List) JSONSerializer.toJava(values); + } else { + //This may include JSON Objects but no way to deal with these right now + } + String[] uriValuesSubmission = new String[uriValues.size()]; + + uriValuesSubmission = uriValues.toArray(uriValuesSubmission); + //This adds literal, connecting the field with the value + submission.addLiteralToForm(editConfiguration, + editConfiguration.getField(submissionUriName), + submissionUriName, + uriValuesSubmission); } //this needs to be different diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessClassGroupDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessClassGroupDataGetterN3.java index 68081a740..f1070ef6e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessClassGroupDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessClassGroupDataGetterN3.java @@ -17,7 +17,7 @@ import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; //Returns the appropriate n3 based on data getter public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract { - private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupDataGetter"; + private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData"; public ProcessClassGroupDataGetterN3(){ 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 ff4a96daf..4e74d8589 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 @@ -2,6 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; +import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; @@ -20,6 +21,7 @@ import com.hp.hpl.jena.rdf.model.StmtIterator; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3; +import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter; /* * This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO. @@ -29,18 +31,19 @@ public class ProcessDataGetterN3Utils { public static HashMap getDataGetterTypeToProcessorMap() { HashMap map = new HashMap(); map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSparqlDataGetterN3"); + map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessClassGroupDataGetterN3"); + map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessIndividualsForClassesDataGetterN3"); + return map; } - public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass) { + public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, JSONObject jsonObject) { HashMap map = getDataGetterTypeToProcessorMap(); // if(map.containsKey(dataGetterClass)) { String processorClass = map.get(dataGetterClass); try { - Class clz = Class.forName(processorClass); - //Don't actually need to pass in json object since that includes the actual submission values - ProcessDataGetterN3 pn = (ProcessDataGetterN3) clz.getConstructor().newInstance(); + ProcessDataGetterN3 pn = instantiateClass(processorClass, jsonObject); return pn; } catch(Exception ex) { log.error("Exception occurred in trying to get processor class for n3 for " + dataGetterClass, ex); @@ -50,4 +53,23 @@ public class ProcessDataGetterN3Utils { return null; } + private static ProcessDataGetterN3 instantiateClass(String processorClass, JSONObject jsonObject) { + ProcessDataGetterN3 pn = null; + try { + Class clz = Class.forName(processorClass); + Constructor ct = clz.getConstructor(); + Class[] parameterTypes =ct.getParameterTypes(); + if(parameterTypes.length > 0 && parameterTypes[0].isAssignableFrom(jsonObject.getClass())) { + pn = (ProcessDataGetterN3) ct.newInstance(jsonObject); + } else { + pn = (ProcessDataGetterN3) ct.newInstance(); + } + + } catch(Exception ex) { + log.error("Error occurred instantiating " + processorClass, ex); + } + return pn; + + } + } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessIndividualsForClassesDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessIndividualsForClassesDataGetterN3.java new file mode 100644 index 000000000..1328fb773 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessIndividualsForClassesDataGetterN3.java @@ -0,0 +1,133 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; + +import java.util.Collection; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import com.hp.hpl.jena.rdf.model.Literal; + +import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +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"; + private JSONObject values = null; + int classCount = 0; + private static String individualClassVarNameBase = "classesSelectedInClassGroup"; + public ProcessIndividualsForClassesDataGetterN3(JSONObject jsonObject){ + this.values = jsonObject; + if(values != null && values.containsKey(individualClassVarNameBase)) { + //Check how many individual classes are in json object + JSONArray ja = values.getJSONArray(individualClassVarNameBase); + classCount = ja.size(); + } + } + //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) { + List classGroupN3 = super.retrieveN3Required(counter); + classGroupN3.addAll(this.addIndividualClassesN3(counter)); + return classGroupN3; + + } + + + private List addIndividualClassesN3(int counter) { + List classN3 = new ArrayList(); + if(classCount > 0) { + classN3.add(generateIndividualClassN3(counter)); + } + return classN3; + } + + private String generateIndividualClassN3(int counter) { + String dataGetterVar = getDataGetterVar(counter); + String n3 = dataGetterVar + " <" + DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS + "> "; + //Consider a multi-valued field - in this case single field with multiple values + n3 += getN3VarName(individualClassVarNameBase, counter); + /* + int i; + for(i = 0; i < classCount; i++) { + if(i != 0) { + n3+= ","; + } + n3 += getN3VarName(individualClassVarNameBase + counter, classCount); + }*/ + n3 += " ."; + return n3; + + } + public List retrieveN3Optional(int counter) { + return null; + } + + //These methods will return the literals and uris expected within the n3 + //and the counter is used to ensure they are numbered correctly + + public List retrieveLiteralsOnForm(int counter) { + //no literals, just the class group URI + List literalsOnForm = new ArrayList(); + return literalsOnForm; + + } + + + public List retrieveUrisOnForm(int counter) { + //get class group uris + List urisOnForm = super.retrieveUrisOnForm(counter); + //now get individual classes selected uri + //urisOnForm.addAll(getIndividualClassesVarNames(counter)); + //here again,consider multi-valued + urisOnForm.add(getVarName(individualClassVarNameBase, counter)); + return urisOnForm; + + } + + private List getIndividualClassesVarNames(int counter) { + List individualClassUris = new ArrayList(); + int i; + for(i = 0; i < classCount; i++) { + individualClassUris.add(getVarName(individualClassVarNameBase + counter, classCount)); + } + return individualClassUris; + + } + + public List retrieveFields(int counter) { + List fields = super.retrieveFields(counter); + fields.add(new FieldVTwo().setName(getVarName(individualClassVarNameBase, counter))); + //Add fields for each class selected + /* List classVarNames = getIndividualClassesVarNames(counter); + for(String v:classVarNames) { + fields.add(new FieldVTwo().setName(v)); + + }*/ + return fields; + } + + //These var names match the names of the elements within the json object returned with the info required for the data getter + + public List getLiteralVarNamesBase() { + return Arrays.asList(); + } + + //these are for the fields ON the form + public List getUriVarNamesBase() { + return Arrays.asList("classGroup", individualClassVarNameBase); + } + + +} + + diff --git a/webapp/web/js/jquery.fix.clone.js b/webapp/web/js/jquery.fix.clone.js new file mode 100644 index 000000000..b7011aaac --- /dev/null +++ b/webapp/web/js/jquery.fix.clone.js @@ -0,0 +1,26 @@ +// Textarea and select clone() bug workaround | Spencer Tipping +// Licensed under the terms of the MIT source code license + +// Motivation. +// jQuery's clone() method works in most cases, but it fails to copy the value of textareas and select elements. This patch replaces jQuery's clone() method with a wrapper that fills in the +// values after the fact. + +// An interesting error case submitted by Piotr PrzybyƂ: If two box itself rather than relying on jQuery's value-based val(). + +(function (original) { + jQuery.fn.clone = function () { + var result = original.apply(this, arguments), + my_textareas = this.find('textarea').add(this.filter('textarea')), + result_textareas = result.find('textarea').add(this.filter('textarea')), + my_selects = this.find('select').add(this.filter('select')), + result_selects = result.find('select').add(this.filter('select')); + + for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val()); + for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex; + + return result; + }; +}) (jQuery.fn.clone); + +// Generated by SDoc \ No newline at end of file diff --git a/webapp/web/js/menupage/pageManagementUtils.js b/webapp/web/js/menupage/pageManagementUtils.js index 79f567d8f..f4a71a096 100644 --- a/webapp/web/js/menupage/pageManagementUtils.js +++ b/webapp/web/js/menupage/pageManagementUtils.js @@ -102,12 +102,14 @@ var pageManagementUtils = { bindEventListeners:function(){ this.defaultTemplateRadio.click( function() { - pageManagementUtils.customTemplateRadio.addClass('hidden'); + pageManagementUtils.customTemplate.addClass('hidden'); + //Also clear custom template value so as not to submit it + pageManagementUtils.clearInputs(pageManagementUtils.customTemplate); }); this.customTemplateRadio.click( function() { - pageManagementUtils.defaultTemplateRadio.removeClass('hidden'); + pageManagementUtils.customTemplate.removeClass('hidden'); }); this.isMenuCheckbox.click( function() { @@ -398,17 +400,20 @@ var pageManagementUtils = { // Check/unckeck all classes for selection $('input:checkbox[name=allSelected]').click(function(){ if ( this.checked ) { - // if checked, select all the checkboxes - $('input:checkbox[name=classInClassGroup]').attr('checked','checked'); + // if checked, select all the checkboxes for this particular section + $(this).closest("ul").find('input:checkbox[name=classInClassGroup]').attr('checked','checked'); + //$('input:checkbox[name=classInClassGroup]').attr('checked','checked'); } else { // if not checked, deselect all the checkboxes - $('input:checkbox[name=classInClassGroup]').removeAttr('checked'); + $(this).closest("ul").find('input:checkbox[name=classInClassGroup]').removeAttr('checked'); + + // $('input:checkbox[name=classInClassGroup]').removeAttr('checked'); } }); $('input:checkbox[name=classInClassGroup]').click(function(){ - $('input:checkbox[name=allSelected]').removeAttr('checked'); + $(this).closest(ul).find('input:checkbox[name=allSelected]').removeAttr('checked'); }); }, //This is SPECIFIC to VIVO so should be moved there updateInternalClassMessage:function(classGroupName) { //User has changed content type diff --git a/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js b/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js index 50dfbfdbe..fa9e3cb31 100644 --- a/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js +++ b/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js @@ -10,8 +10,11 @@ var processIndividualsForClassesDataGetterContent = { var classGroup = pageContentSection.find("select[name='selectClassGroup']").val(); //query model should also be an input //Get classes selected - var classesSelected = pageContentSection.find("input[name='classInClassGroup']:checked").val(); - var returnObject = {classGroup:classGroup, classesSelected:classesSelected, dataGetterClass:this.dataGetterClass}; + var classesSelected = []; + pageContentSection.find("input[name='classInClassGroup']:checked").each(function(){ + classesSelected.push($(this).val()); + }); + var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass}; return returnObject; }