fixing error messages for some ingest servlets. NIHVIVO-3375
This commit is contained in:
parent
49b12e06ff
commit
89e55aafde
3 changed files with 62 additions and 19 deletions
|
@ -16,10 +16,11 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
|
@ -34,6 +35,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||||
|
|
||||||
|
|
||||||
public class JenaCsv2RdfController extends BaseEditController{
|
public class JenaCsv2RdfController extends BaseEditController{
|
||||||
|
Log log = LogFactory.getLog( JenaCsv2RdfController.class );
|
||||||
|
|
||||||
private static final String CSV2RDF_JSP = "/jenaIngest/csv2rdf.jsp";
|
private static final String CSV2RDF_JSP = "/jenaIngest/csv2rdf.jsp";
|
||||||
private static final String CSV2RDF_SELECT_URI_JSP = "/jenaIngest/csv2rdfSelectUri.jsp";
|
private static final String CSV2RDF_SELECT_URI_JSP = "/jenaIngest/csv2rdfSelectUri.jsp";
|
||||||
private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb
|
private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb
|
||||||
|
@ -64,8 +67,14 @@ public class JenaCsv2RdfController extends BaseEditController{
|
||||||
if (!csvUrl.isEmpty() || !filePath.isEmpty()) {
|
if (!csvUrl.isEmpty() || !filePath.isEmpty()) {
|
||||||
String destinationModelNameStr = request.getParameter(
|
String destinationModelNameStr = request.getParameter(
|
||||||
"destinationModelName");
|
"destinationModelName");
|
||||||
Model csv2rdfResult = doExecuteCsv2Rdf(
|
Model csv2rdfResult = null;
|
||||||
|
try{
|
||||||
|
csv2rdfResult = doExecuteCsv2Rdf(
|
||||||
request, fileStream, filePath);
|
request, fileStream, filePath);
|
||||||
|
}catch(Exception ex){
|
||||||
|
forwardToFileUploadError(ex.getMessage(),req,response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
ModelMaker maker = getVitroJenaModelMaker(request);
|
ModelMaker maker = getVitroJenaModelMaker(request);
|
||||||
Boolean csv2rdf = true;
|
Boolean csv2rdf = true;
|
||||||
JenaIngestUtils utils = new JenaIngestUtils();
|
JenaIngestUtils utils = new JenaIngestUtils();
|
||||||
|
@ -96,18 +105,39 @@ public class JenaCsv2RdfController extends BaseEditController{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forwardToFileUploadError( String errrorMsg , HttpServletRequest req, HttpServletResponse response) throws ServletException{
|
// private void forwardToFileUploadError( String errrorMsg , HttpServletRequest req, HttpServletResponse response) throws ServletException{
|
||||||
|
// req.setAttribute("errors", errrorMsg);
|
||||||
|
// RequestDispatcher rd = req.getRequestDispatcher("/jsp/fileUploadError.jsp");
|
||||||
|
// try {
|
||||||
|
// rd.forward(req, response);
|
||||||
|
// } catch (IOException e1) {
|
||||||
|
// throw new ServletException(e1);
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void forwardToFileUploadError(String errrorMsg,
|
||||||
|
HttpServletRequest req, HttpServletResponse response)
|
||||||
|
throws ServletException {
|
||||||
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
|
req.setAttribute("title", "CSV to RDF Error ");
|
||||||
|
req.setAttribute("bodyJsp", "/jsp/fileUploadError.jsp");
|
||||||
req.setAttribute("errors", errrorMsg);
|
req.setAttribute("errors", errrorMsg);
|
||||||
RequestDispatcher rd = req.getRequestDispatcher("/edit/fileUploadError.jsp");
|
|
||||||
|
RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
|
req.setAttribute("css",
|
||||||
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\""
|
||||||
|
+ vreq.getAppBean().getThemeDir() + "css/edit.css\"/>");
|
||||||
try {
|
try {
|
||||||
rd.forward(req, response);
|
rd.forward(req, response);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
|
log.error(e1);
|
||||||
throw new ServletException(e1);
|
throw new ServletException(e1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model doExecuteCsv2Rdf(VitroRequest vreq, FileItem fileStream, String filePath) {
|
public Model doExecuteCsv2Rdf(VitroRequest vreq, FileItem fileStream, String filePath) throws Exception {
|
||||||
char[] quoteChars = {'"'};
|
char[] quoteChars = {'"'};
|
||||||
String namespace = "";
|
String namespace = "";
|
||||||
String tboxNamespace = vreq.getParameter("tboxNamespace");
|
String tboxNamespace = vreq.getParameter("tboxNamespace");
|
||||||
|
@ -140,7 +170,7 @@ public class JenaCsv2RdfController extends BaseEditController{
|
||||||
is = fileStream.getInputStream();
|
is = fileStream.getInputStream();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to access URL " + csvUrl);
|
throw new Exception("Unable to access URL " + csvUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Model[] models = null;
|
Model[] models = null;
|
||||||
|
@ -149,7 +179,7 @@ public class JenaCsv2RdfController extends BaseEditController{
|
||||||
models = c2r.convertToRdf(
|
models = c2r.convertToRdf(
|
||||||
is, vreq.getWebappDaoFactory(), destination);
|
is, vreq.getWebappDaoFactory(), destination);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(
|
throw new Exception(
|
||||||
"Unable to convert " + csvUrl + " to RDF");
|
"Unable to convert " + csvUrl + " to RDF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,9 +319,16 @@ public class RDFUploadController extends BaseEditController {
|
||||||
HttpServletRequest req,
|
HttpServletRequest req,
|
||||||
HttpServletResponse response)
|
HttpServletResponse response)
|
||||||
throws ServletException{
|
throws ServletException{
|
||||||
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
|
req.setAttribute("title","RDF Upload Error ");
|
||||||
|
req.setAttribute("bodyJsp","/jsp/fileUploadError.jsp");
|
||||||
req.setAttribute("errors", errrorMsg);
|
req.setAttribute("errors", errrorMsg);
|
||||||
|
|
||||||
RequestDispatcher rd = req.getRequestDispatcher(
|
RequestDispatcher rd = req.getRequestDispatcher(
|
||||||
"/edit/fileUploadError.jsp");
|
Controllers.BASIC_JSP);
|
||||||
|
req.setAttribute("css",
|
||||||
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
|
||||||
|
vreq.getAppBean().getThemeDir() + "css/edit.css\"/>");
|
||||||
try {
|
try {
|
||||||
rd.forward(req, response);
|
rd.forward(req, response);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
|
|
6
webapp/web/jsp/fileUploadError.jsp
Normal file
6
webapp/web/jsp/fileUploadError.jsp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
${errors}
|
||||||
|
</div>
|
Loading…
Add table
Reference in a new issue