updates for page management and adding multiple data getters in page management

This commit is contained in:
hjkhjk54 2012-05-17 22:03:36 +00:00
parent b6f56756f0
commit bbd45d7851
10 changed files with 430 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -438,7 +438,14 @@ public class EditConfigurationVTwo {
public void setN3Required(String ... n3RequiredStrs){ public void setN3Required(String ... n3RequiredStrs){
this.n3Required = Arrays.asList( n3RequiredStrs ); this.n3Required = Arrays.asList( n3RequiredStrs );
} }
//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<String> n3Required) {
this.n3Required.addAll(n3Required);
}
public void addN3Required(String ... n3RequiredStrs) {
this.n3Required.addAll(Arrays.asList( n3RequiredStrs ));
}
/** return a copy of the value so that the configuration is not modified by external code. /** return a copy of the value so that the configuration is not modified by external code.
* @return * @return
*/ */
@ -454,6 +461,14 @@ public class EditConfigurationVTwo {
this.n3Optional = Arrays.asList( n3Strs ); this.n3Optional = Arrays.asList( n3Strs );
} }
public void addN3Optional(List<String> n3Optional) {
this.n3Optional.addAll(n3Optional);
}
public void addN3Optional(String ... n3Strs){
this.n3Optional.addAll(Arrays.asList( n3Strs ));
}
public Map<String,String> getNewResources() { public Map<String,String> getNewResources() {
return newResources; return newResources;
@ -509,6 +524,13 @@ public class EditConfigurationVTwo {
this.literalsOnForm = Arrays.asList( strs ); this.literalsOnForm = Arrays.asList( strs );
} }
public void addLiteralsOnForm(List<String> literalsOnForm) {
this.literalsOnForm.addAll(literalsOnForm);
}
public void addLiteralsOnForm(String ... strs){
this.literalsOnForm.addAll(Arrays.asList( strs ));
}
public Map<String, List<String>> getUrisInScope() { public Map<String, List<String>> getUrisInScope() {
return urisInScope; return urisInScope;

View file

@ -2,53 +2,22 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
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.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; 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.utils.dataGetter.DataGetterUtils; import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils; import edu.cornell.mannlib.vitro.webapp.utils.menuManagement.MenuManagementDataUtils;
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
/** /**
* Generates the form for adding and editing a page in the display model. * Generates the form for adding and editing a page in the display model.
@ -80,6 +49,11 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
//Add sparql queries //Add sparql queries
setSparqlQueries(conf); setSparqlQueries(conf);
// In scope
setUrisAndLiteralsInScope(conf, vreq);
// on Form
setUrisAndLiteralsOnForm(conf, vreq);
//Set the fields //Set the fields
setFields(conf); setFields(conf);
@ -89,6 +63,24 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
prepare(vreq, conf); prepare(vreq, conf);
return conf ; return conf ;
}
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
}
private void setUrisAndLiteralsInScope(EditConfigurationVTwo conf,
VitroRequest vreq) {
//URIs
conf.addUrisInScope(conf.getVarNameForSubject(),
Arrays.asList(new String[]{conf.getSubjectUri()}));
conf.addUrisInScope(conf.getVarNameForPredicate(),
Arrays.asList(new String[]{conf.getPredicateUri()}));
} }
private void setN3Optional(EditConfigurationVTwo conf) { private void setN3Optional(EditConfigurationVTwo conf) {

View file

@ -0,0 +1,207 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
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.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.preprocessors.utils.ProcessDataGetterN3;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3Utils;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
public class ManagePagePreprocessor extends
BaseEditSubmissionPreprocessorVTwo {
protected static final Log log = LogFactory
.getLog(ManagePagePreprocessor.class.getName());
private static MultiValueEditSubmission submission = null;
private static EditConfigurationVTwo editConfiguration = null;
private static Map<String, List<String>> transformedLiteralsFromForm = null;
private static Map<String, List<String>> urisFromForm = null;
private static List<String> pageContentUnits = null;//String submission from form
private static List<JSONObject> pageContentUnitsJSON = null;//converted to JSON objects that can be read
// String datatype
// Will be editing the edit configuration as well as edit submission here
public ManagePagePreprocessor(EditConfigurationVTwo editConfig) {
super(editConfig);
editConfiguration = editConfig;
}
public void preprocess(MultiValueEditSubmission inputSubmission) {
submission = inputSubmission;
// Get the input elements for concept node and concept label as well
// as vocab uri (which is based on thge
// For query parameters, check whether CUI
copySubmissionValues();
processDataGetters();
}
//Since we will change the uris and literals from form, we should make copies
//of the original values and store them, this will also make iterations
//and updates to the submission independent from accessing the values
private void copySubmissionValues() {
Map<String, List<Literal>> literalsFromForm = submission.getLiteralsFromForm();
transformedLiteralsFromForm = copyMap(EditConfigurationUtils.transformLiteralMap(literalsFromForm));
urisFromForm = copyMap(submission.getUrisFromForm());
pageContentUnits = transformedLiteralsFromForm.get("pageContentUnit");
}
private Map<String, List<String>> copyMap(
Map<String, List<String>> originalMap) {
Map<String, List<String>> copyMap = new HashMap<String, List<String>>();
copyMap.putAll(originalMap);
return copyMap;
}
private void processDataGetters() {
convertToJson();
int counter = 0;
for(JSONObject jsonObject:pageContentUnitsJSON) {
String dataGetterClass = getDataGetterClass(jsonObject);
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject);
//Add n3 required
addN3Required(pn, counter);
//Add N3 Optional as well
addN3Optional(pn, counter);
// Add URIs on Form and Add Literals On Form
addLiteralsAndUrisOnForm(pn, counter);
// Add fields
addFields(pn, counter);
//Add input values to submission
addInputsToSubmission(pn, counter, jsonObject);
counter++;
}
}
private void convertToJson() {
//Iterate through list of inputs
pageContentUnitsJSON = new ArrayList<JSONObject>();
for(String pageContentUnit: pageContentUnits) {
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( pageContentUnit );
pageContentUnitsJSON.add(jsonObject);
}
}
//This is where the actual values will be submitted as if they were separate input fields
//Each field name will correspond to the names of the fileds/uris on form/literals on form
//generated here
private void addInputsToSubmission(ProcessDataGetterN3 pn, int counter, JSONObject jsonObject) {
List<String> literalLabels = pn.getLiteralVarNamesBase();
List<String> uriLabels = pn.getUriVarNamesBase();
//this needs to be different
//Get the literals directly from the processor - which you can get based on counter
//Problem then is we know what the connection is - some way to put that logic within the processor itself?
//It already knows the json object
//--> Get field for this base label, with counter value - that you get from configuration
/*
while(jsonObject.keys().hasNext())
{
//Other than class, all other variables considered a submission value corresponding to field
String key = (String) jsonObject.keys().next();
if(key != "dataGetterClass") {
//not expecting multiple values, so will need to either make this array or
//think about this some more
//TODO: Consider multiple values here
Map<String, String[]> submissionValues = new HashMap<String, String[]>();
submissionValues.put(key, new String[]{jsonObject.getString(key)} );
if(literalLabels.contains(key)) {
submission.addLiteralToForm(editConfiguration.getField(key), field, var, valuesArray)
}
}
}
List<String> uris = pn.retrieveUrissOnForm(counter);
for(String l:literals) {
//json object should have
submissionValues.put(l, new String[]{jsonObject.getString(l)} );
}*/
}
private void addFields(ProcessDataGetterN3 pn, int counter) {
}
//original literals on form: label, uris on form: conceptNode and conceptSource
//This will overwrite the original values in the edit configuration
private void addLiteralsAndUrisOnForm(ProcessDataGetterN3 pn, int counter) {
}
// N3 being reproduced
/*
* ?subject ?predicate ?conceptNode .
*/
//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));
}
//Add n3 optional
private void addN3Optional(ProcessDataGetterN3 pn, int counter) {
editConfiguration.addN3Optional(pn.retrieveN3Optional(counter));
}
private String[] convertDelimitedStringToArray(String inputString) {
String[] inputArray = new String[1];
if (inputString.indexOf(",") != -1) {
inputArray = inputString.split(",");
} else {
inputArray[0] = inputString;
}
return inputArray;
}
private Object getFirstElement(List inputList) {
if(inputList == null || inputList.size() == 0)
return null;
return inputList.get(0);
}
//Each JSON Object will indicate the type of the data getter within it
private String getDataGetterClass(JSONObject jsonObject) {
return jsonObject.getString("dataGetterClass");
}
}

View file

@ -0,0 +1,23 @@
/* $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.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
//Returns the appropriate n3 based on data getter
public interface ProcessDataGetterN3 {
public List<String> retrieveN3Required(int counter);
public List<String> retrieveN3Optional(int counter);
public List<String >retrieveLiteralsOnForm(int counter);
public List<String> retrieveUrissOnForm(int counter);
public List<FieldVTwo> retrieveFields(int counter);
public List<String> getLiteralVarNamesBase();
public List<String> getUriVarNamesBase();
}

View file

@ -0,0 +1,51 @@
/* $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.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import net.sf.json.JSONObject;
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.RDFNode;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
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;
/*
* This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO.
*/
public class ProcessDataGetterN3Utils {
private static final Log log = LogFactory.getLog(ProcessDataGetterN3Utils.class);
public static HashMap<String, String> getDataGetterTypeToProcessorMap() {
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");
return map;
}
public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, JSONObject jsonObject) {
HashMap<String, String> 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);
return pn;
} catch(Exception ex) {
log.error("Exception occurred in trying to get processor class for n3 for " + dataGetterClass, ex);
return null;
}
}
return null;
}
}

View file

@ -0,0 +1,97 @@
/* $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.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.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 {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter";
private JSONObject jsonObject = null;
public ProcessSparqlDataGetterN3(JSONObject inputJsonObject) {
jsonObject = inputJsonObject;
}
//Pass in variable that represents the counter
//TODO: ensure correct model returned
public List<String> 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);
}
public List<String> retrieveN3Optional(int counter) {
return null;
}
private String getDataGetterVar(int counter) {
return "dataGetter" + counter;
}
private String getPrefixes() {
return "@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> . \n" +
"@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> . \n";
}
//Need to add method sfor returning the fields, literals on form, and all that
/*
* addLiteralsAndUrisOnForm(pn, counter);
// Add fields
addFields(pn, counter);
//Add input values to submission
addInputsToSubmission(pn, counter);
*/
public List<String> retrieveLiteralsOnForm(int counter) {
List<String> literalsOnForm = new ArrayList<String>();
literalsOnForm.add("saveToVar" + counter);
literalsOnForm.add("query" + counter);
return literalsOnForm;
}
public List<String> retrieveUrissOnForm(int counter) {
List<String> urisOnForm = new ArrayList<String>();
//We have no uris as far as I know.. well query Model is a uri
urisOnForm.add("queryModel" + counter);
return urisOnForm;
}
public List<FieldVTwo> retrieveFields(int counter) {
List<FieldVTwo> fields = new ArrayList<FieldVTwo>();
fields.add(new FieldVTwo().setName("queryModel" + counter));
fields.add(new FieldVTwo().setName("saveToVar" + counter));
fields.add(new FieldVTwo().setName("query" + counter));
return fields;
}
public List<String> getLiteralVarNamesBase() {
return Arrays.asList("savetoVar", "query");
}
public List<String> getUriVarNamesBase() {
return Arrays.asList("queryModel");
}
}

View file

@ -293,3 +293,5 @@ var pageManagementUtils = {
$(document).ready(function() { $(document).ready(function() {
pageManagementUtils.onLoad(); pageManagementUtils.onLoad();
}); });