Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
split out method for combining upload to temp file
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jun 4, 2013
1 parent 63f2c6a commit 07d5367
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions zanata-war/src/main/java/org/zanata/rest/service/FileService.java
Expand Up @@ -378,31 +378,36 @@ private Response uploadSourcePartAndRespond(String projectSlug, String iteration
.build();
}

File tempFile = combineToTempFileAndDeleteUploadRecord(upload);

return processSourceUploadFromTempFileAndRespond(tempFile, projectSlug, iterationSlug, docId, uploadForm, upload.getParts().size());
}

private File combineToTempFileAndDeleteUploadRecord(HDocumentUpload upload)
{
File tempFile;
try
{
tempFile = combineToTempFile(upload);
}
catch (HashMismatchException e)
{
return Response.status(Status.CONFLICT)
.entity(new ChunkUploadResponse("MD5 hash \"" + e.getExpectedHash()
+ "\" sent with initial request does not match server-generated hash of combined parts \""
+ e.getGeneratedHash() + "\". Upload aborted. Retry upload from first part."))
.build();
throw new ChunkUploadException(Status.CONFLICT,
"MD5 hash \"" + e.getExpectedHash() + "\" sent with initial request does not match" +
" server-generated hash of combined parts \"" + e.getGeneratedHash() +
"\". Upload aborted. Retry upload from first part.");
}
catch (SQLException e)
{
log.error("Error while retreiving document upload part contents", e);
throw new RuntimeException(e);
throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
"Error while retreiving document upload part contents", e);
}
finally
{
// no more need for upload
session.delete(upload);
}

return processSourceUploadFromTempFileAndRespond(tempFile, projectSlug, iterationSlug, docId, uploadForm, upload.getParts().size());
return tempFile;
}

private Response processSourceUploadFromTempFileAndRespond(File tempFile, String projectSlug, String iterationSlug, String docId, DocumentFileUploadForm uploadForm, int uploadChunks)
Expand Down

0 comments on commit 07d5367

Please sign in to comment.