page management related updates

This commit is contained in:
hjkhjk54 2012-06-15 22:14:09 +00:00
parent 7da1f47b62
commit f327e91a3c
12 changed files with 266 additions and 80 deletions

View file

@ -138,4 +138,26 @@ public class FieldVTwo {
public String toString(){ public String toString(){
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
} }
//Check that two fields are the same
//Not sure how to compare EditElement and FieldOptions
public boolean isEqualTo(FieldVTwo inputField) {
//Name required
boolean nameEqual = this.name.equals(inputField.getName());
//Validators initialized so can check
boolean validatorsEqual = this.validators.equals(inputField.getValidators());
//other fields optional and may be null
boolean rangeDatatypeEqual = ((this.rangeDatatypeUri == null && inputField.getRangeDatatypeUri() == null) ||
(this.rangeDatatypeUri != null && inputField.getRangeDatatypeUri() != null
&& this.rangeDatatypeUri.equals(inputField.getRangeDatatypeUri())));
boolean rangeLangEqual = ((this.rangeLang == null && inputField.getRangeLang() == null) ||
(this.rangeLang != null && inputField.getRangeLang() != null
&& this.rangeLang.equals(inputField.getRangeLang())));
return (nameEqual &&
validatorsEqual &&
rangeDatatypeEqual &&
rangeLangEqual);
}
} }

View file

@ -4,19 +4,19 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
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 net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.model.Literal; 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.BaseEditSubmissionPreprocessorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; 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.EditConfigurationVTwo;
@ -26,11 +26,6 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigu
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.JSONSerializer;
import net.sf.json.util.JSONUtils;
public class ManagePagePreprocessor extends public class ManagePagePreprocessor extends
BaseEditSubmissionPreprocessorVTwo { BaseEditSubmissionPreprocessorVTwo {
@ -103,6 +98,7 @@ public class ManagePagePreprocessor extends
//if submission already has value for this, then leave be //if submission already has value for this, then leave be
//otherwise replace with blank value sentinel //otherwise replace with blank value sentinel
boolean haslv = submission.hasLiteralValue(literalName);
if(!submission.hasLiteralValue(literalName)) { if(!submission.hasLiteralValue(literalName)) {
submission.addLiteralToForm(editConfiguration, submission.addLiteralToForm(editConfiguration,
editConfiguration.getField(literalName), editConfiguration.getField(literalName),
@ -114,9 +110,9 @@ public class ManagePagePreprocessor extends
for(String uriName: uriKeys) { for(String uriName: uriKeys) {
//these values should never be overwritten or deleted //these values should never be overwritten or deleted
if(uriName != "page" && uriName != "menuItem" && !uriName.startsWith("dataGetter")) { if(uriName != "page" && uriName != "menuItem" && !uriName.startsWith("dataGetter")) {
boolean hasuv = submission.hasUriValue(uriName);
if(!submission.hasUriValue(uriName)) { if(!submission.hasUriValue(uriName)) {
submission.addLiteralToForm(editConfiguration, submission.addUriToForm(editConfiguration,
editConfiguration.getField(uriName),
uriName, uriName,
(new String[] {EditConfigurationConstants.BLANK_SENTINEL})); (new String[] {EditConfigurationConstants.BLANK_SENTINEL}));
} }
@ -133,8 +129,11 @@ public class ManagePagePreprocessor extends
for(JSONObject jsonObject:pageContentUnitsJSON) { for(JSONObject jsonObject:pageContentUnitsJSON) {
String dataGetterClass = getDataGetterClass(jsonObject); String dataGetterClass = getDataGetterClass(jsonObject);
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject); ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject);
//Removing n3 required b/c retracts in edit case depend on both n3 required and n3 optional
//To not muddle up logic, we will just add ALL required and optional statements
//from data getters directly to N3 optional
//Add n3 required //Add n3 required
addN3Required(pn, counter); //addN3Required(pn, counter);
//Add N3 Optional as well //Add N3 Optional as well
addN3Optional(pn, counter); addN3Optional(pn, counter);
// Add URIs on Form and Add Literals On Form // Add URIs on Form and Add Literals On Form
@ -273,7 +272,22 @@ public class ManagePagePreprocessor extends
private void addFields(ProcessDataGetterN3 pn, int counter) { private void addFields(ProcessDataGetterN3 pn, int counter) {
List<FieldVTwo> fields = pn.retrieveFields(counter); List<FieldVTwo> fields = pn.retrieveFields(counter);
editConfiguration.addFields(fields); //Check if fields don't already exist in case of editing
Map<String, FieldVTwo> existingFields = editConfiguration.getFields();
for(FieldVTwo newField: fields) {
String newFieldName = newField.getName();
//if not already in list and about the same
if(existingFields.containsKey(newFieldName)) {
FieldVTwo existingField = existingFields.get(newFieldName);
if(existingField.isEqualTo(newField)) {
log.debug("This field already exists and so will not be added:" + newFieldName);
} else {
log.error("The field with the same name is different and will not be added as a different field exists which is different:" + newFieldName);
}
} else {
editConfiguration.addField(newField);
}
}
} }
@ -291,7 +305,9 @@ public class ManagePagePreprocessor extends
/* /*
* ?subject ?predicate ?conceptNode . * ?subject ?predicate ?conceptNode .
*/ */
//NOT Using this right now
//This will overwrite the original with the set of new n3 required //This will overwrite the original with the set of new n3 required
/*
private void addN3Required(ProcessDataGetterN3 pn, int counter) { private void addN3Required(ProcessDataGetterN3 pn, int counter) {
//Use the process utils to figure out what class required to retrieve the N3 required //Use the process utils to figure out what class required to retrieve the N3 required
List<String> requiredList = pn.retrieveN3Required(counter); List<String> requiredList = pn.retrieveN3Required(counter);
@ -300,7 +316,7 @@ public class ManagePagePreprocessor extends
if(requiredList != null) { if(requiredList != null) {
editConfiguration.addN3Required(requiredList); editConfiguration.addN3Required(requiredList);
} }
} }*/
private List<String> getPageToDataGetterN3( private List<String> getPageToDataGetterN3(
ProcessDataGetterN3 pn, int counter) { ProcessDataGetterN3 pn, int counter) {
String dataGetterVar = pn.getDataGetterVar(counter); String dataGetterVar = pn.getDataGetterVar(counter);
@ -313,32 +329,26 @@ public class ManagePagePreprocessor extends
//Add n3 optional //Add n3 optional
private void addN3Optional(ProcessDataGetterN3 pn, int counter) { private void addN3Optional(ProcessDataGetterN3 pn, int counter) {
List<String> addList = new ArrayList<String>();
//Get required list
List<String> requiredList = pn.retrieveN3Required(counter);
//Add connection between data getter and page
requiredList.addAll(getPageToDataGetterN3(pn, counter));
//get optional n3
List<String> optionalList = pn.retrieveN3Optional(counter); List<String> optionalList = pn.retrieveN3Optional(counter);
if(requiredList != null) {
addList.addAll(requiredList);
}
if(optionalList != null) { if(optionalList != null) {
editConfiguration.addN3Optional(optionalList); addList.addAll(optionalList);
} }
}
private String[] convertDelimitedStringToArray(String inputString) { editConfiguration.addN3Optional(addList);
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 //Each JSON Object will indicate the type of the data getter within it
private String getDataGetterClass(JSONObject jsonObject) { private String getDataGetterClass(JSONObject jsonObject) {
String javaURI = jsonObject.getString("dataGetterClass"); String javaURI = jsonObject.getString("dataGetterClass");

View file

@ -19,6 +19,7 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -28,7 +29,7 @@ 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.ClassGroupPageData"; private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData";
private static String classGroupVarBase = "classGroup"; public static String classGroupVarBase = "classGroup";
private Log log = LogFactory.getLog(ProcessClassGroupDataGetterN3.class); private Log log = LogFactory.getLog(ProcessClassGroupDataGetterN3.class);
public ProcessClassGroupDataGetterN3(){ public ProcessClassGroupDataGetterN3(){
@ -106,10 +107,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//TODO: Update //TODO: Update
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
//First, put dataGetterURI within scope as well //First, put dataGetterURI within scope as well
existingUriValues.put(this.getDataGetterVar(counter), new ArrayList<String>(Arrays.asList(dataGetterURI))); this.populateExistingDataGetterURI(dataGetterURI, counter);
//Sparql queries for values to be executed //Sparql queries for values to be executed
//And then placed in the correct place/literal or uri //And then placed in the correct place/literal or uri
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
Query query = QueryFactory.create(querystr); Query query = QueryFactory.create(querystr);
@ -117,11 +118,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
ResultSet results = qe.execSelect(); ResultSet results = qe.execSelect();
while( results.hasNext()){ while( results.hasNext()){
QuerySolution qs = results.nextSolution(); QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar"); Resource classGroupResource = qs.getResource("classGroup");
Literal htmlValueLiteral = qs.getLiteral("htmlValue");
//Put both literals in existing literals //Put both literals in existing literals
existingLiteralValues.put(this.getVarName("saveToVar", counter), existingUriValues.put(this.getVarName(classGroupVarBase, counter),
new ArrayList<Literal>(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); new ArrayList<String>(Arrays.asList(classGroupResource.getURI())));
} }
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
@ -132,17 +132,32 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue . //?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
protected String getExistingValuesSparqlQuery(String dataGetterURI) { protected String getExistingValuesClassGroup(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + String query = this.getSparqlPrefix() + "SELECT ?classGroup WHERE {" +
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + "<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" +
"<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" +
"}"; "}";
return query; return query;
} }
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
JSONObject jo = new JSONObject(); JSONObject jObject = new JSONObject();
return jo; jObject.element("dataGetterClass", classType);
String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null;
try{
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while( results.hasNext()){
QuerySolution qs = results.nextSolution();
Resource classGroupResource = qs.getResource("classGroup");
//Put both literals in existing literals
jObject.element(classGroupVarBase, classGroupResource.getURI());
}
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
} }
} }

View file

@ -14,6 +14,15 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer; import net.sf.json.JSONSerializer;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 { public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 {
@ -58,11 +67,19 @@ public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 {
protected Map<String, List<Literal>> existingLiteralValues = new HashMap<String, List<Literal>>(); protected Map<String, List<Literal>> existingLiteralValues = new HashMap<String, List<Literal>>();
protected Map<String, List<String>> existingUriValues = new HashMap<String, List<String>>(); protected Map<String, List<String>> existingUriValues = new HashMap<String, List<String>>();
public Map<String, List<Literal>> retrieveExistingLiteralValues() { public Map<String, List<Literal>> retrieveExistingLiteralValues() {
return existingLiteralValues; return existingLiteralValues;
} }
public Map<String, List<String>> retrieveExistingUriValues() { public Map<String, List<String>> retrieveExistingUriValues() {
return existingUriValues; return existingUriValues;
} }
//Data getter var needs to be included in uris in scope
public void populateExistingDataGetterURI(String dataGetterURI, int counter) {
existingUriValues.put(this.getVarName("dataGetter", counter), new ArrayList<String>(Arrays.asList(dataGetterURI)));
}
} }

View file

@ -88,8 +88,8 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
//Execute populate before retrieval //Execute populate before retrieval
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
//First, put dataGetterURI within scope as well //First, put dataGetterURI within scope as well
existingUriValues.put(this.getDataGetterVar(counter), new ArrayList<String>(Arrays.asList(dataGetterURI))); this.populateExistingDataGetterURI(dataGetterURI, counter);
//Sparql queries for values to be executed //Sparql queries for values to be executed
//And then placed in the correct place/literal or uri //And then placed in the correct place/literal or uri
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;

View file

@ -20,6 +20,7 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -150,23 +151,33 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
//First, put dataGetterURI within scope as well //First, put dataGetterURI within scope as well
existingUriValues.put(this.getDataGetterVar(counter), new ArrayList<String>(Arrays.asList(dataGetterURI))); this.populateExistingDataGetterURI(dataGetterURI, counter);
//Sparql queries for values to be executed //Sparql queries for values to be executed
//And then placed in the correct place/literal or uri //And then placed in the correct place/literal or uri
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesIndividualsForClasses(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
Query query = QueryFactory.create(querystr); Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel); qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect(); ResultSet results = qe.execSelect();
List<String> individualsForClasses = new ArrayList<String>();
while( results.hasNext()){ while( results.hasNext()){
QuerySolution qs = results.nextSolution(); QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar"); Resource classGroupResource = qs.getResource("classGroup");
Literal htmlValueLiteral = qs.getLiteral("htmlValue"); String classGroupVarName = this.getVarName(classGroupVarBase, counter);
//Put both literals in existing literals if(!existingUriValues.containsKey(classGroupVarName)) {
existingLiteralValues.put(this.getVarName("saveToVar", counter), //Put both literals in existing literals
new ArrayList<Literal>(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); existingUriValues.put(this.getVarName(classGroupVarBase, counter),
new ArrayList<String>(Arrays.asList(classGroupResource.getURI())));
}
Resource individualForClassResource = qs.getResource("individualForClass");
individualsForClasses.add(individualForClassResource.getURI());
//Put both literals in existing literals
} }
existingUriValues.put(this.getVarName(individualClassVarNameBase, counter),
new ArrayList<String>(individualsForClasses));
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
} }
@ -176,18 +187,45 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue . //?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
protected String getExistingValuesSparqlQuery(String dataGetterURI) { protected String getExistingValuesIndividualsForClasses(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + String query = this.getSparqlPrefix() + "SELECT ?classGroup ?individualForClass WHERE {" +
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + "<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" +
"<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + "<" + dataGetterURI + "> <" + DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS + "> ?individualForClass . \n" +
"}"; "}";
return query; return query;
} }
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
JSONObject jo = new JSONObject(); JSONObject jObject = new JSONObject();
return jo; jObject.element("dataGetterClass", classType);
String querystr = getExistingValuesIndividualsForClasses(dataGetterURI);
QueryExecution qe = null;
try{
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
JSONArray individualsForClasses = new JSONArray();
String classGroupURI = null;
while( results.hasNext()){
QuerySolution qs = results.nextSolution();
if(classGroupURI == null) {
Resource classGroupResource = qs.getResource("classGroup");
classGroupURI = classGroupResource.getURI();
}
Resource individualForClassResource = qs.getResource("individualForClass");
individualsForClasses.add(individualForClassResource.getURI());
//Put both literals in existing literals
}
jObject.element("classGroup", classGroupURI);
//this is a json array
jObject.element("classesSelectedInClassGroup", individualsForClasses);
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
} }
} }

View file

@ -19,6 +19,7 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -112,7 +113,7 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
//First, put dataGetterURI within scope as well //First, put dataGetterURI within scope as well
existingUriValues.put(this.getDataGetterVar(counter), new ArrayList<String>(Arrays.asList(dataGetterURI))); this.populateExistingDataGetterURI(dataGetterURI, counter);
//Sparql queries for values to be executed //Sparql queries for values to be executed
//And then placed in the correct place/literal or uri //And then placed in the correct place/literal or uri
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesSparqlQuery(dataGetterURI);
@ -124,10 +125,18 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
while( results.hasNext()){ while( results.hasNext()){
QuerySolution qs = results.nextSolution(); QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar"); Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Literal htmlValueLiteral = qs.getLiteral("htmlValue"); Literal queryLiteral = qs.getLiteral("query");
//Put both literals in existing literals Resource queryModelResource = qs.getResource("queryModel");
existingLiteralValues.put(this.getVarName("saveToVar", counter), existingLiteralValues.put(this.getVarName("saveToVar", counter),
new ArrayList<Literal>(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); new ArrayList<Literal>(Arrays.asList(saveToVarLiteral)));
existingLiteralValues.put(this.getVarName("query", counter),
new ArrayList<Literal>(Arrays.asList(queryLiteral)));
existingUriValues.put(this.getVarName("queryModel", counter),
new ArrayList<String>(Arrays.asList(queryModelResource.getURI())));
} }
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
@ -137,11 +146,14 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
} }
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
//?dataGetter a SparqlDataGetter ; display:saveToVar ?saveToVar; display:queryModel ?queryModel;
//display:query ?query ..
protected String getExistingValuesSparqlQuery(String dataGetterURI) { protected String getExistingValuesSparqlQuery(String dataGetterURI) {
String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?query ?queryModel WHERE {" +
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + "<" + dataGetterURI + "> display:query ?query . \n" +
"<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + "OPTIONAL {<" + dataGetterURI + "> display:saveToVar ?saveToVar .} \n" +
"OPTIONAL {<" + dataGetterURI + "> display:queryModel ?queryModel . }\n" +
"}"; "}";
return query; return query;
} }
@ -149,8 +161,33 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) {
JSONObject jo = new JSONObject(); JSONObject jObject = new JSONObject();
return jo; jObject.element("dataGetterClass", classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null;
try{
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while( results.hasNext()){
QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Literal queryLiteral = qs.getLiteral("query");
Resource queryModelResource = qs.getResource("queryModel");
jObject.element("saveToVar", saveToVarLiteral.getString());
jObject.element("query", queryLiteral.getString());
if(queryModelResource != null) {
jObject.element("queryModel", queryModelResource.getURI());
} else {
jObject.element("queryModel", "");
}
}
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
} }
} }

View file

@ -15,7 +15,19 @@ var processClassGroupDataGetterContent = {
//query model should also be an input, ensure class group URI is saved as URI and not string //query model should also be an input, ensure class group URI is saved as URI and not string
var returnObject = {classGroup:classGroup, dataGetterClass:this.dataGetterClass}; var returnObject = {classGroup:classGroup, dataGetterClass:this.dataGetterClass};
return returnObject; return returnObject;
},
//For an existing set of content where form is already set, fill in the values
populatePageContentSection:function(existingContentObject, pageContentSection) {
var classGroupValue = existingContentObject["classGroup"];
pageContentSection.find("select[name='selectClassGroup']").val(classGroupValue);
},
//For the label of the content section for editing, need to add additional value
retrieveAdditionalLabelText:function(existingContentObject) {
//Right now return empty but can hook this into a hashmap with labels and uris
//set up in browse class group
return "";
} }
} }

View file

@ -19,6 +19,24 @@ var processIndividualsForClassesDataGetterContent = {
}); });
var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass}; var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass};
return returnObject; return returnObject;
},
//For an existing set of content where form is already set, fill in the values
populatePageContentSection:function(existingContentObject, pageContentSection) {
var classGroupValue = existingContentObject["classGroup"];
var classesSelected = existingContenetObject["classesSelectedInClassGroup"];
var numberSelected = classesSelected.length;
var i;
for(i = 0; i < numberSelected; i++) {
var classSelected = classesSelected[i];
pageContentSection.find("input[name='classInClassGroup'][value='" + classSelected + "']").attr("checked", "checked");
}
pageContentSection.find("select[name='selectClassGroup']").val(classGroupValue);
},
//For the label of the content section for editing, need to add additional value
retrieveAdditionalLabelText:function(existingContentObject) {
//Right now return empty but can hook this into a hashmap with labels and uris
//set up in browse class group
return "";
} }
} }

View file

@ -17,6 +17,21 @@ var processSparqlDataGetterContent = {
//set query model to query model here - vitro:contentDisplayModel //set query model to query model here - vitro:contentDisplayModel
var returnObject = {saveToVar:variableValue, query:queryValue, dataGetterClass:this.dataGetterClass, queryModel:queryModel}; var returnObject = {saveToVar:variableValue, query:queryValue, dataGetterClass:this.dataGetterClass, queryModel:queryModel};
return returnObject; return returnObject;
},
//For an existing set of content where form is already set, fill in the values
populatePageContentSection:function(existingContentObject, pageContentSection) {
var saveToVarValue = existingContentObject["saveToVar"];
var queryValue = existingContentObject["query"];
var queryModelValue = existingContentObject["queryModel"];
//Now find and set value
pageContentSection.find("input[name='saveToVar']").val(saveToVarValue);
pageContentSection.find("textarea[name='query']").val(queryValue);
pageContentSection.find("input[name='queryModel']").val(queryModelValue);
},
//For the label of the content section for editing, need to add additional value
retrieveAdditionalLabelText:function(existingContentObject) {
var saveToVarValue = existingContentObject["saveToVar"];
return saveToVarValue;
} }

View file

@ -2,3 +2,4 @@
<#-- Scripts for class group browsing --> <#-- Scripts for class group browsing -->
${scripts.add('<script type="text/javascript" src="${urls.base}/js/menupage/processClassGroupDataGetterContent.js"></script>')} ${scripts.add('<script type="text/javascript" src="${urls.base}/js/menupage/processClassGroupDataGetterContent.js"></script>')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/menupage/processIndividualsForClassesDataGetterContent.js"></script>')} ${scripts.add('<script type="text/javascript" src="${urls.base}/js/menupage/processIndividualsForClassesDataGetterContent.js"></script>')}
<#--Setting up script with class group URIs and labels for editing purposes-->

View file

@ -16,7 +16,7 @@
<#--Existing Values For Editing condition--> <#--Existing Values For Editing condition-->
<#assign literalValues = editConfiguration.existingLiteralValues /> <#assign literalValues = editConfiguration.existingLiteralValues />
<#assign uriValues = editConfiguration.existingUriValues /> <#assign uriValues = editConfiguration.existingUriValues />
<#if menuAction == "Edit"> <#if menuAction = "Edit">
<#assign pageName = lvf.getFormFieldValue(editSubmission, editConfiguration, "pageName")/> <#assign pageName = lvf.getFormFieldValue(editSubmission, editConfiguration, "pageName")/>
<#assign prettyUrl = lvf.getFormFieldValue(editSubmission, editConfiguration, "prettyUrl")/> <#assign prettyUrl = lvf.getFormFieldValue(editSubmission, editConfiguration, "prettyUrl")/>
<#assign menuItem = lvf.getFormFieldValue(editSubmission, editConfiguration, "menuItem")/> <#assign menuItem = lvf.getFormFieldValue(editSubmission, editConfiguration, "menuItem")/>
@ -76,10 +76,10 @@
<input type="text" name="prettyUrl" value="${prettyUrl!''}" role="input" /> <input type="text" name="prettyUrl" value="${prettyUrl!''}" role="input" />
<p class="note">Must begin with a leading forward slash: / (e.g., /people)</p> <p class="note">Must begin with a leading forward slash: / (e.g., /people)</p>
<p style="margin-top:8px;margin-bottom:2px">Template<span class="requiredHint"> *</span></p> <p style="margin-top:8px;margin-bottom:2px">Template<span class="requiredHint"> *</span></p>
<input type="radio" class="default-template" name="selectedTemplate" value="default" <#if selectedTemplateType = "default">checked</#if> role="radio" /> <input type="radio" class="default-template" name="selectedTemplate" value="default" <#if selectedTemplateType = "default">checked="checked"</#if> role="radio" />
<label class="inline" for="default"> Default</label> <label class="inline" for="default"> Default</label>
<br /> <br />
<input type="radio" name="selectedTemplate" class="custom-template" value="custom" <#if selectedTemplateType = "custom">checked</#if> role="input" /> <input type="radio" name="selectedTemplate" class="custom-template" value="custom" <#if selectedTemplateType = "custom">checked="checked"</#if> role="input" />
<label class="inline" for="custom"> Custom template</label> <label class="inline" for="custom"> Custom template</label>
<section id="custom-template" <#if selectedTemplateType != 'custom'>class="hidden" </#if>role="region"> <section id="custom-template" <#if selectedTemplateType != 'custom'>class="hidden" </#if>role="region">
<input type="text" name="customTemplate" value="${customTemplate!''}" size="40" role="input" /><span class="requiredHint"> *</span> <input type="text" name="customTemplate" value="${customTemplate!''}" size="40" role="input" /><span class="requiredHint"> *</span>
@ -87,6 +87,7 @@
<p style="margin-top:10px;margin-bottom:0px"><input id="menuCheckbox" type="checkbox" name="menuCheckbox"> This is a menu page</p> <p style="margin-top:10px;margin-bottom:0px"><input id="menuCheckbox" type="checkbox" name="menuCheckbox"> This is a menu page</p>
<section id="menu" role="region" style="margin-top:10px"> <section id="menu" role="region" style="margin-top:10px">
<label for="default">Menu Item Name</label> <label for="default">Menu Item Name</label>
<input type="hidden" id="menuItem" name="menuItem" value="${menuItem!''}" />
<input type="text" id="menuLinkText" name="menuLinkText" value="${menuLinkText!''}" size="28" role="input" /> <input type="text" id="menuLinkText" name="menuLinkText" value="${menuLinkText!''}" size="28" role="input" />
<input type="text" id="menuPosition" name="menuPosition" value="${menuPosition!''}" /> <input type="text" id="menuPosition" name="menuPosition" value="${menuPosition!''}" />
<p class="note">If left blank, the page title will be used.</p> <p class="note">If left blank, the page title will be used.</p>