Merge pull request #620 from tuub/DS-2113

Fixes DS-2113: JSPUI HTML5 upload should store Bitstreams...
This commit is contained in:
Peter Dietz
2014-10-24 06:25:00 -04:00
4 changed files with 67 additions and 82 deletions

View File

@@ -435,7 +435,7 @@ public class UploadStep extends AbstractProcessingStep
* UI-related code! (if STATUS_COMPLETE or 0 is returned, * UI-related code! (if STATUS_COMPLETE or 0 is returned,
* no errors occurred!) * no errors occurred!)
*/ */
protected int processUploadFile(Context context, HttpServletRequest request, public int processUploadFile(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo) HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException, throws ServletException, IOException, SQLException,
AuthorizeException AuthorizeException

View File

@@ -315,7 +315,7 @@ public class UploadWithEmbargoStep extends UploadStep
* UI-related code! (if STATUS_COMPLETE or 0 is returned, * UI-related code! (if STATUS_COMPLETE or 0 is returned,
* no errors occurred!) * no errors occurred!)
*/ */
protected int processUploadFile(Context context, HttpServletRequest request, public int processUploadFile(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo) HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException, throws ServletException, IOException, SQLException,
AuthorizeException AuthorizeException

View File

@@ -46,6 +46,7 @@ import org.dspace.submit.AbstractProcessingStep;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.util.Collections; import java.util.Collections;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.dspace.submit.step.UploadStep;
/** /**
* Submission Manager servlet for DSpace. Handles the initial submission of * Submission Manager servlet for DSpace. Handles the initial submission of
@@ -270,21 +271,47 @@ public class SubmissionController extends DSpaceServlet
} }
else else
{ {
// We got the complete file. Add the file to the // We got the complete file. Assemble it and store
// list of files that should be saved into the // it in the repository.
// request when the user clicks the next button.
log.debug("Going to assemble file chunks."); log.debug("Going to assemble file chunks.");
HttpSession session = request.getSession(false);
if (session != null) if (completedFile.length() > 0)
{ {
synchronized(mutex) String fileName = completedFile.getName();
String filePath = tempDir + File.separator + fileName;
// Read the temporary file
InputStream fileInputStream =
new BufferedInputStream(new FileInputStream(completedFile));
// to safely store the file in the repository
// we have to add it as a bitstream to the
// appropriate item (or to be specific its
// bundle). Instead of rewriting this code,
// we should use the same code, that's used for
// the "old" file upload (which is not using JS).
SubmissionInfo si = getSubmissionInfo(context, request);
UploadStep us = new UploadStep();
request.setAttribute(fileName + "-path", filePath);
request.setAttribute(fileName + "-inputstream", fileInputStream);
request.setAttribute(fileName + "-description", request.getParameter("description"));
int uploadResult = us.processUploadFile(context, request, response, si);
// cleanup our temporary file
if (!completedFile.delete())
{ {
if (session.getAttribute("assembled_files") == null) log.error("Unable to delete temporary file " + filePath);
{
session.setAttribute("assembled_files", new ArrayList<File>());
}
((List<File>) session.getAttribute("assembled_files")).add(completedFile);
} }
// We already assembled the complete file.
// In case of any error it won't help to
// reupload the last chunk. That makes the error
// handling realy easy:
if (uploadResult != UploadStep.STATUS_COMPLETE)
{
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
context.commit();
} }
return; return;
} }
@@ -1499,79 +1526,35 @@ public class SubmissionController extends DSpaceServlet
// Wrap multipart request to get the submission info // Wrap multipart request to get the submission info
wrapper = new FileUploadRequest(request); wrapper = new FileUploadRequest(request);
} }
HttpSession session = request.getSession(false); log.debug("Did not recoginze resumable upload, falling back to "
List<File> assembledFiles = null; + "simple upload.");
if (session != null) Enumeration fileParams = wrapper.getFileParameterNames();
while (fileParams.hasMoreElements())
{ {
synchronized(mutex) String fileName = (String) fileParams.nextElement();
File temp = wrapper.getFile(fileName);
//if file exists and has a size greater than zero
if (temp != null && temp.length() > 0)
{ {
assembledFiles = (List<File>) session.getAttribute("assembled_files"); // Read the temp file into an inputstream
if (assembledFiles != null) fileInputStream = new BufferedInputStream(
new FileInputStream(temp));
filePath = wrapper.getFilesystemName(fileName);
// cleanup our temp file
if (!temp.delete())
{ {
session.removeAttribute("assembled_files"); log.error("Unable to delete temporary file");
} }
}
}
if (assembledFiles != null)
{
log.debug("Recoginzed resumable upload, will assemble files...");
for (File file : assembledFiles) //save this file's info to request (for UploadStep class)
{ request.setAttribute(fileName + "-path", filePath);
if (file != null && file.length() > 0) request.setAttribute(fileName + "-inputstream", fileInputStream);
{ request.setAttribute(fileName + "-description", wrapper.getParameter("description"));
String fileName = file.getName();
// Read the temp file into an inputstream
fileInputStream = new BufferedInputStream(
new FileInputStream(file));
filePath = tempDir + File.separator + file.getName();
// cleanup our temp file
if (!file.delete())
{
log.error("Unable to delete temporary file " + filePath);
}
//save this file's info to request (for UploadStep class)
request.setAttribute(fileName + "-path", filePath);
request.setAttribute(fileName + "-inputstream", fileInputStream);
request.setAttribute(fileName + "-description", wrapper.getParameter("description"));
}
}
}
else // falling back to unresumable upload
{
log.debug("Did not recoginze resumable upload, falling back to "
+ "simple upload.");
Enumeration fileParams = wrapper.getFileParameterNames();
while (fileParams.hasMoreElements())
{
String fileName = (String) fileParams.nextElement();
File temp = wrapper.getFile(fileName);
//if file exists and has a size greater than zero
if (temp != null && temp.length() > 0)
{
// Read the temp file into an inputstream
fileInputStream = new BufferedInputStream(
new FileInputStream(temp));
filePath = wrapper.getFilesystemName(fileName);
// cleanup our temp file
if (!temp.delete())
{
log.error("Unable to delete temporary file");
}
//save this file's info to request (for UploadStep class)
request.setAttribute(fileName + "-path", filePath);
request.setAttribute(fileName + "-inputstream", fileInputStream);
request.setAttribute(fileName + "-description", wrapper.getParameter("description"));
}
} }
} }
} }

View File

@@ -41,6 +41,7 @@
//get submission information object //get submission information object
SubmissionInfo subInfo = SubmissionController.getSubmissionInfo(context, request); SubmissionInfo subInfo = SubmissionController.getSubmissionInfo(context, request);
request.setAttribute("submission.info", subInfo);
boolean withEmbargo = ((Boolean)request.getAttribute("with_embargo")).booleanValue(); boolean withEmbargo = ((Boolean)request.getAttribute("with_embargo")).booleanValue();
@@ -419,7 +420,8 @@
simultaneousUploads:1, simultaneousUploads:1,
testChunks: true, testChunks: true,
throttleProgressCallbacks:1, throttleProgressCallbacks:1,
method: "multipart" method: "multipart",
query:{workspace_item_id:'<%= subInfo.getSubmissionItem().getID()%>'}
}); });
// Resumable.js isn't supported, fall back on a different method // Resumable.js isn't supported, fall back on a different method