Merge pull request #1358 from tuub/DS-3136

DS-3136: Prevent the occurrence of internal server error while adding a bitstream to an item if the upload button is pressed without selecting a file
This commit is contained in:
Pascal-Nicolas Becker
2016-04-21 18:06:10 +02:00
3 changed files with 23 additions and 3 deletions

View File

@@ -1474,6 +1474,7 @@ jsp.tools.move-item.inheritpolicies = Inherit defaul
jsp.tools.upload-bitstream.info = Select the bitstream to upload jsp.tools.upload-bitstream.info = Select the bitstream to upload
jsp.tools.upload-bitstream.title = Upload Bitstream jsp.tools.upload-bitstream.title = Upload Bitstream
jsp.tools.upload-bitstream.upload = Upload jsp.tools.upload-bitstream.upload = Upload
jsp.tools.upload-bitstream.select.file.msg = Please select a file first
jsp.workspace.ws-error.errormsg1 = The system was unable to process your request correctly. You must specify an item. jsp.workspace.ws-error.errormsg1 = The system was unable to process your request correctly. You must specify an item.
jsp.workspace.ws-error.errormsg2 = Go back to "My DSpace", and select "Open" for the WorkSpace Item that you wish to work with. If you are still experiencing problems please do not hesitate to contact us and we will do our best to solve the problem. jsp.workspace.ws-error.errormsg2 = Go back to "My DSpace", and select "Open" for the WorkSpace Item that you wish to work with. If you are still experiencing problems please do not hesitate to contact us and we will do our best to solve the problem.
jsp.workspace.ws-error.heading = Error - Workspace Item jsp.workspace.ws-error.heading = Error - Workspace Item

View File

@@ -102,6 +102,9 @@ public class EditItemServlet extends DSpaceServlet
/** User confirms withdrawal of item */ /** User confirms withdrawal of item */
public static final int PUBLICIZE = 11; public static final int PUBLICIZE = 11;
/** JSP to upload bitstream */
protected static final String UPLOAD_BITSTREAM_JSP = "/tools/upload-bitstream.jsp";
/** Logger */ /** Logger */
private static final Logger log = Logger.getLogger(EditCommunitiesServlet.class); private static final Logger log = Logger.getLogger(EditCommunitiesServlet.class);
@@ -832,7 +835,7 @@ public class EditItemServlet extends DSpaceServlet
// Show upload bitstream page // Show upload bitstream page
request.setAttribute("item", item); request.setAttribute("item", item);
JSPManager JSPManager
.showJSP(request, response, "/tools/upload-bitstream.jsp"); .showJSP(request, response, UPLOAD_BITSTREAM_JSP);
}else }else
if(button.equals("submit_update_order") || button.startsWith("submit_order_")) if(button.equals("submit_update_order") || button.startsWith("submit_order_"))
{ {
@@ -908,7 +911,18 @@ public class EditItemServlet extends DSpaceServlet
Bitstream b = null; Bitstream b = null;
Item item = itemService.find(context, UIUtil.getUUIDParameter(wrapper, "item_id")); Item item = itemService.find(context, UIUtil.getUUIDParameter(wrapper, "item_id"));
File temp = wrapper.getFile("file"); File temp = wrapper.getFile("file");
if(temp == null)
{
boolean noFileSelected = true;
// Show upload bitstream page
request.setAttribute("noFileSelected", noFileSelected);
request.setAttribute("item", item);
JSPManager
.showJSP(request, response, UPLOAD_BITSTREAM_JSP);
return;
}
// Read the temp file as logo // Read the temp file as logo
InputStream is = new BufferedInputStream(new FileInputStream(temp)); InputStream is = new BufferedInputStream(new FileInputStream(temp));

View File

@@ -26,6 +26,8 @@
<% <%
Item item = (Item) request.getAttribute("item"); Item item = (Item) request.getAttribute("item");
request.setAttribute("LanguageSwitch", "hide"); request.setAttribute("LanguageSwitch", "hide");
Boolean noFileSelected = (Boolean) request.getAttribute("noFileSelected");
boolean isNoFileSelected = (noFileSelected == null ? false : noFileSelected.booleanValue());
%> %>
<dspace:layout style="submission" titlekey="jsp.tools.upload-bitstream.title" <dspace:layout style="submission" titlekey="jsp.tools.upload-bitstream.title"
@@ -39,8 +41,11 @@
<h1><fmt:message key="jsp.tools.upload-bitstream.title"/></h1> <h1><fmt:message key="jsp.tools.upload-bitstream.title"/></h1>
<%-- <p>Select the bitstream to upload</p> --%> <%-- <p>Select the bitstream to upload</p> --%>
<% if(isNoFileSelected){ %>
<p class="alert alert-warning"><fmt:message key="jsp.tools.upload-bitstream.select.file.msg"/></p>
<%} else {%>
<p class="alert alert-info"><fmt:message key="jsp.tools.upload-bitstream.info"/></p> <p class="alert alert-info"><fmt:message key="jsp.tools.upload-bitstream.info"/></p>
<%}%>
<form method="post" enctype="multipart/form-data" action=""> <form method="post" enctype="multipart/form-data" action="">
<div class="container row"> <div class="container row">
<input class="form-control" type="file" size="40" name="file"/> <input class="form-control" type="file" size="40" name="file"/>