Updates for page management

This commit is contained in:
hjkhjk54 2012-06-04 21:36:04 +00:00
parent 918451f294
commit a31b91bddd
15 changed files with 292 additions and 33 deletions

View file

@ -130,11 +130,14 @@ public class DisplayVocabulary {
public static final String HOME_MENU_ITEM = DISPLAY_NS + "HomeMenuItem";
/* some URIs of properties used with the SPARQL DataGetter */
/* some URIs of properties used with the SPARQL DataGetter, and save to var is saved for fixedHtml */
public static final String SAVE_TO_VAR = DISPLAY_NS + "saveToVar" ;
public static final String QUERY_MODEL = DISPLAY_NS + "queryModel";
public static final String QUERY = DISPLAY_NS + "query";
/* URI of property for Fixed HTML Generator */
public static final String FIXED_HTML_VALUE = DISPLAY_NS + "htmlValue";
//public static final Individual EVENTS = m_model.createIndividual( NS + "Events", PAGE );
//public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( NS + "EventsMenuItem", NAVIGATION_ELEMENT );

View file

@ -13,6 +13,7 @@ import javax.servlet.http.HttpSession;
import com.hp.hpl.jena.ontology.OntModel;
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.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
@ -154,7 +155,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
//For the case of a new page
if(subjectUri == null) {
//Once added, return to pageList
editConfiguration.setUrlToReturnTo("/pageList");
editConfiguration.setUrlToReturnTo(UrlBuilder.getUrl("/pageList"));
editConfiguration.setEntityToReturnTo("?page");
editConfiguration.setPredicateUri(predicateUri);

View file

@ -180,10 +180,7 @@ public class ManagePagePreprocessor extends
uriValuesSubmission = uriValues.toArray(uriValuesSubmission);
//This adds literal, connecting the field with the value
submission.addLiteralToForm(editConfiguration,
editConfiguration.getField(submissionUriName),
submissionUriName,
uriValuesSubmission);
submission.addUriToForm(editConfiguration, submissionUriName, uriValuesSubmission);
}
//this needs to be different

View file

@ -18,7 +18,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 ProcessClassGroupDataGetterN3(){
}
@ -27,18 +27,28 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//TODO: ensure correct model returned
//We shouldn't use the ACTUAL values here but generate the n3 required
public List<String> retrieveN3Required(int counter) {
String dataGetterVar = getDataGetterVar(counter);
String n3 = dataGetterVar + " a <" + classType + ">; \n" +
"<" + DisplayVocabulary.FOR_CLASSGROUP + "> ?classGroup .";
List<String> requiredList = new ArrayList<String>();
requiredList.add(getPrefixes() + n3);
return requiredList;
return this.retrieveN3ForTypeAndClassGroup(counter);
}
public List<String> retrieveN3Optional(int counter) {
return null;
}
public List<String> retrieveN3ForTypeAndClassGroup(int counter) {
String n3ForType = this.getN3ForTypePartial(counter);
String n3 = n3ForType +"; \n" +
"<" + DisplayVocabulary.FOR_CLASSGROUP + "> " + getN3VarName(classGroupVarBase, counter) + " .";
List<String> n3List = new ArrayList<String>();
n3List.add(getPrefixes() + n3);
return n3List;
}
public String getN3ForTypePartial(int counter) {
String dataGetterVar = getDataGetterVar(counter);
String n3 = dataGetterVar + " a <" + getClassType() + ">";
return n3;
}
//These methods will return the literals and uris expected within the n3
//and the counter is used to ensure they are numbered correctly
@ -75,6 +85,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
return Arrays.asList("classGroup");
}
//This class can be extended so returning type here
public String getClassType() {
return classType;
}
}

View file

@ -33,6 +33,7 @@ public class ProcessDataGetterN3Utils {
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSparqlDataGetterN3");
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");
return map;
}
@ -57,13 +58,15 @@ public class ProcessDataGetterN3Utils {
ProcessDataGetterN3 pn = null;
try {
Class<?> clz = Class.forName(processorClass);
Constructor<?> ct = clz.getConstructor();
Constructor<?>[] ctList = clz.getConstructors();
for (Constructor<?> ct: ctList) {
Class<?>[] parameterTypes =ct.getParameterTypes();
if(parameterTypes.length > 0 && parameterTypes[0].isAssignableFrom(jsonObject.getClass())) {
pn = (ProcessDataGetterN3) ct.newInstance(jsonObject);
} else {
pn = (ProcessDataGetterN3) ct.newInstance();
}
}
} catch(Exception ex) {
log.error("Error occurred instantiating " + processorClass, ex);

View file

@ -0,0 +1,81 @@
/* $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.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
//Returns the appropriate n3 based on data getter
public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter";
public ProcessFixedHTMLN3(){
}
//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
public List<String> retrieveN3Required(int counter) {
String dataGetterVar = getDataGetterVar(counter);
String n3 = dataGetterVar + " a <" + classType + ">; \n" +
"display:saveToVar " + getN3VarName("saveToVar", counter) + "; \n" +
"display:htmlValue " + getN3VarName("htmlValue", 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));
literalsOnForm.add(getVarName("htmlValue", counter));
return literalsOnForm;
}
public List<String> retrieveUrisOnForm(int counter) {
List<String> urisOnForm = new ArrayList<String>();
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("htmlValue", counter)));
return fields;
}
public List<String> getLiteralVarNamesBase() {
return Arrays.asList("saveToVar", "htmlValue");
}
//these are for the fields ON the form
public List<String> getUriVarNamesBase() {
return Arrays.asList();
}
}

View file

@ -36,12 +36,20 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
//TODO: ensure correct model returned
//We shouldn't use the ACTUAL values here but generate the n3 required
public List<String> retrieveN3Required(int counter) {
List<String> classGroupN3 = super.retrieveN3Required(counter);
List<String> classGroupN3 = this.retrieveN3ForTypeAndClassGroup(counter);
classGroupN3.addAll(this.addIndividualClassesN3(counter));
return classGroupN3;
}
/*
@Override
public String getN3ForTypePartial(int counter) {
String dataGetterVar = getDataGetterVar(counter);
String n3 = dataGetterVar + " a <" + getClassType() + ">";
return n3;
}*/
private List<String> addIndividualClassesN3(int counter) {
List<String> classN3 = new ArrayList<String>();
@ -127,6 +135,11 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
return Arrays.asList("classGroup", individualClassVarNameBase);
}
@Override
public String getClassType() {
return classType;
}
}

View file

@ -0,0 +1,128 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
public class FixedHTMLDataGetter extends DataGetterBase implements DataGetter{
String dataGetterURI;
String htmlValue;
String saveToVar;
VitroRequest vreq;
ServletContext context;
private final static String defaultTemplate = "menupage--defaultFixedHtml.ftl";
final static Log log = LogFactory.getLog(FixedHTMLDataGetter.class);
/**
* Constructor with display model and data getter URI that will be called by reflection.
*/
public FixedHTMLDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){
this.configure(vreq, displayModel,dataGetterURI);
}
@Override
public Map<String, Object> getData(Map<String, Object> pageData) {
Map<String, Object> rmap = new HashMap<String,Object>();
rmap.put("variableName", this.saveToVar);
rmap.put(this.saveToVar, this.htmlValue);
//this is the default template set here - overridden by page level template if there is one
rmap.put("bodyTemplate", defaultTemplate);
return rmap;
}
/**
* Configure this instance based on the URI and display model.
*/
protected void configure(VitroRequest vreq, Model displayModel, String dataGetterURI) {
if( vreq == null )
throw new IllegalArgumentException("VitroRequest may not be null.");
if( displayModel == null )
throw new IllegalArgumentException("Display Model may not be null.");
if( dataGetterURI == null )
throw new IllegalArgumentException("PageUri may not be null.");
this.vreq = vreq;
this.context = vreq.getSession().getServletContext();
this.dataGetterURI = dataGetterURI;
QuerySolutionMap initBindings = new QuerySolutionMap();
initBindings.add("dataGetterURI", ResourceFactory.createResource(this.dataGetterURI));
int count = 0;
Query dataGetterConfigurationQuery = QueryFactory.create(dataGetterQuery) ;
displayModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qexec = QueryExecutionFactory.create(
dataGetterConfigurationQuery, displayModel, initBindings) ;
ResultSet res = qexec.execSelect();
try{
while( res.hasNext() ){
count++;
QuerySolution soln = res.next();
// is NOT OPTIONAL
Literal value = soln.getLiteral("htmlValue");
if( dataGetterConfigurationQuery == null )
log.error("no html value defined for page " + this.dataGetterURI);
else
this.htmlValue = value.getLexicalForm();
//saveToVar is OPTIONAL
Literal saveTo = soln.getLiteral("saveToVar");
if( saveTo != null && saveTo.isLiteral() ){
this.saveToVar = saveTo.asLiteral().getLexicalForm();
}else{
this.saveToVar = defaultVarNameForResults;
}
}
}finally{ qexec.close(); }
}finally{ displayModel.leaveCriticalSection(); }
}
private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">";
private static final String htmlValuePropertyURI= "<" + DisplayVocabulary.FIXED_HTML_VALUE+ ">";
public static final String defaultVarNameForResults = "results";
/**
* Query to get the definition of the SparqlDataGetter for a given URI.
*/
private static final String dataGetterQuery =
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" +
"SELECT ?saveToVar ?htmlValue WHERE { \n" +
" ?dataGetterURI "+saveToVarPropertyURI+" ?saveToVar . \n" +
" ?dataGetterURI "+htmlValuePropertyURI+" ?htmlValue . \n" +
"}";
}

View file

@ -114,6 +114,9 @@ owl:versionInfo
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#queryModel>
a owl:DatatypeProperty.
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#htmlValue>
a owl:DatatypeProperty.
######### Object Properties#########
###Basic
rdfs:range

View file

@ -221,8 +221,8 @@ var pageManagementUtils = {
pageManagementUtils.createPageContentForSubmission();
//return true;
//For testing, not submitting anything
event.preventDefault();
return false;
//event.preventDefault();
return true;
} else{
$('#error-alert').removeClass('hidden');
@ -261,8 +261,8 @@ var pageManagementUtils = {
//Clone the object, renaming ids and copying text area values as well
$newContentObj = pageManagementUtils.createCloneObject(contentType, counter);
if ( contentType == "fixedHTML" || contentType == "sparqlQuery") {
varOrClass = $newContentObj.find('input#saveToVar').val();
if ( contentType == "sparqlQuery" || contentType == "fixedHtml") {
varOrClass = $newContentObj.find('input[name="saveToVar"]').val();
}
else if ( contentType == "browseClassGroup" ) {
$newContentObj.find('section#classesInSelectedGroup' + counter).removeClass('hidden');

View file

@ -12,7 +12,7 @@ var processClassGroupDataGetterContent = {
processPageContentSection:function(pageContentSection) {
//Will look at classes etc.
var classGroup = pageContentSection.find("select[name='selectClassGroup']").val();
//query model should also be an input
//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;
}

View file

@ -9,10 +9,10 @@ var processFixedHTMLDataGetterContent = {
},
//requires variable and text area
processPageContentSection:function(pageContentSection) {
var variableValue = pageContentSection.find("input[name='variable']").val();
var queryValue = pageContentSection.find("textarea[name='textArea']").val();
var saveToVarValue = pageContentSection.find("input[name='saveToVar']").val();
var htmlValue = pageContentSection.find("textarea[name='htmlValue']").val();
//query model should also be an input
var returnObject = {saveToVar:variableValue, query:queryValue, dataGetterClass:this.dataGetterClass, queryModel:"vitro:contextDisplayModel"};
var returnObject = {saveToVar:saveToVarValue, htmlValue:htmlValue, dataGetterClass:this.dataGetterClass};
return returnObject;
}

View file

@ -12,6 +12,7 @@ var processIndividualsForClassesDataGetterContent = {
//Get classes selected
var classesSelected = [];
pageContentSection.find("input[name='classInClassGroup']:checked").each(function(){
//Need to make sure that the class is also saved as a URI
classesSelected.push($(this).val());
});
var returnObject = {classGroup:classGroup, classesSelectedInClassGroup:classesSelected, dataGetterClass:this.dataGetterClass};

View file

@ -0,0 +1,15 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--Save to variable indicated in generator -->
<#assign htmlExists = false/>
<#if variableName?has_content>
<#assign htmlExists = true />
</#if>
<#if htmlExists>
${variableName}
<#else>
No HTML specified.
</#if>