updates for page management

This commit is contained in:
hjkhjk54 2012-06-18 21:15:22 +00:00
parent 491c4f6d9a
commit c338c9025b
10 changed files with 260 additions and 86 deletions

View file

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONArray;
@ -79,17 +80,20 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
setUrisAndLiteralsOnForm(conf, vreq);
//Set the fields
setFields(conf);
//Adding additional data, specifically edit mode
addFormSpecificData(conf, vreq);
//Add preprocessor
conf.addEditSubmissionPreprocessor(new ManagePagePreprocessor(conf));
//Prepare
//Prepare: add literals/uris in scope based on sparql queries
prepare(vreq, conf);
//This method specifically retrieves information for edit
populateExistingDataGetter(vreq, conf, session.getServletContext());
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
@ -198,15 +202,11 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
@Override
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
//setup the model selectors for query, write and display models on editConfig
//Double-check if this will even work with over-written model in the case of display model?
setupModelSelectorsFromVitroRequest(vreq, editConfig);
OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel");
if (editConfig.isParamUpdate()) {
//editConfig.prepareForObjPropUpdate(queryModel);
//Set up edit configuration with all the values required
//Retrieve existing values for page and menu item level
editConfig.prepareForParamUpdate(queryModel);
retrieveExistingDataGetterInfo(editConfig, queryModel);
}
else{
//if no subject uri, this is creating a new page
@ -214,17 +214,33 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
}
}
private void populateExistingDataGetter(VitroRequest vreq,
EditConfigurationVTwo editConfig,
ServletContext context) {
if (editConfig.isParamUpdate()) {
//setup the model selectors for query, write and display models on editConfig
setupModelSelectorsFromVitroRequest(vreq, editConfig);
OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel");
retrieveExistingDataGetterInfo(context, editConfig, queryModel);
}
}
//This method will get the data getters related to this page
//And retrieve the current information for each of those data getters
private void retrieveExistingDataGetterInfo(EditConfigurationVTwo editConfig, OntModel queryModel) {
private void retrieveExistingDataGetterInfo(ServletContext context,
EditConfigurationVTwo editConfig,
OntModel queryModel) {
String pageUri = editConfig.getSubjectUri();
executeExistingDataGettersInfo(editConfig, pageUri, queryModel);
executeExistingDataGettersInfo(context, editConfig, pageUri, queryModel);
}
private void executeExistingDataGettersInfo(EditConfigurationVTwo editConfig, String pageUri, OntModel queryModel) {
private void executeExistingDataGettersInfo(ServletContext servletContext,
EditConfigurationVTwo editConfig,
String pageUri,
OntModel queryModel) {
//Create json array to be set within form specific data
JSONArray jsonArray = new JSONArray();
String querystr = getExistingDataGettersQuery();
@ -246,7 +262,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
//json representation to be returned to template saved in json array
processExistingDataGetter(counter,
dg.getURI(),
dgClassName, editConfig, queryModel, jsonArray);
dgClassName, editConfig, queryModel, jsonArray, servletContext);
counter++;
}
@ -266,7 +282,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
}
private void processExistingDataGetter(int counter, String dataGetterURI, String dgClassName,
EditConfigurationVTwo editConfig, OntModel queryModel, JSONArray jsonArray) {
EditConfigurationVTwo editConfig, OntModel queryModel, JSONArray jsonArray, ServletContext context) {
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dgClassName, null);
//Add N3 Optional as well
@ -279,14 +295,18 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
addExistingDataGetterNewResources(editConfig, pn, counter);
//Add values in scope
addValuesInScope(editConfig, pn, counter, dataGetterURI, queryModel);
//create JSON object and return in form specific dadta
addJSONObjectToArray(dataGetterURI, pn, queryModel, jsonArray);
//Get data getter-specific form specific data should it exist
addDataGetterSpecificFormData(dataGetterURI, pn, queryModel, jsonArray, context);
}
//Takes data getter information, packs within JSON object to send back to the form
private void addJSONObjectToArray(String dataGetterURI, ProcessDataGetterN3 pn, OntModel queryModel, JSONArray jsonArray) {
JSONObject jo = pn.getExistingValuesJSON(dataGetterURI, queryModel);
//Any data that needs to be placed within form specific data
//including: (i) The JSON object representing the existing information to be returned to template
//Takes data getter information, packs within JSON object to send back to the form
private void addDataGetterSpecificFormData(String dataGetterURI, ProcessDataGetterN3 pn, OntModel queryModel, JSONArray jsonArray, ServletContext context) {
JSONObject jo = pn.getExistingValuesJSON(dataGetterURI, queryModel, context);
jsonArray.add(jo);
}

View file

@ -21,9 +21,15 @@ import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import javax.servlet.ServletContext;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
//Returns the appropriate n3 based on data getter
@ -139,9 +145,17 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
return query;
}
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject();
jObject.element("dataGetterClass", classType);
//Get class group
getExistingClassGroup(dataGetterURI, jObject, queryModel);
//Get classes within class group
getExistingClassesInClassGroup(context, dataGetterURI, jObject);
return jObject;
}
private void getExistingClassGroup(String dataGetterURI, JSONObject jObject, OntModel queryModel) {
String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null;
try{
@ -157,7 +171,41 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
}
//Assumes JSON Object received will have the class group resource URI within it
//TODO: Refactor to take advantage of existing code that uses OTHER JSON library
protected void getExistingClassesInClassGroup(ServletContext context, String dataGetterURI, JSONObject jObject) {
//Check for class group resource within json object
if(jObject.containsKey(classGroupVarBase)) {
String classGroupURI = jObject.getString(classGroupVarBase);
//Get classes for classGroupURI and include in
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
VClassGroup group = vcgc.getGroup(classGroupURI);
populateClassesInClassGroupJSON(jObject, group);
} else {
log.error("JSONObject does not have class group URI included. ");
}
}
//JSONObject will include results JSON object that will include classes JSON Arrya as well as
//class group information
protected void populateClassesInClassGroupJSON(JSONObject jObject, VClassGroup group) {
JSONArray classes = new JSONArray();
for( VClass vc : group){
JSONObject vcObj = new JSONObject();
vcObj.element("name", vc.getName());
vcObj.element("URI", vc.getURI());
classes.add(vcObj);
}
JSONObject results = new JSONObject();
results.element("classes", classes);
results.element("classGroupName", group.getPublicName());
results.element("classGroupUri", group.getURI());
jObject.element("results", results);
}
}

View file

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
import javax.servlet.ServletContext;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Literal;
@ -33,6 +34,6 @@ public interface ProcessDataGetterN3 {
public Map<String, List<Literal>> retrieveExistingLiteralValues();
public Map<String, List<String>> retrieveExistingUriValues();
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel);
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel);
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context);
}

View file

@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletContext;
import net.sf.json.JSONObject;
@ -128,7 +129,7 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
//Method to create a JSON object with existing values to return to form
//There may be a better way to do this without having to run the query twice
//TODO: Refactor code if required
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject();
jObject.element("dataGetterClass", classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI);

View file

@ -21,6 +21,7 @@ import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -196,9 +197,17 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
}
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject();
jObject.element("dataGetterClass", classType);
//Get selected class group and which classes were selected
getExistingClassGroupAndIndividuals(dataGetterURI, jObject, queryModel);
//Get all classes within the class group
super.getExistingClassesInClassGroup(context, dataGetterURI, jObject);
return jObject;
}
private void getExistingClassGroupAndIndividuals(String dataGetterURI, JSONObject jObject, OntModel queryModel) {
String querystr = getExistingValuesIndividualsForClasses(dataGetterURI);
QueryExecution qe = null;
try{
@ -225,7 +234,6 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
}
}

View file

@ -20,6 +20,7 @@ import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -160,7 +161,7 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject();
jObject.element("dataGetterClass", classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI);