updates for page management

This commit is contained in:
hjkhjk54 2012-06-01 21:32:56 +00:00
parent 7da7c3da87
commit 918451f294
7 changed files with 246 additions and 26 deletions

View file

@ -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.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.ProcessDataGetterN3;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3Utils; 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.JSONObject;
import net.sf.json.JSONSerializer; import net.sf.json.JSONSerializer;
import net.sf.json.util.JSONUtils;
public class ManagePagePreprocessor extends public class ManagePagePreprocessor extends
BaseEditSubmissionPreprocessorVTwo { BaseEditSubmissionPreprocessorVTwo {
@ -83,7 +85,7 @@ public class ManagePagePreprocessor extends
int counter = 0; int counter = 0;
for(JSONObject jsonObject:pageContentUnitsJSON) { for(JSONObject jsonObject:pageContentUnitsJSON) {
String dataGetterClass = getDataGetterClass(jsonObject); String dataGetterClass = getDataGetterClass(jsonObject);
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass); ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject);
//Add n3 required //Add n3 required
addN3Required(pn, counter); addN3Required(pn, counter);
//Add N3 Optional as well //Add N3 Optional as well
@ -136,23 +138,52 @@ public class ManagePagePreprocessor extends
List<String> uriLabels = pn.getUriVarNamesBase(); List<String> uriLabels = pn.getUriVarNamesBase();
for(String literalLabel:literalLabels) { for(String literalLabel:literalLabels) {
//TODO: Deal with multiple submission values List<String> literalValues = new ArrayList<String>();
//This retrieves the value for this particular json object Object jsonValue = jsonObject.get(literalLabel);
String literalValue = jsonObject.getString(literalLabel); //Var names will depend on which data getter object this is on the page, so depends on counter
//Var names will depend on which data getter object this is on the page, so depends on counter
String submissionLiteralName = pn.getVarName(literalLabel, 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<String>) JSONSerializer.toJava(values);
}
//This adds literal, connecting the field with //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) { for(String uriLabel:uriLabels) {
//TODO: Deal with multiple submission values List<String> uriValues = new ArrayList<String>();
//This retrieves the value for this particular json object Object jsonValue = jsonObject.get(uriLabel);
String uriValue = jsonObject.getString(uriLabel); //Var names will depend on which data getter object this is on the page, so depends on counter
//Var names will depend on which data getter object this is on the page, so depends on counter
String submissionUriName = pn.getVarName(uriLabel, counter); String submissionUriName = pn.getVarName(uriLabel, counter);
//This adds literal, connecting the field with //if single value, then, add to values
submission.addLiteralToForm(editConfiguration, editConfiguration.getField(submissionUriName), submissionUriName, new String[]{uriValue}); 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<String>) 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 //this needs to be different

View file

@ -17,7 +17,7 @@ import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer; import net.sf.json.JSONSerializer;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract { 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(){ public ProcessClassGroupDataGetterN3(){

View file

@ -2,6 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
import java.lang.reflect.Constructor;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; 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.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. * 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<String, String> getDataGetterTypeToProcessorMap() { public static HashMap<String, String> getDataGetterTypeToProcessorMap() {
HashMap<String, String> map = new HashMap<String, String>(); HashMap<String, String> map = new HashMap<String, String>();
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.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; return map;
} }
public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass) { public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, JSONObject jsonObject) {
HashMap<String, String> map = getDataGetterTypeToProcessorMap(); HashMap<String, String> map = getDataGetterTypeToProcessorMap();
// //
if(map.containsKey(dataGetterClass)) { if(map.containsKey(dataGetterClass)) {
String processorClass = map.get(dataGetterClass); String processorClass = map.get(dataGetterClass);
try { try {
Class<?> clz = Class.forName(processorClass); ProcessDataGetterN3 pn = instantiateClass(processorClass, 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; return pn;
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in trying to get processor class for n3 for " + dataGetterClass, 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; 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;
}
} }

View file

@ -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<String> retrieveN3Required(int counter) {
List<String> classGroupN3 = super.retrieveN3Required(counter);
classGroupN3.addAll(this.addIndividualClassesN3(counter));
return classGroupN3;
}
private List<String> addIndividualClassesN3(int counter) {
List<String> classN3 = new ArrayList<String>();
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<String> 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<String> retrieveLiteralsOnForm(int counter) {
//no literals, just the class group URI
List<String> literalsOnForm = new ArrayList<String>();
return literalsOnForm;
}
public List<String> retrieveUrisOnForm(int counter) {
//get class group uris
List<String> 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<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);
fields.add(new FieldVTwo().setName(getVarName(individualClassVarNameBase, counter)));
//Add fields for each class selected
/* List<String> 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<String> getLiteralVarNamesBase() {
return Arrays.asList();
}
//these are for the fields ON the form
public List<String> getUriVarNamesBase() {
return Arrays.asList("classGroup", individualClassVarNameBase);
}
}

View file

@ -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 <select> options had the same value, the clone() method would select the wrong one in the cloned box. The fix, suggested by Piotr
// and implemented here, is to use the selectedIndex property on the <select> 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

View file

@ -102,12 +102,14 @@ var pageManagementUtils = {
bindEventListeners:function(){ bindEventListeners:function(){
this.defaultTemplateRadio.click( 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() { this.customTemplateRadio.click( function() {
pageManagementUtils.defaultTemplateRadio.removeClass('hidden'); pageManagementUtils.customTemplate.removeClass('hidden');
}); });
this.isMenuCheckbox.click( function() { this.isMenuCheckbox.click( function() {
@ -398,17 +400,20 @@ var pageManagementUtils = {
// Check/unckeck all classes for selection // Check/unckeck all classes for selection
$('input:checkbox[name=allSelected]').click(function(){ $('input:checkbox[name=allSelected]').click(function(){
if ( this.checked ) { if ( this.checked ) {
// if checked, select all the checkboxes // if checked, select all the checkboxes for this particular section
$('input:checkbox[name=classInClassGroup]').attr('checked','checked'); $(this).closest("ul").find('input:checkbox[name=classInClassGroup]').attr('checked','checked');
//$('input:checkbox[name=classInClassGroup]').attr('checked','checked');
} else { } else {
// if not checked, deselect all the checkboxes // 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=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 }, //This is SPECIFIC to VIVO so should be moved there
updateInternalClassMessage:function(classGroupName) { //User has changed content type updateInternalClassMessage:function(classGroupName) { //User has changed content type

View file

@ -10,8 +10,11 @@ var processIndividualsForClassesDataGetterContent = {
var classGroup = pageContentSection.find("select[name='selectClassGroup']").val(); var classGroup = pageContentSection.find("select[name='selectClassGroup']").val();
//query model should also be an input //query model should also be an input
//Get classes selected //Get classes selected
var classesSelected = pageContentSection.find("input[name='classInClassGroup']:checked").val(); var classesSelected = [];
var returnObject = {classGroup:classGroup, classesSelected:classesSelected, dataGetterClass:this.dataGetterClass}; pageContentSection.find("input[name='classInClassGroup']:checked").each(function(){
classesSelected.push($(this).val());
});
var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass};
return returnObject; return returnObject;
} }