adding solr data getter and some other changes
This commit is contained in:
parent
30ca552848
commit
29f41f61c7
14 changed files with 480 additions and 17 deletions
|
@ -0,0 +1,59 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONObject;
|
||||
|
||||
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.VClassGroupsForRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
|
||||
/**
|
||||
*This class will get all the vclasses in the system.
|
||||
*/
|
||||
public class GetAllVClasses extends JsonObjectProducer {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(GetAllVClasses.class);
|
||||
|
||||
public GetAllVClasses(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject process() throws Exception {
|
||||
JSONObject map = new JSONObject();
|
||||
//Get all VClassGroups
|
||||
List<VClass> vclasses = new ArrayList<VClass>();
|
||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
||||
List<VClassGroup> groups = vcgc.getGroups();
|
||||
for(VClassGroup vcg: groups) {
|
||||
for( VClass vc : vcg){
|
||||
vclasses.add(vc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Sort vclass by name
|
||||
Collections.sort(vclasses);
|
||||
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vclasses.size());
|
||||
|
||||
for(VClass vc: vclasses) {
|
||||
JSONObject vcObj = new JSONObject();
|
||||
vcObj.put("name", vc.getName());
|
||||
vcObj.put("URI", vc.getURI());
|
||||
classes.add(vcObj);
|
||||
}
|
||||
map.put("classes", classes);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -83,6 +83,8 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
|
||||
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
|
||||
new GetRandomSolrIndividualsByVClass(vreq).process(resp);
|
||||
} else if( vreq.getParameter("getAllVClasses") != null ){
|
||||
new GetAllVClasses(vreq).process(resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,8 +104,10 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
|||
// funny business because it needs to be able to retrieve anonymous union
|
||||
// classes by their "pseudo-bnode URIs".
|
||||
// Someday we'll need to figure out a different way of doing this.
|
||||
WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
||||
vreq.getSession().getServletContext()).getWebappDaoFactory();
|
||||
//WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
||||
// vreq.getSession().getServletContext()).getWebappDaoFactory();
|
||||
WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory();
|
||||
|
||||
List<VClass> types = new ArrayList<VClass>();
|
||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -30,10 +31,14 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
|||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
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.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
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.fields.FieldVTwo;
|
||||
|
@ -521,6 +526,8 @@ private String getExistingIsSelfContainedTemplateQuery() {
|
|||
MenuManagementDataUtils.includeRequiredSystemData(vreq.getSession().getServletContext(), data);
|
||||
data.put("classGroup", new ArrayList<String>());
|
||||
data.put("classGroups", DataGetterUtils.getClassGroups(vreq));
|
||||
//for solr individuals data get getter
|
||||
data.put("classes", this.getAllVClasses(vreq));
|
||||
data.put("availablePermissions", this.getAvailablePermissions(vreq));
|
||||
data.put("availablePermissionOrderedList", this.getAvailablePermissonsOrderedURIs());
|
||||
}
|
||||
|
@ -664,4 +671,33 @@ private String getExistingIsSelfContainedTemplateQuery() {
|
|||
return query;
|
||||
}
|
||||
|
||||
//Get all vclasses for the list of vclasses for solr
|
||||
//Originally considered using an ajax request to get the vclasses list which is fine for adding a new content type
|
||||
//but for an existing solr content type, would need to make yet another ajax request which seems too much
|
||||
private List<HashMap<String, String>> getAllVClasses(VitroRequest vreq) {
|
||||
List<VClass> vclasses = new ArrayList<VClass>();
|
||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
||||
List<VClassGroup> groups = vcgc.getGroups();
|
||||
for(VClassGroup vcg: groups) {
|
||||
for( VClass vc : vcg){
|
||||
vclasses.add(vc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Sort vclass by name
|
||||
Collections.sort(vclasses);
|
||||
ArrayList<HashMap<String, String>> classes = new ArrayList<HashMap<String, String>>(vclasses.size());
|
||||
|
||||
|
||||
for(VClass vc: vclasses) {
|
||||
HashMap<String, String> vcObj = new HashMap<String, String>();
|
||||
vcObj.put("name", vc.getName());
|
||||
vcObj.put("URI", vc.getURI());
|
||||
classes.add(vcObj);
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public class ProcessDataGetterN3Map {
|
|||
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessClassGroupDataGetterN3");
|
||||
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessIndividualsForClassesDataGetterN3");
|
||||
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessFixedHTMLN3");
|
||||
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSolrIndividualsDataGetterN3");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,179 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.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;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
//Returns the appropriate n3 based on data getter
|
||||
public class ProcessSolrIndividualsDataGetterN3 extends ProcessDataGetterAbstract {
|
||||
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter";
|
||||
private Log log = LogFactory.getLog(ProcessFixedHTMLN3.class);
|
||||
|
||||
public ProcessSolrIndividualsDataGetterN3(){
|
||||
|
||||
}
|
||||
//Pass in variable that represents the counter
|
||||
|
||||
//TODO: ensure correct model returned
|
||||
//We shouldn't use the ACTUAL values here but generate the n3 required
|
||||
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
|
||||
public List<String> retrieveN3Required(int counter) {
|
||||
String dataGetterVar = getDataGetterVar(counter);
|
||||
//UPDATE: Using variable for class type
|
||||
String classTypeVar = getN3VarName(classTypeVarBase, counter);
|
||||
String n3 = dataGetterVar + " a " + classTypeVar + "; \n" +
|
||||
"display:saveToVar " + getN3VarName("saveToVar", counter) + "; \n" +
|
||||
"display:hasVClassId " + getN3VarName("vclassUri", counter) + " .";
|
||||
List<String> requiredList = new ArrayList<String>();
|
||||
requiredList.add(getPrefixes() + n3);
|
||||
return requiredList;
|
||||
|
||||
}
|
||||
public List<String> retrieveN3Optional(int counter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<String> retrieveLiteralsOnForm(int counter) {
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
literalsOnForm.add(getVarName("saveToVar",counter));
|
||||
return literalsOnForm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<String> retrieveUrisOnForm(int counter) {
|
||||
List<String> urisOnForm = new ArrayList<String>();
|
||||
//UPDATE: adding class type as uri on form
|
||||
urisOnForm.add(getVarName("vclassUri", counter));
|
||||
|
||||
urisOnForm.add(getVarName(classTypeVarBase, counter));
|
||||
return urisOnForm;
|
||||
|
||||
}
|
||||
|
||||
public List<FieldVTwo> retrieveFields(int counter) {
|
||||
List<FieldVTwo> fields = new ArrayList<FieldVTwo>();
|
||||
|
||||
//fields.add(new FieldVTwo().setName(getVarName("dataGetter", counter)));
|
||||
fields.add(new FieldVTwo().setName(getVarName("saveToVar", counter)));
|
||||
fields.add(new FieldVTwo().setName(getVarName("vclassUri", counter)));
|
||||
//UPDATE: adding class type to the uris on the form
|
||||
fields.add(new FieldVTwo().setName(getVarName(classTypeVarBase, counter)));
|
||||
return fields;
|
||||
}
|
||||
|
||||
public List<String> getLiteralVarNamesBase() {
|
||||
return Arrays.asList("saveToVar");
|
||||
}
|
||||
|
||||
//these are for the fields ON the form
|
||||
public List<String> getUriVarNamesBase() {
|
||||
return Arrays.asList(classTypeVarBase, "vclassUri");
|
||||
}
|
||||
|
||||
//For Existing Values in case of editing
|
||||
|
||||
//Execute populate before retrieval
|
||||
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
|
||||
//First, put dataGetterURI within scope as well
|
||||
this.populateExistingDataGetterURI(dataGetterURI, counter);
|
||||
//Put in type
|
||||
this.populateExistingClassType(this.getClassType(), 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;
|
||||
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");
|
||||
Resource vclassUriResource = qs.getResource("vclassUri");
|
||||
//Put both literals in existing literals
|
||||
existingLiteralValues.put(this.getVarName("saveToVar", counter),
|
||||
new ArrayList<Literal>(Arrays.asList(saveToVarLiteral)));
|
||||
existingUriValues.put(this.getVarName("vclassUri", counter),
|
||||
new ArrayList<String>(Arrays.asList(vclassUriResource.getURI())));
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
|
||||
protected String getExistingValuesSparqlQuery(String dataGetterURI) {
|
||||
String query = this.getSparqlPrefix() + " SELECT ?saveToVar ?vclassUri WHERE {" +
|
||||
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" +
|
||||
"<" + dataGetterURI + "> display:hasVClassId ?vclassUri . \n" +
|
||||
"}";
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
//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, ServletContext context) {
|
||||
JSONObject jObject = new JSONObject();
|
||||
jObject.element("dataGetterClass", classType);
|
||||
jObject.element(classTypeVarBase, 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");
|
||||
Resource vclassUriResource = qs.getResource("vclassUri");
|
||||
String vclassUriString = vclassUriResource.getURI();
|
||||
jObject.element("saveToVar", saveToVarLiteral.getString());
|
||||
//TODO: Handle single and double quotes within string and escape properlyu
|
||||
jObject.element("vclassUri", vclassUriString);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
|
||||
}
|
||||
return jObject;
|
||||
|
||||
}
|
||||
|
||||
//Escape single and double quotes for html string to be returned to form
|
||||
public String replaceQuotes(String inputStr) {
|
||||
return inputStr.replaceAll("\'", "'").replaceAll("\"", """);
|
||||
|
||||
}
|
||||
|
||||
//This class can be extended so returning type here
|
||||
public String getClassType() {
|
||||
return classType;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -605,7 +605,8 @@ page_text = page text
|
|||
|
||||
sparql_query_results = Sparql Query Results
|
||||
no_results_returned = No results were returned.
|
||||
|
||||
solr_individual_results = Solr Class Individuals
|
||||
select_vclass_uri = Select VClass
|
||||
#
|
||||
# manage proxies templates ( /templates/freemarker/body/manageproxies )
|
||||
#
|
||||
|
@ -849,9 +850,9 @@ delete = delete
|
|||
map_processor_error = An error has occurred and the map of processors for this content is missing. Please contact the administrator
|
||||
code_processing_error = An error has occurred and the code for processing this content is missing a component. Please contact the administrator.
|
||||
|
||||
supply_class_group = You must supply a class group
|
||||
select_classes_to_display = You must select the classes to display
|
||||
|
||||
supply_class_group = You must supply a class group.
|
||||
select_classes_to_display = You must select the classes to display.
|
||||
select_class_for_solr = You must select a class to display its individuals.
|
||||
supply_variable_name = You must supply a variable to save HTML content.
|
||||
apostrophe_not_allowed = The variable name should not have an apostrophe.
|
||||
double_quote_note_allowed = The variable name should not have a double quote.
|
||||
|
|
|
@ -104,6 +104,7 @@ var pageManagementUtils = {
|
|||
this.classGroupSection = $("section#browseClassGroup");
|
||||
this.sparqlQuerySection = $("section#sparqlQuery");
|
||||
this.fixedHTMLSection = $("section#fixedHtml");
|
||||
this.solrIndividualsSection = $("section#solrIndividuals");
|
||||
//From original menu management edit
|
||||
this.defaultTemplateRadio = $('input.default-template');
|
||||
this.customTemplateRadio = $('input.custom-template');
|
||||
|
@ -117,6 +118,7 @@ var pageManagementUtils = {
|
|||
this.classesForClassGroup = $('section#classesInSelectedGroup');
|
||||
this.selectedGroupForPage = $('#selectedContentTypeValue');
|
||||
this.allClassesSelectedCheckbox = $('#allSelected');
|
||||
|
||||
this.displayInternalMessage = $('#internal-class label em');
|
||||
this.pageContentSubmissionInputs = $("#pageContentSubmissionInputs");
|
||||
this.headerBar = $("section#headerBar");
|
||||
|
@ -131,6 +133,8 @@ var pageManagementUtils = {
|
|||
this.rightSideDiv = $("div#rightSide");
|
||||
//contentDivs container where content added/existing placed
|
||||
this.savedContentDivs = $("section#contentDivs");
|
||||
//for solr individuals data getter
|
||||
this.solrAllClassesDropdown = $("select#vclassUri");
|
||||
},
|
||||
initDisplay: function(){
|
||||
//right side components
|
||||
|
@ -143,6 +147,7 @@ var pageManagementUtils = {
|
|||
this.classGroupSection.hide();
|
||||
this.sparqlQuerySection.hide();
|
||||
this.fixedHTMLSection.hide();
|
||||
this.solrIndividualsSection.hide();
|
||||
this.classesForClassGroup.addClass('hidden');
|
||||
//left side components
|
||||
//These depend on whether or not this is an existing item or not
|
||||
|
@ -155,8 +160,44 @@ var pageManagementUtils = {
|
|||
this.menuSection.hide();
|
||||
}
|
||||
}
|
||||
|
||||
//populates the dropdown of classes for the solr individuals template
|
||||
//dropdown now populated in template/from form specific data instead of ajax request
|
||||
//this.populateClassForSolrDropdown();
|
||||
},
|
||||
//this method can be utilized if using an ajax request to get the vclasses
|
||||
/*
|
||||
//for solr individuals - remember this populates the template class dropdown
|
||||
populateClassForSolrDropdown:function() {
|
||||
|
||||
//Run ajax query
|
||||
var url = "dataservice?getAllVClasses=1";
|
||||
|
||||
//Make ajax call to retrieve vclasses
|
||||
$.getJSON(url, function(results) {
|
||||
//Moved the function to processClassGroupDataGetterContent
|
||||
//Should probably remove this entire method and copy there
|
||||
pageManagementUtils.displayAllClassesForSolrDropdown(results);
|
||||
});
|
||||
},
|
||||
displayAllClassesForSolrDropdown:function(results) {
|
||||
if ( results.classes.length == 0 ) {
|
||||
|
||||
} else {
|
||||
var appendHtml = "";
|
||||
$.each(results.classes, function(i, item) {
|
||||
var thisClass = results.classes[i];
|
||||
var thisClassName = thisClass.name;
|
||||
//Create options for the dropdown
|
||||
appendHtml += "<option value='" + thisClass.URI + "'>" + thisClassName + "</option>";
|
||||
});
|
||||
|
||||
//if there are options to add
|
||||
if(appendHtml != "") {
|
||||
pageManagementUtils.solrAllClassesDropdown.html(appendHtml);
|
||||
}
|
||||
|
||||
}
|
||||
},*/
|
||||
bindEventListeners:function(){
|
||||
|
||||
this.defaultTemplateRadio.click( function() {
|
||||
|
@ -206,10 +247,13 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.checkSelfContainedRadio();
|
||||
});
|
||||
//replacing with menu management edit version which is extended with some of the logic below
|
||||
//This is technically content specific and should be moved into the individual processor classes somehow
|
||||
this.selectClassGroupDropdown.change(function() {
|
||||
pageManagementUtils.chooseClassGroup();
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.contentTypeSelect.change( function() {
|
||||
pageManagementUtils.handleContentTypeSelect();
|
||||
});
|
||||
|
@ -229,6 +273,7 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.classGroupSection.hide();
|
||||
pageManagementUtils.fixedHTMLSection.hide();
|
||||
pageManagementUtils.sparqlQuerySection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.hide();
|
||||
//Reset main content type drop-down
|
||||
pageManagementUtils.contentTypeSelectOptions.eq(0).attr('selected', 'selected');
|
||||
if ( pageManagementUtils.leftSideDiv.css("height") != undefined ) {
|
||||
|
@ -291,7 +336,8 @@ var pageManagementUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
//Select content type
|
||||
//Select content type - this is content type specific
|
||||
//TODO: Find better way to refactor this and/or see if any of this display functionality can be moved into content type processing
|
||||
handleContentTypeSelect:function() {
|
||||
_this = pageManagementUtils;
|
||||
pageManagementUtils.clearSourceTemplateValues();
|
||||
|
@ -299,22 +345,31 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.classGroupSection.show();
|
||||
pageManagementUtils.fixedHTMLSection.hide();
|
||||
pageManagementUtils.sparqlQuerySection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.hide();
|
||||
pageManagementUtils.headerBar.text(pageManagementUtils.browseClassGroup + " - ");
|
||||
pageManagementUtils.headerBar.show();
|
||||
$('div#selfContainedDiv').hide();
|
||||
}
|
||||
if ( _this.contentTypeSelect.val() == "fixedHtml" || _this.contentTypeSelect.val() == "sparqlQuery" ) {
|
||||
if ( _this.contentTypeSelect.val() == "fixedHtml" || _this.contentTypeSelect.val() == "sparqlQuery" || _this.contentTypeSelect.val() == "solrIndividuals") {
|
||||
pageManagementUtils.classGroupSection.hide();
|
||||
//if fixed html show that, otherwise show sparql results
|
||||
if ( _this.contentTypeSelect.val() == "fixedHtml" ) {
|
||||
pageManagementUtils.headerBar.text(pageManagementUtils.fixedHtml + " - ");
|
||||
pageManagementUtils.fixedHTMLSection.show();
|
||||
pageManagementUtils.sparqlQuerySection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.hide();
|
||||
}
|
||||
else {
|
||||
else if (_this.contentTypeSelect.val() == "sparqlQuery"){
|
||||
pageManagementUtils.headerBar.text(pageManagementUtils.sparqlResults + " - ");
|
||||
pageManagementUtils.sparqlQuerySection.show();
|
||||
pageManagementUtils.fixedHTMLSection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.hide();
|
||||
} else {
|
||||
//solr individuals
|
||||
pageManagementUtils.headerBar.text(pageManagementUtils.solrIndividuals + " - ");
|
||||
pageManagementUtils.sparqlQuerySection.hide();
|
||||
pageManagementUtils.fixedHTMLSection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.show();
|
||||
}
|
||||
|
||||
pageManagementUtils.headerBar.show();
|
||||
|
@ -325,6 +380,7 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.classGroupSection.hide();
|
||||
pageManagementUtils.fixedHTMLSection.hide();
|
||||
pageManagementUtils.sparqlQuerySection.hide();
|
||||
pageManagementUtils.solrIndividualsSection.hide();
|
||||
pageManagementUtils.classesForClassGroup.addClass('hidden');
|
||||
pageManagementUtils.headerBar.hide();
|
||||
pageManagementUtils.headerBar.text("");
|
||||
|
@ -359,6 +415,7 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.clearInputs(pageManagementUtils.fixedHTMLSection);
|
||||
pageManagementUtils.clearInputs(pageManagementUtils.sparqlQuerySection);
|
||||
pageManagementUtils.clearInputs(pageManagementUtils.classGroupSection);
|
||||
pageManagementUtils.clearInputs(pageManagementUtils.solrIndividualsSection);
|
||||
|
||||
},
|
||||
clearInputs:function($el) {
|
||||
|
@ -387,7 +444,7 @@ var pageManagementUtils = {
|
|||
// Get rid of the cancel link; it'll be replaced by a delete link
|
||||
$newContentObj.find('span#cancelContent' + counter).html('');
|
||||
|
||||
if ( contentType == "sparqlQuery" || contentType == "fixedHtml") {
|
||||
if ( contentType == "sparqlQuery" || contentType == "fixedHtml" || contentType == "solrIndividuals") {
|
||||
varOrClass = $newContentObj.find('input[name="saveToVar"]').val();
|
||||
}
|
||||
else if ( contentType == "browseClassGroup" ) {
|
||||
|
|
|
@ -9,7 +9,8 @@ var processDataGetterUtils = {
|
|||
dataGetterProcessorMap:{"browseClassGroup": processClassGroupDataGetterContent,
|
||||
"sparqlQuery": processSparqlDataGetterContent,
|
||||
"fixedHtml":processFixedHTMLDataGetterContent,
|
||||
"individualsForClasses":processIndividualsForClassesDataGetterContent},
|
||||
"individualsForClasses":processIndividualsForClassesDataGetterContent,
|
||||
"solrIndividuals":processSolrDataGetterContent},
|
||||
selectDataGetterType:function(pageContentSection) {
|
||||
var contentType = pageContentSection.attr("contentType");
|
||||
//The form can provide "browse class group" as content type but need to check
|
||||
|
|
86
webapp/web/js/menupage/processSolrDataGetterContent.js
Normal file
86
webapp/web/js/menupage/processSolrDataGetterContent.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
$.extend(this, i18nStringsSolrIndividuals);
|
||||
|
||||
//Process sparql data getter and provide a json object with the necessary information
|
||||
var processSolrDataGetterContent = {
|
||||
dataGetterClass:null,
|
||||
//can use this if expect to initialize from elsewhere
|
||||
initProcessor:function(dataGetterClass) {
|
||||
this.dataGetterClass =dataGetterClass;
|
||||
|
||||
},
|
||||
|
||||
processPageContentSection:function(pageContentSection) {
|
||||
|
||||
var variableValue = pageContentSection.find("input[name='saveToVar']").val();
|
||||
var vclassUriValue = pageContentSection.find("select[name='vclassUri']").val();
|
||||
|
||||
|
||||
//query model should also be an input
|
||||
//set query model to query model here - vitro:contentDisplayModel
|
||||
var returnObject = {saveToVar:variableValue, vclassUri:vclassUriValue, 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 saveToVarValue = existingContentObject["saveToVar"];
|
||||
var vclassUriValue = existingContentObject["vclassUri"];
|
||||
|
||||
|
||||
//Now find and set value
|
||||
pageContentSection.find("input[name='saveToVar']").val(saveToVarValue);
|
||||
//set value of solr query
|
||||
pageContentSection.find("select[name='vclassUri']").val(vclassUriValue);
|
||||
|
||||
},
|
||||
//For the label of the content section for editing, need to add additional value
|
||||
retrieveContentLabel:function() {
|
||||
return i18nStringsSolrIndividuals.solrIndividuals;
|
||||
},
|
||||
//For the label of the content section for editing, need to add additional value
|
||||
retrieveAdditionalLabelText:function(existingContentObject) {
|
||||
var saveToVarValue = existingContentObject["saveToVar"];
|
||||
return saveToVarValue;
|
||||
},
|
||||
//Validation on form submit: Check to see that class group has been selected
|
||||
validateFormSubmission: function(pageContentSection, pageContentSectionLabel) {
|
||||
var validationError = "";
|
||||
//Check that vclassuri and saveToVar have been input
|
||||
var variableValue = pageContentSection.find("input[name='saveToVar']").val();
|
||||
if(variableValue == "") {
|
||||
validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.supplyQueryVariable + " <br />"
|
||||
}
|
||||
if(processSolrDataGetterContent.stringHasSingleQuote(variableValue)) {
|
||||
validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.noApostrophes + " <br />";
|
||||
}
|
||||
if(processSolrDataGetterContent.stringHasDoubleQuote(variableValue)) {
|
||||
validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.noDoubleQuotes + " <br />";
|
||||
}
|
||||
|
||||
//validation for solr individuals
|
||||
|
||||
var vclassUriValue = pageContentSection.find("select[name='vclassUri']").val();
|
||||
if(vclassUriValue == "") {
|
||||
validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.selectClass + " <br />";
|
||||
}
|
||||
return validationError;
|
||||
},
|
||||
encodeQuotes:function(inputStr) {
|
||||
return inputStr.replace(/'/g, ''').replace(/"/g, '"');
|
||||
},
|
||||
//For the variable name, no single quote should be allowed
|
||||
//This can be extended for other special characters
|
||||
stringHasSingleQuote:function(inputStr) {
|
||||
return(inputStr.indexOf("'") != -1);
|
||||
},
|
||||
stringHasDoubleQuote:function(inputStr) {
|
||||
return(inputStr.indexOf("\"") != -1);
|
||||
},
|
||||
replaceEncodedWithEscapedQuotes: function(inputStr) {
|
||||
|
||||
return inputStr.replace(/'/g, "\'").replace(/"/g, "\"");
|
||||
}
|
||||
|
||||
|
||||
};
|
|
@ -2,4 +2,5 @@
|
|||
<#--These are the different content templates that will be cloned and used within page management-->
|
||||
<#include "pageManagement--browseClassGroups.ftl">
|
||||
<#include "pageManagement--sparqlQuery.ftl">
|
||||
<#include "pageManagement--fixedHtml.ftl">
|
||||
<#include "pageManagement--fixedHtml.ftl">
|
||||
<#include "pageManagement--solrIndividuals.ftl">
|
|
@ -12,7 +12,8 @@ scripts list.-->
|
|||
"browseClassGroup": "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData",
|
||||
"individualsForClasses": "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter",
|
||||
"sparqlQuery":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter",
|
||||
"fixedHtml":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter"
|
||||
"fixedHtml":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter",
|
||||
"solrIndividuals":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter"
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,33 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
<#--This contains the template for the Solr Class individuals content type that is to be cloned and used in page management-->
|
||||
<#assign classGroup = pageData.classGroup />
|
||||
<#assign classGroups = pageData.classGroups />
|
||||
<#assign classes = pageData.classes />
|
||||
<section id="solrIndividuals" class="contentSectionContainer">
|
||||
<label id="variableLabel" for="variable">${i18n().variable_name_all_caps}<span class="requiredHint"> *</span></label>
|
||||
<input type="text" name="saveToVar" size="20" value="" id="saveToVar" role="input" />
|
||||
<label id="vclassUriLabel" for="vclassUri">${i18n().select_vclass_uri}<span class="requiredHint"> *</span></label>
|
||||
<br/>
|
||||
<select name="vclassUri" id="vclassUri">
|
||||
<option value="">Select class</option>
|
||||
<#list classes as classObj>
|
||||
<option value="${classObj.URI}">${classObj.name}</option>
|
||||
</#list>
|
||||
</select>
|
||||
<br/>
|
||||
<input type="button" id="doneWithContent" class="doneWithContent" name="doneWithContent" value="${i18n().save_this_content}" />
|
||||
<#if menuAction == "Add">
|
||||
<span id="cancelContent"> or <a class="cancel" href="javascript:" id="cancelContentLink" title="${i18n().cancel_title}">${i18n().cancel_link}</a></span>
|
||||
</#if>
|
||||
</section>
|
||||
<script>
|
||||
var i18nStringsSolrIndividuals = {
|
||||
solrIndividuals: '${i18n().solr_individual_results}',
|
||||
supplyQueryVariable: '${i18n().supply_query_variable}',
|
||||
noApostrophes: '${i18n().apostrophe_not_allowed}',
|
||||
noDoubleQuotes: '${i18n().double_quote_note_allowed}',
|
||||
supplyQuery: '${i18n().supply_sparql_query}',
|
||||
selectClass: '${i18n().select_class_for_solr}'
|
||||
};
|
||||
</script>
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/js/menupage/processSolrDataGetterContent.js"></script>')}
|
|
@ -80,7 +80,8 @@
|
|||
<option value="" selected="selected">${i18n().select_type}</option>
|
||||
<option value="browseClassGroup">${i18n().browse_class_group}</option>
|
||||
<option value="fixedHtml">${i18n().fixed_html}</option>
|
||||
<option value="sparqlQuery">${i18n().sparql_query_results}</option>
|
||||
<option value="sparqlQuery">${i18n().sparql_query_results}</option>
|
||||
<option value="solrIndividuals">${i18n().solr_individual_results}</option>
|
||||
</select> <span class="note">${i18n().add_types}</span>
|
||||
</section>
|
||||
<section id="contentDivs"></section>
|
||||
|
@ -136,8 +137,10 @@
|
|||
|
||||
|
||||
</section>
|
||||
<section id="pagePermissions>
|
||||
<label for="default">${i18n().page_select_permission}</label>
|
||||
<section id="pagePermissions">
|
||||
<br/>
|
||||
<label for="action">${i18n().page_select_permission}</label>
|
||||
|
||||
<select id="action" name="action">
|
||||
<option value="">${i18n().page_select_permission_option}</option>
|
||||
<#list pageAvailablePermissionsURIsList as permissionURI>
|
||||
|
@ -176,6 +179,7 @@
|
|||
browseClassGroup: '${i18n().browse_class_group}',
|
||||
fixedHtml: '${i18n().fixed_html}',
|
||||
sparqlResults: '${i18n().sparql_query_results}',
|
||||
solrIndividuals: '${i18n().solr_individual_results}',
|
||||
orString: '${i18n().or}',
|
||||
deleteString: '${i18n().delete}',
|
||||
allCapitalized: '${i18n().all_capitalized}',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue