Starting to work on manage web pages form.

This commit is contained in:
briancaruso 2011-11-16 20:14:00 +00:00
parent 714bfc196f
commit f3fc43deaa
2 changed files with 118 additions and 12 deletions

View file

@ -1,8 +1,20 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Custom form for managing webpages for individuals --> <#-- Custom form for managing web pages for individuals -->
<h2><em>${subjectName}</em></h2> <#if (editConfiguration.pageData.webpages?size > 0) >
<#assign ulClass="">
<#else>
<#assign ulClass="class='dd'">
</#if>
<#assign baseEditWebpageUrl=editConfiguration.pageData.baseEditWebpageUrl>
<#assign deleteWebpageUrl=editConfiguration.pageData.deleteWebpageUrl>
<#assign showAddFormUrl=editConfiguration.pageData.showAddFormUrl>
<#if (editConfiguration.pageData.subjectName??) >
<h2><em>${editConfiguration.pageData.subjectName}</em></h2>
</#if>
<h3>Manage Web Pages</h3> <h3>Manage Web Pages</h3>
@ -11,11 +23,11 @@
</script> </script>
<ul id="webpageList" ${ulClass} role="list"> <ul id="webpageList" ${ulClass} role="list">
<#if !webpages?has_content> <#if !editConfiguration.pageData.webpages?has_content>
<p>This individual currently has no web pages specified. Add a new web page by clicking on the button below.</p> <p>This individual currently has no web pages specified. Add a new web page by clicking on the button below.</p>
</#if> </#if>
<#list webpages as webpage> <#list editConfiguration.pageData.webpages as webpage>
<li class="webpage" role="listitem"> <li class="webpage" role="listitem">
<#if webpage.anchor> <#if webpage.anchor>
<#assign anchor=webpage.anchor > <#assign anchor=webpage.anchor >
@ -45,13 +57,14 @@
These can just be ordinary links, rather than a v:input element, as in These can just be ordinary links, rather than a v:input element, as in
addAuthorsToInformationResource.jsp. --> addAuthorsToInformationResource.jsp. -->
<a href="${showAddFormUrl}" id="showAddForm" class="button green">Add Web Page</a> <a href="${showAddFormUrl}" id="showAddForm" class="button green">Add Web Page</a>
<a href="${returnToIndividualUrl}" id="returnToIndividual" class="return">Return to Individual</a>
<a href="/indiviudal?uri=${editConfiguration.subjectUri}" id="returnToIndividual" class="return">Return to Individual</a>
</section> </section>
<script type="text/javascript"> <script type="text/javascript">
var customFormData = { var customFormData = {
rankPredicate: '${rankPredicate}', rankPredicate: '${editConfiguration.pageData.rankPredicate}',
reorderUrl: '${reorderUrl}' reorderUrl: '${editConfiguration.pageData.reorderUrl}'
}; };
</script> </script>

View file

@ -1,18 +1,111 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
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 edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.EditConfigurationVTwo;
/**
* This is an odd controller that is just drawing a page with links on it.
* 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.
*/
public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator { public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
public static Log log = LogFactory.getLog(ManageWebpagesForIndividualGenerator.class);
@Override @Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
HttpSession session) {
// TODO Auto-generated method stub EditConfigurationVTwo config = new EditConfigurationVTwo();
throw new Error(this.getClass().getName() + " is not yet implement"); config.setTemplate("manageWebpagesForIndividual.ftl");
config.setSubjectUri(EditConfigurationUtils.getSubjectUri(vreq));
config.setEntityToReturnTo( EditConfigurationUtils.getSubjectUri(vreq));
List<Map<String,String>> webpages = getWebpages(config.getSubjectUri(), vreq);
config.addFormSpecificData("webpages",webpages);
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" />
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("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>
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(config.getSubjectUri());
if( subject != null && subject.getName() != null ){
config.addFormSpecificData("subjectName", subject.getName());
}else{
config.addFormSpecificData("subjectName", null);
}
return config;
} }
private static String WEBPAGE_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?link ?url ?anchor ?rank WHERE { \n"
+ " ?subject core:webpage ?link . \n"
+ " OPTIONAL { ?link core:linkURI ?url } \n"
+ " OPTIONAL { ?link core:linkAnchorText ?anchor } \n"
+ " OPTIONAL { ?link core:rank ?rank } \n"
+ "} ORDER BY ?rank";
private List<Map<String, String>> getWebpages(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(WEBPAGE_QUERY, "subject", subjectUri);
log.debug("Query string is: " + queryStr);
List<Map<String, String>> webpages = new ArrayList<Map<String, String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
RDFNode node = soln.get("link");
if (node.isURIResource()) {
webpages.add(QueryUtils.querySolutionToStringValueMap(soln));
}
}
} catch (Exception e) {
log.error(e, e);
}
return webpages;
}
} }