NIHVIVO-1521 Ajax controllers now extend VitroAjaxController rather than FreemarkerHttpServlet.
This commit is contained in:
parent
a38a81b2e6
commit
c5b06b5379
6 changed files with 42 additions and 152 deletions
|
@ -92,5 +92,13 @@ public abstract class VitroAjaxController extends HttpServlet {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void doError(HttpServletResponse response, String errorMsg, int httpstatus){
|
||||||
|
response.setStatus(httpstatus);
|
||||||
|
try {
|
||||||
|
response.getWriter().write(errorMsg);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.debug("IO exception during output",e );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,32 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||||
|
|
||||||
public class PrimitiveDelete extends PrimitiveRdfEdit {
|
public class PrimitiveDelete extends VitroAjaxController {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(PrimitiveDelete.class);
|
private static final Log log = LogFactory.getLog(PrimitiveDelete.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
protected boolean testIsAuthorized(HttpServletRequest request) {
|
||||||
|
return LoginStatusBean.getBean(request).isLoggedIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||||
|
|
||||||
String uriToDelete = vreq.getParameter("deletion");
|
String uriToDelete = vreq.getParameter("deletion");
|
||||||
if (StringUtils.isEmpty(uriToDelete)) {
|
if (StringUtils.isEmpty(uriToDelete)) {
|
||||||
|
|
|
@ -23,68 +23,24 @@ import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils;
|
||||||
|
|
||||||
public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle(String siteName, VitroRequest vreq) {
|
protected boolean testIsAuthorized(HttpServletRequest request) {
|
||||||
return "RDF edit";
|
return LoginStatusBean.getBean(request).isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int requiredLoginLevel() {
|
protected void doRequest(VitroRequest vreq,
|
||||||
return LoginStatusBean.EDITOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
|
||||||
return new TemplateResponseValues("primitiveRdfEdit.ftl");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doPost(HttpServletRequest request,
|
|
||||||
HttpServletResponse response) throws ServletException, IOException {
|
HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
if( !LoginStatusBean.getBean(request).isLoggedIn()){
|
|
||||||
doError(response,"You must be logged in to use this servlet.",HttpStatus.SC_UNAUTHORIZED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PolicyIface policy = RequestPolicyList.getPolicies( request );
|
|
||||||
//
|
|
||||||
// if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
|
||||||
// policy = ServletPolicyList.getPolicies( getServletContext() );
|
|
||||||
// if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
|
||||||
// log.debug("No policy found in request at " + RequestPolicyList.POLICY_LIST);
|
|
||||||
// doError(response, "no policy found.",500);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// IdentifierBundle ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
|
||||||
// .getIdBundleForRequest(request,request.getSession(false),getServletContext());
|
|
||||||
//
|
|
||||||
// if( ids == null ){
|
|
||||||
// log.error("No IdentifierBundle objects for request");
|
|
||||||
// doError(response,"no identifiers found",500);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
processRequest(vreq, response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
|
||||||
|
|
||||||
//Test error case
|
//Test error case
|
||||||
/*
|
/*
|
||||||
if (1==1) {
|
if (1==1) {
|
||||||
|
@ -122,17 +78,6 @@ public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//check permissions
|
|
||||||
//TODO: (bdc34)This is not yet implemented, must check the IDs against the policies for permissons before doing an edit!
|
|
||||||
// rjy7 put policy check in separate method so subclasses can inherit
|
|
||||||
boolean hasPermission = true;
|
|
||||||
|
|
||||||
if( !hasPermission ){
|
|
||||||
//if not okay, send error message
|
|
||||||
doError(response,"Insufficent permissions.",HttpStatus.SC_UNAUTHORIZED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServletContext sc = getServletContext();
|
ServletContext sc = getServletContext();
|
||||||
String editorUri = EditN3Utils.getEditorUri(vreq, vreq.getSession(false), sc);
|
String editorUri = EditN3Utils.getEditorUri(vreq, vreq.getSession(false), sc);
|
||||||
try {
|
try {
|
||||||
|
@ -208,15 +153,6 @@ public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doError(HttpServletResponse response, String errorMsg, int httpstatus){
|
|
||||||
response.setStatus(httpstatus);
|
|
||||||
try {
|
|
||||||
response.getWriter().write(errorMsg);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.debug("IO exception during output",e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OntModel getWriteModel(HttpServletRequest request){
|
protected OntModel getWriteModel(HttpServletRequest request){
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
if( session == null || session.getAttribute("jenaOntModel") == null )
|
if( session == null || session.getAttribute("jenaOntModel") == null )
|
||||||
|
|
|
@ -2,14 +2,17 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
|
@ -21,16 +24,22 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
* @author rjy7
|
* @author rjy7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReorderController extends PrimitiveRdfEdit {
|
public class ReorderController extends VitroAjaxController {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(ReorderController.class);
|
private static final Log log = LogFactory.getLog(ReorderController.class);
|
||||||
|
|
||||||
private static String RANK_PREDICATE_PARAMETER_NAME = "predicate";
|
private static String RANK_PREDICATE_PARAMETER_NAME = "predicate";
|
||||||
private static String INDIVIDUAL_PREDICATE_PARAMETER_NAME = "individuals";
|
private static String INDIVIDUAL_PREDICATE_PARAMETER_NAME = "individuals";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean testIsAuthorized(HttpServletRequest request) {
|
||||||
|
return LoginStatusBean.getBean(request).isLoggedIn();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
protected void doRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||||
|
|
||||||
String errorMsg = null;
|
String errorMsg = null;
|
||||||
String rankPredicate = vreq.getParameter(RANK_PREDICATE_PARAMETER_NAME);
|
String rankPredicate = vreq.getParameter(RANK_PREDICATE_PARAMETER_NAME);
|
||||||
|
@ -88,51 +97,6 @@ public class ReorderController extends PrimitiveRdfEdit {
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Alternate implementation: build up a model of additions and retractions, use only one db write
|
|
||||||
// DataPropertyDao dpDao = wadf.getDataPropertyDao();
|
|
||||||
// if( dpDao == null) {
|
|
||||||
// errorMsg = "No DataPropertyDao available";
|
|
||||||
// log.error(errorMsg);
|
|
||||||
// doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// DataProperty dp = dpDao.getDataPropertyByURI(rankPredicate);
|
|
||||||
// String rangeDatatypeUri = dp.getRangeDatatypeURI();
|
|
||||||
//
|
|
||||||
// Model additions = com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel();
|
|
||||||
// Model retractions = com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel();
|
|
||||||
// OntModel model = getQueryModel(vreq);
|
|
||||||
//
|
|
||||||
// int counter = 1;
|
|
||||||
// for (String individualUri : individualUris) {
|
|
||||||
// Resource resource = model.createResource(individualUri);
|
|
||||||
// Property property = model.getProperty(rankPredicate);
|
|
||||||
// // Remove all existing rank statements for this individual and predicate
|
|
||||||
// StmtIterator stmts = model.listStatements(resource, property, (RDFNode) null);
|
|
||||||
// retractions.add(stmts);
|
|
||||||
//
|
|
||||||
// Literal lit = null;
|
|
||||||
// if (rangeDatatypeUri != null) {
|
|
||||||
// lit = model.createTypedLiteral(counter, rangeDatatypeUri);
|
|
||||||
// } else {
|
|
||||||
// lit = model.createLiteral(String.valueOf(counter));
|
|
||||||
// // or: lit = model.createTypedLiteral(count) ?
|
|
||||||
// }
|
|
||||||
// Statement stmt = model.createStatement(resource, property, lit);
|
|
||||||
// additions.add(stmt);
|
|
||||||
//
|
|
||||||
// counter++;
|
|
||||||
// }
|
|
||||||
// ServletContext sc = getServletContext();
|
|
||||||
// String editorUri = EditN3Utils.getEditorUri(vreq, vreq.getSession(false), sc);
|
|
||||||
// try {
|
|
||||||
// processChanges( additions, retractions, getWriteModel(vreq), getQueryModel(vreq), editorUri);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// doError(response,e.getMessage(),HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// // end alternate implementation
|
|
||||||
|
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,13 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
String NORESULT_MSG = "";
|
String NORESULT_MSG = "";
|
||||||
private int defaultMaxSearchSize= 1000;
|
private int defaultMaxSearchSize= 1000;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean testIsAuthorized(HttpServletRequest request) {
|
||||||
|
return LoginStatusBean.getBean(request).isLoggedIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void doRequest(VitroRequest vreq, HttpServletResponse response)
|
protected void doRequest(VitroRequest vreq, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
|
@ -389,11 +396,4 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean testIsAuthorized(HttpServletRequest request) {
|
|
||||||
return LoginStatusBean.getBean(request).isLoggedIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<form method="POST">
|
|
||||||
|
|
||||||
Additions:<br />
|
|
||||||
<textarea name="additions"></textarea>
|
|
||||||
|
|
||||||
<br /><br />
|
|
||||||
|
|
||||||
Retractions:<br />
|
|
||||||
<textarea name="retractions"></textarea>
|
|
||||||
|
|
||||||
<br /><br />
|
|
||||||
|
|
||||||
<div>
|
|
||||||
N3<input type="radio" name="rdfFormat" value="N3"/>
|
|
||||||
TURTLE<input type="radio" name="rdfFormat" value="TURTLE"/>
|
|
||||||
RDF/XML<input type="radio" name="rdfFormat" value="RDF/XML"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="submit"/>
|
|
||||||
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
Loading…
Add table
Reference in a new issue