Starting to work on manage web pages form.
This commit is contained in:
parent
714bfc196f
commit
f3fc43deaa
2 changed files with 118 additions and 12 deletions
|
@ -1,18 +1,111 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
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 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.dao.jena.QueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
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 static Log log = LogFactory.getLog(ManageWebpagesForIndividualGenerator.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("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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue