protected void doDSPost(Context context, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException,
SQLException, AuthorizeException
{
// Configuration of current step in Item Submission Process
SubmissionStepConfig currentStepConfig;
//need to find out what type of form we are dealing with
String contentType = request.getContentType();
// if multipart form, we have to wrap the multipart request
// in order to be able to retrieve request parameters, etc.
if ((contentType != null)
&& (contentType.indexOf("multipart/form-data") != -1))
{
try
{
request = wrapMultipartRequest(request);
// check if the POST request was send by resumable.js
String resumableFilename = request.getParameter("resumableFilename");
if (!StringUtils.isEmpty(resumableFilename))
{
log.debug("resumable Filename: '" + resumableFilename + "'.");
File completedFile = null;
try
{
log.debug("Starting doPostResumable method.");
completedFile = doPostResumable(request);
} catch(IOException e){
// we were unable to receive the complete chunk => initialize reupload
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
}
if (completedFile == null)
{
// if a part/chunk was uploaded, but the file is not completly uploaded yet
log.debug("Got one file chunk, but the upload is not completed yet.");
return;
}
else
{
// We got the complete file. Assemble it and store
// it in the repository.
log.debug("Going to assemble file chunks.");
if (completedFile.length() > 0)
{
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())
{
log.error("Unable to delete temporary file " + filePath);
}
// 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;
}
}
}
catch (FileSizeLimitExceededException e)
{
log.warn("Upload exceeded upload.max");
if (ConfigurationManager.getBooleanProperty("webui.submit.upload.progressbar", true))
{
Gson gson = new Gson();
// old browser need to see this response as html to work
response.setContentType("text/html");
JSONUploadResponse jsonResponse = new JSONUploadResponse();
jsonResponse.addUploadFileSizeLimitExceeded(
e.getActualSize(), e.getPermittedSize());
response.getWriter().print(gson.toJson(jsonResponse));
response.flushBuffer();
}
else
{
JSPManager.showFileSizeLimitExceededError(request, response, e.getMessage(), e.getActualSize(), e.getPermittedSize());
}
return;
}
//also, upload any files and save their contents to Request (for later processing by UploadStep)
uploadFiles(context, request);
}
// Reload submission info from request parameters
SubmissionInfo subInfo = getSubmissionInfo(context, request);
// a submission info object is necessary to continue
if (subInfo == null)
{
// Work around for problem where people select "is a thesis", see
// the error page, and then use their "back" button thinking they
// can start another submission - it's been removed so the ID in the
// form is invalid. If we detect the "removed_thesis" attribute we
// display a friendly message instead of an integrity error.
if (request.getSession().getAttribute("removed_thesis") != null)
{
request.getSession().removeAttribute("removed_thesis");
JSPManager.showJSP(request, response,
"/submit/thesis-removed-workaround.jsp");
return;
}
else
{
// If the submission info was invalid, throw an integrity error
log.warn(LogManager.getHeader(context, "integrity_error",
UIUtil.getRequestLogInfo(request)));
JSPManager.showIntegrityError(request, response);
return;
}
}
// First, check for a click on "Cancel/Save" button.
if (UIUtil.getSubmitButton(request, "").equals(AbstractProcessingStep.CANCEL_BUTTON))
{
// Get the current step
currentStepConfig = getCurrentStepConfig(request, subInfo);
// forward user to JSP which will confirm
// the cancel/save request.
doCancelOrSave(context, request, response, subInfo,
currentStepConfig);
}
// Special case - no InProgressSubmission yet
// If no submission, we assume we will be going
// to the "select collection" step.
else if (subInfo.getSubmissionItem() == null)
{
// we have just started this submission
// (or we have just resumed a saved submission)
// do the "Select Collection" step
doStep(context, request, response, subInfo, SELECT_COLLECTION);
}
else
// otherwise, figure out the next Step to call!
{
// Get the current step
currentStepConfig = getCurrentStepConfig(request, subInfo);
//if user already confirmed the cancel/save request
if (UIUtil.getBoolParameter(request, "cancellation"))
{
// user came from the cancel/save page,
// so we need to process that page before proceeding
processCancelOrSave(context, request, response, subInfo, currentStepConfig);
}
//check for click on "<- Previous" button
else if (UIUtil.getSubmitButton(request, "").startsWith(
AbstractProcessingStep.PREVIOUS_BUTTON))
{
// return to the previous step
doPreviousStep(context, request, response, subInfo, currentStepConfig);
}
//check for click on Progress Bar
else if (UIUtil.getSubmitButton(request, "").startsWith(
AbstractProcessingStep.PROGRESS_BAR_PREFIX))
{
// jumping to a particular step/page
doStepJump(context, request, response, subInfo, currentStepConfig);
}
else
{
// by default, load step class to start
// or continue its processing
doStep(context, request, response, subInfo, currentStepConfig.getStepNumber());
}
}
}