From f327e91a3cbdf2a827e1b84291532162a0fad123 Mon Sep 17 00:00:00 2001 From: hjkhjk54 Date: Fri, 15 Jun 2012 22:14:09 +0000 Subject: [PATCH] page management related updates --- .../edit/n3editing/VTwo/fields/FieldVTwo.java | 22 ++++++ .../preprocessors/ManagePagePreprocessor.java | 76 +++++++++++-------- .../utils/ProcessClassGroupDataGetterN3.java | 41 ++++++---- .../utils/ProcessDataGetterAbstract.java | 27 +++++-- .../utils/ProcessFixedHTMLN3.java | 4 +- ...cessIndividualsForClassesDataGetterN3.java | 64 ++++++++++++---- .../utils/ProcessSparqlDataGetterN3.java | 57 +++++++++++--- .../processClassGroupDataGetterContent.js | 12 +++ ...sIndividualsForClassesDataGetterContent.js | 20 ++++- .../processSparqlDataGetterContent.js | 15 ++++ ...geManagement--browseClassGroupsScripts.ftl | 1 + .../freemarker/edit/forms/pageManagement.ftl | 7 +- 12 files changed, 266 insertions(+), 80 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/FieldVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/FieldVTwo.java index 48ef58668..fd538d53d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/FieldVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/FieldVTwo.java @@ -138,4 +138,26 @@ public class FieldVTwo { public String toString(){ 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); + + } } 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 f4fc7e1ae..51f4f100c 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 @@ -4,19 +4,19 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.List; 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.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.dao.DisplayVocabulary; 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; @@ -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.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 { @@ -103,6 +98,7 @@ public class ManagePagePreprocessor extends //if submission already has value for this, then leave be //otherwise replace with blank value sentinel + boolean haslv = submission.hasLiteralValue(literalName); if(!submission.hasLiteralValue(literalName)) { submission.addLiteralToForm(editConfiguration, editConfiguration.getField(literalName), @@ -114,9 +110,9 @@ public class ManagePagePreprocessor extends for(String uriName: uriKeys) { //these values should never be overwritten or deleted if(uriName != "page" && uriName != "menuItem" && !uriName.startsWith("dataGetter")) { + boolean hasuv = submission.hasUriValue(uriName); if(!submission.hasUriValue(uriName)) { - submission.addLiteralToForm(editConfiguration, - editConfiguration.getField(uriName), + submission.addUriToForm(editConfiguration, uriName, (new String[] {EditConfigurationConstants.BLANK_SENTINEL})); } @@ -133,8 +129,11 @@ public class ManagePagePreprocessor extends for(JSONObject jsonObject:pageContentUnitsJSON) { String dataGetterClass = getDataGetterClass(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 - addN3Required(pn, counter); + //addN3Required(pn, counter); //Add N3 Optional as well addN3Optional(pn, counter); // Add URIs on Form and Add Literals On Form @@ -273,7 +272,22 @@ public class ManagePagePreprocessor extends private void addFields(ProcessDataGetterN3 pn, int counter) { List fields = pn.retrieveFields(counter); - editConfiguration.addFields(fields); + //Check if fields don't already exist in case of editing + Map 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 . */ + //NOT Using this right now //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 List requiredList = pn.retrieveN3Required(counter); @@ -300,7 +316,7 @@ public class ManagePagePreprocessor extends if(requiredList != null) { editConfiguration.addN3Required(requiredList); } - } + }*/ private List getPageToDataGetterN3( ProcessDataGetterN3 pn, int counter) { String dataGetterVar = pn.getDataGetterVar(counter); @@ -313,32 +329,26 @@ public class ManagePagePreprocessor extends //Add n3 optional private void addN3Optional(ProcessDataGetterN3 pn, int counter) { + List addList = new ArrayList(); + //Get required list + List requiredList = pn.retrieveN3Required(counter); + //Add connection between data getter and page + requiredList.addAll(getPageToDataGetterN3(pn, counter)); + //get optional n3 List optionalList = pn.retrieveN3Optional(counter); + if(requiredList != null) { + addList.addAll(requiredList); + } + if(optionalList != null) { - editConfiguration.addN3Optional(optionalList); + addList.addAll(optionalList); } - } - - private String[] convertDelimitedStringToArray(String inputString) { - String[] inputArray = new String[1]; - if (inputString.indexOf(",") != -1) { - inputArray = inputString.split(","); - } else { - inputArray[0] = inputString; - } - return inputArray; + + editConfiguration.addN3Optional(addList); } - - - 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) { String javaURI = jsonObject.getString("dataGetterClass"); 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 704d89a44..2a0db5974 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 @@ -19,6 +19,7 @@ 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; +import com.hp.hpl.jena.rdf.model.Resource; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; 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 public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract { 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); public ProcessClassGroupDataGetterN3(){ @@ -106,10 +107,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract { //TODO: Update public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { //First, put dataGetterURI within scope as well - existingUriValues.put(this.getDataGetterVar(counter), new ArrayList(Arrays.asList(dataGetterURI))); + this.populateExistingDataGetterURI(dataGetterURI, counter); //Sparql queries for values to be executed //And then placed in the correct place/literal or uri - String querystr = getExistingValuesSparqlQuery(dataGetterURI); + String querystr = getExistingValuesClassGroup(dataGetterURI); QueryExecution qe = null; try{ Query query = QueryFactory.create(querystr); @@ -117,11 +118,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract { ResultSet results = qe.execSelect(); while( results.hasNext()){ QuerySolution qs = results.nextSolution(); - Literal saveToVarLiteral = qs.getLiteral("saveToVar"); - Literal htmlValueLiteral = qs.getLiteral("htmlValue"); + Resource classGroupResource = qs.getResource("classGroup"); //Put both literals in existing literals - existingLiteralValues.put(this.getVarName("saveToVar", counter), - new ArrayList(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); + existingUriValues.put(this.getVarName(classGroupVarBase, counter), + new ArrayList(Arrays.asList(classGroupResource.getURI()))); } } catch(Exception 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 . - protected String getExistingValuesSparqlQuery(String dataGetterURI) { - String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + - "<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + - "<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + + protected String getExistingValuesClassGroup(String dataGetterURI) { + String query = this.getSparqlPrefix() + "SELECT ?classGroup WHERE {" + + "<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" + "}"; return query; } public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { - JSONObject jo = new JSONObject(); - return jo; + JSONObject jObject = new JSONObject(); + 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; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java index b7ab0dbc6..0f9b4a0a1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java @@ -14,6 +14,15 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import net.sf.json.JSONObject; 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 public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 { @@ -58,12 +67,20 @@ public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 { protected Map> existingLiteralValues = new HashMap>(); protected Map> existingUriValues = new HashMap>(); public Map> retrieveExistingLiteralValues() { - return existingLiteralValues; - } - public Map> retrieveExistingUriValues() { - return existingUriValues; - } + return existingLiteralValues; + } + public Map> retrieveExistingUriValues() { + 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(Arrays.asList(dataGetterURI))); + } + + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessFixedHTMLN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessFixedHTMLN3.java index cad9cefec..e4ac768c6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessFixedHTMLN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessFixedHTMLN3.java @@ -88,8 +88,8 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract { //Execute populate before retrieval public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) { //First, put dataGetterURI within scope as well - existingUriValues.put(this.getDataGetterVar(counter), new ArrayList(Arrays.asList(dataGetterURI))); - //Sparql queries for values to be executed + this.populateExistingDataGetterURI(dataGetterURI, counter); + //Sparql queries for values to be executed //And then placed in the correct place/literal or uri String querystr = getExistingValuesSparqlQuery(dataGetterURI); QueryExecution qe = null; 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 index 521e7ba09..1ff854d22 100644 --- 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 @@ -20,6 +20,7 @@ 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; +import com.hp.hpl.jena.rdf.model.Resource; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; 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) { //First, put dataGetterURI within scope as well - existingUriValues.put(this.getDataGetterVar(counter), new ArrayList(Arrays.asList(dataGetterURI))); + this.populateExistingDataGetterURI(dataGetterURI, counter); //Sparql queries for values to be executed //And then placed in the correct place/literal or uri - String querystr = getExistingValuesSparqlQuery(dataGetterURI); + String querystr = getExistingValuesIndividualsForClasses(dataGetterURI); QueryExecution qe = null; try{ Query query = QueryFactory.create(querystr); qe = QueryExecutionFactory.create(query, queryModel); ResultSet results = qe.execSelect(); + List individualsForClasses = new ArrayList(); while( results.hasNext()){ QuerySolution qs = results.nextSolution(); - Literal saveToVarLiteral = qs.getLiteral("saveToVar"); - Literal htmlValueLiteral = qs.getLiteral("htmlValue"); - //Put both literals in existing literals - existingLiteralValues.put(this.getVarName("saveToVar", counter), - new ArrayList(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); + Resource classGroupResource = qs.getResource("classGroup"); + String classGroupVarName = this.getVarName(classGroupVarBase, counter); + if(!existingUriValues.containsKey(classGroupVarName)) { + //Put both literals in existing literals + existingUriValues.put(this.getVarName(classGroupVarBase, counter), + new ArrayList(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(individualsForClasses)); } catch(Exception 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 . - protected String getExistingValuesSparqlQuery(String dataGetterURI) { - String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + - "<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + - "<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + + protected String getExistingValuesIndividualsForClasses(String dataGetterURI) { + String query = this.getSparqlPrefix() + "SELECT ?classGroup ?individualForClass WHERE {" + + "<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" + + "<" + dataGetterURI + "> <" + DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS + "> ?individualForClass . \n" + "}"; return query; } public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { - JSONObject jo = new JSONObject(); - return jo; + JSONObject jObject = new JSONObject(); + 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; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java index 1ef4d1e1d..6bc8e05f3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSparqlDataGetterN3.java @@ -19,6 +19,7 @@ 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; +import com.hp.hpl.jena.rdf.model.Resource; 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) { //First, put dataGetterURI within scope as well - existingUriValues.put(this.getDataGetterVar(counter), new ArrayList(Arrays.asList(dataGetterURI))); + this.populateExistingDataGetterURI(dataGetterURI, counter); //Sparql queries for values to be executed //And then placed in the correct place/literal or uri String querystr = getExistingValuesSparqlQuery(dataGetterURI); @@ -124,10 +125,18 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract { while( results.hasNext()){ QuerySolution qs = results.nextSolution(); Literal saveToVarLiteral = qs.getLiteral("saveToVar"); - Literal htmlValueLiteral = qs.getLiteral("htmlValue"); - //Put both literals in existing literals + Literal queryLiteral = qs.getLiteral("query"); + Resource queryModelResource = qs.getResource("queryModel"); existingLiteralValues.put(this.getVarName("saveToVar", counter), - new ArrayList(Arrays.asList(saveToVarLiteral, htmlValueLiteral))); + new ArrayList(Arrays.asList(saveToVarLiteral))); + + existingLiteralValues.put(this.getVarName("query", counter), + new ArrayList(Arrays.asList(queryLiteral))); + + existingUriValues.put(this.getVarName("queryModel", counter), + new ArrayList(Arrays.asList(queryModelResource.getURI()))); + + } } catch(Exception ex) { log.error("Exception occurred in retrieving existing values with query " + querystr, ex); @@ -136,12 +145,15 @@ 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) { - String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + - "<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + - "<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + + String query = this.getSparqlPrefix() + "SELECT ?saveToVar ?query ?queryModel WHERE {" + + "<" + dataGetterURI + "> display:query ?query . \n" + + "OPTIONAL {<" + dataGetterURI + "> display:saveToVar ?saveToVar .} \n" + + "OPTIONAL {<" + dataGetterURI + "> display:queryModel ?queryModel . }\n" + "}"; return query; } @@ -149,8 +161,33 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract { public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { - JSONObject jo = new JSONObject(); - return jo; + JSONObject jObject = new JSONObject(); + 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; } } diff --git a/webapp/web/js/menupage/processClassGroupDataGetterContent.js b/webapp/web/js/menupage/processClassGroupDataGetterContent.js index 9462eedd0..5cdbdfc3a 100644 --- a/webapp/web/js/menupage/processClassGroupDataGetterContent.js +++ b/webapp/web/js/menupage/processClassGroupDataGetterContent.js @@ -15,7 +15,19 @@ var processClassGroupDataGetterContent = { //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}; 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 ""; } + } \ No newline at end of file diff --git a/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js b/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js index 290ca11b3..f37d1f034 100644 --- a/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js +++ b/webapp/web/js/menupage/processIndividualsForClassesDataGetterContent.js @@ -19,6 +19,24 @@ var processIndividualsForClassesDataGetterContent = { }); var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass}; 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 ""; + } } \ No newline at end of file diff --git a/webapp/web/js/menupage/processSparqlDataGetterContent.js b/webapp/web/js/menupage/processSparqlDataGetterContent.js index fb00769a6..851de0aa6 100644 --- a/webapp/web/js/menupage/processSparqlDataGetterContent.js +++ b/webapp/web/js/menupage/processSparqlDataGetterContent.js @@ -17,6 +17,21 @@ var processSparqlDataGetterContent = { //set query model to query model here - vitro:contentDisplayModel var returnObject = {saveToVar:variableValue, query:queryValue, dataGetterClass:this.dataGetterClass, queryModel:queryModel}; 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; } diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement--browseClassGroupsScripts.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement--browseClassGroupsScripts.ftl index 4f87fb4f4..558ac87d7 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement--browseClassGroupsScripts.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement--browseClassGroupsScripts.ftl @@ -2,3 +2,4 @@ <#-- Scripts for class group browsing --> ${scripts.add('')} ${scripts.add('')} +<#--Setting up script with class group URIs and labels for editing purposes--> \ No newline at end of file diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl index 7de2ab23a..840a96a3e 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl @@ -16,7 +16,7 @@ <#--Existing Values For Editing condition--> <#assign literalValues = editConfiguration.existingLiteralValues /> <#assign uriValues = editConfiguration.existingUriValues /> -<#if menuAction == "Edit"> +<#if menuAction = "Edit"> <#assign pageName = lvf.getFormFieldValue(editSubmission, editConfiguration, "pageName")/> <#assign prettyUrl = lvf.getFormFieldValue(editSubmission, editConfiguration, "prettyUrl")/> <#assign menuItem = lvf.getFormFieldValue(editSubmission, editConfiguration, "menuItem")/> @@ -76,10 +76,10 @@

Must begin with a leading forward slash: / (e.g., /people)

Template *

- checked role="radio" /> + checked="checked" role="radio" />
- checked role="input" /> + checked="checked" role="input" />
class="hidden" role="region"> * @@ -87,6 +87,7 @@

This is a menu page