From 00338b05d98e5e8c232cf3edf12c296b4370bb10 Mon Sep 17 00:00:00 2001 From: hjkhjk54 Date: Fri, 15 Jun 2012 22:14:29 +0000 Subject: [PATCH] page management related updates --- .../processInternalClassDataGetterContent.js | 41 +++++- .../ProcessInternalClassDataGetterN3.java | 128 +++++++++++++----- 2 files changed, 129 insertions(+), 40 deletions(-) diff --git a/productMods/js/menupage/processInternalClassDataGetterContent.js b/productMods/js/menupage/processInternalClassDataGetterContent.js index a6196b93..db6c7757 100644 --- a/productMods/js/menupage/processInternalClassDataGetterContent.js +++ b/productMods/js/menupage/processInternalClassDataGetterContent.js @@ -8,6 +8,8 @@ var processInternalClassDataGetterContent = { }, //Do we need a separate content type for each of the others? processPageContentSection:function(pageContentSection) { + //get class group + var classGroup = pageContentSection.find("select[name='selectClassGroup']").val(); //Get classes selected var classesSelected = []; pageContentSection.find("input[name='classInClassGroup']:checked").each(function(){ @@ -15,16 +17,45 @@ var processInternalClassDataGetterContent = { classesSelected.push($(this).val()); }); //If internal class selected, include here - var isInternal=false; + var isInternal="false"; //if this checkbox is checked, then isInternal should be true pageContentSection.find("input[name='display-internalClass']:checked").each(function() { - isInternal=true; + isInternal="true"; }); - //Not returning class group although could if need be.. - var returnObject = { classesSelectedInClassGroup:classesSelected, + //JSON Object to be returned + var returnObject = { classGroup: classGroup, + classesSelectedInClassGroup:classesSelected, isInternal:isInternal, 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 = existingContentObject["classesSelectedInClassGroup"]; + var isInternal = existingContentObject["isInternal"]; + //Set class group + pageContentSection.find("select[name='selectClassGroup']").val(classGroupValue); + //Set classes selected within class group + //TODO: Add magic for "all" if all classes selected + 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"); + } + //Also internal class needs to be selected + if(isInternal == "true") { + pageContentSection.find("input[name='display-internalClass']").attr("checked", "checked"); + } + //Since this is populating content from the template, no need to "uncheck" anything + + }, + //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/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java index 105caee7..646eecfc 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessInternalClassDataGetterN3.java @@ -20,6 +20,8 @@ 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 com.hp.hpl.jena.rdf.model.ResourceFactory; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; @@ -39,16 +41,17 @@ public class ProcessInternalClassDataGetterN3 extends ProcessIndividualsForClas } //Pass in variable that represents the counter - - //Original menu managemenet didn't include the top level class group as type for internal classes + //Saving both type and class group here //That can be included here if need be, but for now just adding the type alone public List retrieveN3Required(int counter) { + return super.retrieveN3Required(counter); + /* List requiredN3 = new ArrayList(); String partialN3 = this.getN3ForTypePartial(counter) + "."; requiredN3.add(getPrefixes() + partialN3); requiredN3.addAll(this.addIndividualClassesN3(counter)); return requiredN3; - + */ } @@ -81,8 +84,7 @@ public class ProcessInternalClassDataGetterN3 extends ProcessIndividualsForClas } //URIs on form are same as individuals for class group so no need to reimplement - - + //i.e. class groups and individuals selected within class group public List retrieveFields(int counter) { List fields = super.retrieveFields(counter); @@ -97,46 +99,58 @@ public class ProcessInternalClassDataGetterN3 extends ProcessIndividualsForClas return Arrays.asList(internalClassVarNameBase); } - //these are for the fields ON the form - public List getUriVarNamesBase() { - return Arrays.asList(individualClassVarNameBase); - } + //get URI Var Names base is same as ProcessIndividualsForClassGroup: classGroup and individualClassVarNameBase @Override public String getClassType() { return classType; } - - - public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { - JSONObject jo = new JSONObject(); - return jo; - } - - //Existing values - //TODO: Correct - //How to override methods in here and access elements required? - //Unclear? - /* - @Override + 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))); + //((ProcessDataGetterAbstract)this).populateExistingDataGetterURI(dataGetterURI, counter); + 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 = getExistingValuesInternalClass(dataGetterURI); QueryExecution qe = null; + Literal internalClassLiteral = null; try{ Query query = QueryFactory.create(querystr); qe = QueryExecutionFactory.create(query, queryModel); ResultSet results = qe.execSelect(); + String classGroupURI = null; + 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))); + //Class group + Resource classGroupResource = qs.getResource("classGroup"); + String classGroupVarName = this.getVarName(classGroupVarBase, counter); + if(classGroupURI == null) { + //Put both literals in existing literals + existingUriValues.put(this.getVarName(classGroupVarBase, counter), + new ArrayList(Arrays.asList(classGroupResource.getURI()))); + } + //Individuals For classes + Resource individualForClassResource = qs.getResource("individualForClass"); + individualsForClasses.add(individualForClassResource.getURI()); + //If internal class value is present and we have not already saved it in a previous result iteration + if(qs.get("internalClass") != null && internalClassLiteral == null) { + + internalClassLiteral= qs.getLiteral("internalClass"); + existingLiteralValues.put(this.getVarName("internalClass", counter), + new ArrayList(Arrays.asList(internalClassLiteral))); + } + } + //Put array of individuals for classes within + existingUriValues.put(this.getVarName(individualClassVarNameBase, counter), + new ArrayList(individualsForClasses)); + //Final check, in case no internal class flag was returned, set to false + if(internalClassLiteral == null) { + existingLiteralValues.put(this.getVarName("internalClass", counter), + new ArrayList( + Arrays.asList(ResourceFactory.createPlainLiteral("false")) + )); } } catch(Exception ex) { log.error("Exception occurred in retrieving existing values with query " + querystr, ex); @@ -147,16 +161,60 @@ public class ProcessInternalClassDataGetterN3 extends ProcessIndividualsForClas //?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue . - @Override - protected String getExistingValuesSparqlQuery(String dataGetterURI) { - String query = super.getSparqlPrefix() + "SELECT ?saveToVar ?htmlValue WHERE {" + - "<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" + - "<" + dataGetterURI + "> display:htmlValue ?htmlValue . \n" + + protected String getExistingValuesInternalClass(String dataGetterURI) { + String query = this.getSparqlPrefix() + "SELECT ?classGroup ?individualForClass ?internalClass WHERE {" + + "<" + dataGetterURI + "> <" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup . \n" + + "<" + dataGetterURI + "> <" + DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS + "> ?individualForClass . \n" + + "OPTIONAL {<" + dataGetterURI + "> <" + DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL + "> ?internaClass .} \n" + "}"; return query; } -*/ + + public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel) { + JSONObject jObject = new JSONObject(); + jObject.element("dataGetterClass", classType); + String querystr = getExistingValuesInternalClass(dataGetterURI); + QueryExecution qe = null; + Literal internalClassLiteral = 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(); + } + //individuals for classes + Resource individualForClassResource = qs.getResource("individualForClass"); + individualsForClasses.add(individualForClassResource.getURI()); + //Put both literals in existing literals + //If internal class value is present and we have not already saved it in a previous result iteration + if(qs.get("internalClass") != null && internalClassLiteral == null) { + internalClassLiteral= qs.getLiteral("internalClass"); + } + } + + + jObject.element("classGroup", classGroupURI); + //this is a json array + jObject.element("individualsForClasses", individualsForClasses); + //Internal class - if null then add false otherwise use the value + if(internalClassLiteral != null) { + jObject.element("internalClass", internalClassLiteral.getString()); + } else { + jObject.element("internalClass", "false"); + } + } catch(Exception ex) { + log.error("Exception occurred in retrieving existing values with query " + querystr, ex); + } + return jObject; + } + }