Working on addEditWebpageForm and manageWebpagesForIndividual
This commit is contained in:
parent
a231470f01
commit
64aff4dfe7
4 changed files with 229 additions and 45 deletions
|
@ -1,8 +1,21 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Template for adding/editing core:webpages -->
|
||||
<#import "lib-vivo-form.ftl" as lvf>
|
||||
|
||||
<#if editConfig.object?has_content>
|
||||
<#assign subjectName=editConfiguration.pageData.subjectName!"an Individual" />
|
||||
|
||||
<#--If edit submission exists, then retrieve validation errors if they exist-->
|
||||
<#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content>
|
||||
<#assign submissionErrors = editSubmission.validationErrors/>
|
||||
</#if>
|
||||
|
||||
<#--Retrieve variables needed-->
|
||||
<#assign url = lvf.getFormFieldValue(editSubmission, editConfiguration, "url")/>
|
||||
<#assign anchor = lvf.getFormFieldValue(editSubmission, editConfiguration, "anchor") />
|
||||
<#assign newRank = lvf.getFormFieldValue(editSubmission, editConfiguration, "newRank") />
|
||||
|
||||
<#if editConfiguration.object?has_content>
|
||||
<#assign editMode = "edit">
|
||||
<#else>
|
||||
<#assign editMode = "add">
|
||||
|
@ -13,33 +26,42 @@
|
|||
<#assign submitButtonText="Save changes">
|
||||
<#assign disabledVal="disabled">
|
||||
<#else>
|
||||
<#assign titleVerb="Add">
|
||||
<#assign titleVerb="Add webpage for">
|
||||
<#assign submitButtonText="Add webpage">
|
||||
<#assign disabledVal=""/>
|
||||
</#if>
|
||||
|
||||
<#assign requiredHint="<span class='requiredHint'> *</span>" />
|
||||
|
||||
<h2>${title} ${subjectName}</h2>
|
||||
<h2>${titleVerb} ${subjectName}</h2>
|
||||
|
||||
<#if submissionErrors??>
|
||||
<section id="error-alert" role="alert">
|
||||
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
|
||||
<p>
|
||||
<#list submissionErrors?keys as errorFieldName>
|
||||
${errorFieldName}: ${submissionErrors[errorFieldName]} <br/>
|
||||
</#list>
|
||||
</p>
|
||||
</section>
|
||||
</#if>
|
||||
|
||||
<form class="customForm" action ="${submitUrl}" class="customForm">
|
||||
|
||||
<label for="url">URL ${requiredHint}</label>
|
||||
<input size="70" type="text" id="url" name="url" value="<#if url??>${url}</#if>" role="input" />
|
||||
<input size="70" type="text" id="url" name="url" value="${url}" role="input" />
|
||||
|
||||
<label for="anchor">Webpage Name</label>
|
||||
<input size="70" type="text" id="anchor" name="anchor" value="<#if anchor??>${anchor}</#if>" role="input" />
|
||||
<input size="70" type="text" id="anchor" name="anchor" value="${anchor}" role="input" />
|
||||
|
||||
<#if editMode="add">
|
||||
<input type="hidden" name="rank" value="${newRank}" />
|
||||
</#if>
|
||||
|
||||
<input type="hidden" id="editKey" name="editKey" value="${editConfiguration.editKey}"/>
|
||||
<p class="submit">
|
||||
<input type="submit" id="submit" value="${submitButtonText}" role="button" />
|
||||
|
||||
<span class="or"> or </span>
|
||||
|
||||
<a class="cancel" href="${editConfiguration.cancelUrl}" title="Cancel">Cancel</a>
|
||||
<input type="submit" id="submit" value="${submitButtonText}"/><span class="or"> or </span>
|
||||
<a class="cancel" href="${editConfiguration.cancelUrl}">Cancel</a>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
<#assign ulClass="class='dd'">
|
||||
</#if>
|
||||
|
||||
<#assign baseEditWebpageUrl=editConfiguration.pageData.baseEditWebpageUrl>
|
||||
<#assign deleteWebpageUrl=editConfiguration.pageData.deleteWebpageUrl>
|
||||
<#assign showAddFormUrl=editConfiguration.pageData.showAddFormUrl>
|
||||
<#assign baseEditWebpageUrl=editConfiguration.pageData.baseEditWebpageUrl!"baseEditWebpageUrl is undefined">
|
||||
<#assign deleteWebpageUrl=editConfiguration.pageData.deleteWebpageUrl!"deleteWebpageUrl is undefined">
|
||||
<#assign showAddFormUrl=editConfiguration.pageData.showAddFormUrl!"showAddFormUrl is undefined">
|
||||
|
||||
<#if (editConfiguration.pageData.subjectName??) >
|
||||
<h2><em>${editConfiguration.pageData.subjectName}</em></h2>
|
||||
|
@ -29,7 +29,7 @@
|
|||
|
||||
<#list editConfiguration.pageData.webpages as webpage>
|
||||
<li class="webpage" role="listitem">
|
||||
<#if webpage.anchor>
|
||||
<#if webpage.anchor??>
|
||||
<#assign anchor=webpage.anchor >
|
||||
<#else>
|
||||
<#assign anchor=webpage.url >
|
||||
|
@ -39,7 +39,7 @@
|
|||
<a href="${webpage.url}">${anchor}</a>
|
||||
</span>
|
||||
<span class="editingLinks">
|
||||
<a href="${baseEditWebpageUrl}&objectUri=${webpage.link}" class="edit">Edit</a> |
|
||||
<a href="${baseEditWebpageUrl}&objectUri=${webpage.link?url}" class="edit">Edit</a> |
|
||||
<a href="${deleteWebpageUrl}" class="remove">Delete</a>
|
||||
</span>
|
||||
</li>
|
||||
|
@ -58,9 +58,10 @@
|
|||
addAuthorsToInformationResource.jsp. -->
|
||||
<a href="${showAddFormUrl}" id="showAddForm" class="button green">Add Web Page</a>
|
||||
|
||||
<a href="/indiviudal?uri=${editConfiguration.subjectUri}" id="returnToIndividual" class="return">Return to Individual</a>
|
||||
<a href="${cancelUrl}" id="returnToIndividual" class="return">Return to Individual</a>
|
||||
</section>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var customFormData = {
|
||||
rankPredicate: '${editConfiguration.pageData.rankPredicate}',
|
||||
|
|
|
@ -3,16 +3,174 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators
|
|||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||
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.FieldVTwo;
|
||||
/**
|
||||
|
||||
Custom form for adding or editing a webpage associated with an individual. The primary page,
|
||||
ManageWebpagesForIndividual, should forward to this page if: (a) we are adding a new page, or
|
||||
(b) an edit link in the Manage Webpages view has been clicked. But right now (a) is not implemented.
|
||||
|
||||
Object properties:
|
||||
core:webpage (range: core:URLLink)
|
||||
core:webpageOf (domain: core:URLLink) (inverse of core:webpage)
|
||||
|
||||
Class:
|
||||
core:URLLink - the link to be added to the individual
|
||||
|
||||
Data properties of core:URLLink:
|
||||
core:linkURI
|
||||
core:linkAnchorText
|
||||
core:rank
|
||||
|
||||
*/
|
||||
public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
public static Log log = LogFactory.getLog( AddEditWebpageFormGenerator.class );
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new Error(this.getClass().getName() + " is not yet implement");
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
EditConfigurationVTwo config = new EditConfigurationVTwo();
|
||||
|
||||
config.setTemplate("addEditWebpageForm.ftl");
|
||||
|
||||
initBasics(config, vreq);
|
||||
initPropertyParameters(vreq, session, config);
|
||||
initObjectPropForm(config, vreq);
|
||||
|
||||
config.setVarNameForSubject("subject");
|
||||
|
||||
config.setVarNameForObject("link");
|
||||
config.addNewResource("link", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
config.setN3Required(list( N3_FOR_WEBPAGE ));
|
||||
config.setN3Optional(list( N3_FOR_ANCHOR, N3_FOR_RANK));
|
||||
|
||||
config.addUrisInScope("webpageProperty", list( core + "webpage"));
|
||||
config.addUrisInScope("inverseProperty", list( core + "webpageOf"));
|
||||
config.addUrisInScope("linkClass", list( core + "URLLink"));
|
||||
config.addUrisInScope("linkURI", list( core + "linkURI" ));
|
||||
config.addUrisInScope("linkAnchorPredicate", list( core + "linkAnchorText" ));
|
||||
config.addUrisInScope("rankPredicate", list( core + "rank"));
|
||||
config.addUrisInScope("linkClass", list( core + "URLLink"));
|
||||
|
||||
config.setLiteralsOnForm(list("url","anchor","rank"));
|
||||
|
||||
config.addSparqlForExistingLiteral("url", URL_QUERY);
|
||||
config.addSparqlForExistingLiteral("anchor", ANCHOR_QUERY);
|
||||
config.addSparqlForExistingLiteral("rank", MAX_RANK_QUERY);
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("url").
|
||||
setValidators(list("nonempty", "datatype:"+XSD.anyURI.toString(), "httpUrl")).
|
||||
setRangeDatatypeUri(XSD.anyURI.toString()));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("anchor").
|
||||
setValidators(list("datatype:"+XSD.anyURI.toString())).
|
||||
setRangeDatatypeUri(XSD.anyURI.toString()));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("rank").
|
||||
setRangeDatatypeUri(XSD.integer.toString()));
|
||||
|
||||
config.addFormSpecificData("newRank",
|
||||
getMaxRank( EditConfigurationUtils.getObjectUri(vreq),
|
||||
EditConfigurationUtils.getSubjectUri(vreq), vreq )
|
||||
+ 1 );
|
||||
|
||||
//might be null
|
||||
config.addFormSpecificData("subjectName", getName( config, vreq));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/** may be null */
|
||||
private Object getName(EditConfigurationVTwo config, VitroRequest vreq) {
|
||||
Individual ind = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(config.getSubjectUri());
|
||||
if( ind == null )
|
||||
return null;
|
||||
else
|
||||
return ind.getName();
|
||||
}
|
||||
|
||||
/* ********* N3 Assertions *********** */
|
||||
static String N3_FOR_WEBPAGE =
|
||||
"?subject ?webpageProperty ?link . \n"+
|
||||
"?link ?inverseProperty ?subject . \n"+
|
||||
"?link a ?linkClass ; \n" +
|
||||
" ?linkURI ?url .";
|
||||
|
||||
static String N3_FOR_ANCHOR =
|
||||
"?link ?linkAnchorPredicate ?anchor .";
|
||||
|
||||
static String N3_FOR_RANK =
|
||||
"?link ?rankPredicate ?rank .";
|
||||
|
||||
/* *********** SPARQL queries for existing values ************** */
|
||||
|
||||
static String URL_QUERY =
|
||||
"SELECT ?urlExisting WHERE { ?link ?linkURI ?urlExisting }";
|
||||
|
||||
static String ANCHOR_QUERY =
|
||||
"SELECT ?anchorExisting WHERE { ?link ?linkAnchorPredicate ?anchorExisting }";
|
||||
|
||||
static String RANK_QUERY =
|
||||
"SELECT ?rankExisting WHERE { ?link ?rankPredicate ?rankExisting }";
|
||||
|
||||
static String core = "http://vivoweb.org/ontology/core#";
|
||||
|
||||
|
||||
/* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned,
|
||||
* since it's ranked highest. Preventing that would require getting all the ranks and sorting in Java,
|
||||
* throwing out non-int values.
|
||||
*/
|
||||
private static String MAX_RANK_QUERY = ""
|
||||
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||
+ "SELECT DISTINCT ?rank WHERE { \n"
|
||||
+ " ?subject core:webpage ?link . \n"
|
||||
+ " ?link core:rank ?rank .\n"
|
||||
+ "} ORDER BY DESC(?rank) LIMIT 1";
|
||||
|
||||
private int getMaxRank(String objectUri, String subjectUri, VitroRequest vreq) {
|
||||
|
||||
int maxRank = 0; // default value
|
||||
if (objectUri == null) { // adding new webpage
|
||||
String queryStr = QueryUtils.subUriForQueryVar(MAX_RANK_QUERY, "subject", subjectUri);
|
||||
log.debug("Query string is: " + queryStr);
|
||||
try {
|
||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||
if (results != null && results.hasNext()) { // there is at most one result
|
||||
QuerySolution soln = results.next();
|
||||
RDFNode node = soln.get("rank");
|
||||
if (node != null && node.isLiteral()) {
|
||||
// node.asLiteral().getInt() won't return an xsd:string that
|
||||
// can be parsed as an int.
|
||||
int rank = Integer.parseInt(node.asLiteral().getLexicalForm());
|
||||
if (rank > maxRank) {
|
||||
log.debug("setting maxRank to " + rank);
|
||||
maxRank = rank;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Invalid rank returned from query: not an integer value.");
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
return maxRank;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
@ -25,6 +27,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTw
|
|||
* It is not an example of the normal use of the RDF editing system and
|
||||
* was just migrated over from an odd use of the JSP RDF editing system
|
||||
* during the 1.4 release.
|
||||
*
|
||||
* This mainly sets up pageData for the template to use.
|
||||
*/
|
||||
public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
public static Log log = LogFactory.getLog(ManageWebpagesForIndividualGenerator.class);
|
||||
|
@ -35,6 +39,10 @@ public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationG
|
|||
EditConfigurationVTwo config = new EditConfigurationVTwo();
|
||||
config.setTemplate("manageWebpagesForIndividual.ftl");
|
||||
|
||||
initBasics(config, vreq);
|
||||
initPropertyParameters(vreq, session, config);
|
||||
initObjectPropForm(config, vreq);
|
||||
|
||||
config.setSubjectUri(EditConfigurationUtils.getSubjectUri(vreq));
|
||||
config.setEntityToReturnTo( EditConfigurationUtils.getSubjectUri(vreq));
|
||||
|
||||
|
@ -43,29 +51,24 @@ public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationG
|
|||
|
||||
config.addFormSpecificData("rankPredicate", "http://vivoweb.org/ontology/core#rank" );
|
||||
config.addFormSpecificData("reorderUrl", "/edit/reorder" );
|
||||
|
||||
|
||||
config.addFormSpecificData("deleteWebpageUrl", "/edit/primitiveDelete");
|
||||
//<c:url var="deleteWebpageUrl" value="/edit/primitiveDelete" />
|
||||
|
||||
config.addFormSpecificData("deleteWebpageUrl", "/edit/reorder");
|
||||
//<c:url var="reorderUrl" value="/edit/reorder" />
|
||||
ParamMap paramMap = new ParamMap();
|
||||
paramMap.put("subjectUri", config.getSubjectUri());
|
||||
paramMap.put("editForm", AddEditWebpageFormGenerator.class.getName());
|
||||
paramMap.put("view", "form");
|
||||
String path = UrlBuilder.getUrl( UrlBuilder.Route.EDIT_REQUEST_DISPATCH ,paramMap);
|
||||
|
||||
config.addFormSpecificData("baseEditWebpageUrl", "TODO.BASICEDITWEBPAGEURL");
|
||||
/*
|
||||
<c:url var="baseEditWebpageUrl" value="/edit/editRequestDispatch.jsp">
|
||||
<c:param name="subjectUri" value="<%= subjectUri %>" />
|
||||
<c:param name="predicateUri" value="<%= predicateUri %>" />
|
||||
<c:param name="view" value="form" />
|
||||
</c:url>
|
||||
*/
|
||||
config.addFormSpecificData("baseEditWebpageUrl", path);
|
||||
|
||||
config.addFormSpecificData("showAddFormUrl", "TODO.SHOWADDFORMURL");
|
||||
// <c:url var="showAddFormUrl" value="/edit/editRequestDispatch.jsp">
|
||||
// <c:param name="subjectUri" value="<%= subjectUri %>" />
|
||||
// <c:param name="predicateUri" value="<%= predicateUri %>" />
|
||||
// <c:param name="cancelTo" value="manage" />
|
||||
// </c:url>
|
||||
paramMap = new ParamMap();
|
||||
paramMap.put("subjectUri", config.getSubjectUri());
|
||||
paramMap.put("predicateUri", config.getPredicateUri());
|
||||
paramMap.put("editForm" , AddEditWebpageFormGenerator.class.getName() );
|
||||
paramMap.put("cancelTo", "manage");
|
||||
path = UrlBuilder.getUrl( UrlBuilder.Route.EDIT_REQUEST_DISPATCH ,paramMap);
|
||||
|
||||
config.addFormSpecificData("showAddFormUrl", path);
|
||||
|
||||
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(config.getSubjectUri());
|
||||
if( subject != null && subject.getName() != null ){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue