HDocumentUpload upload =
util.saveUploadPart(id, locale, uploadForm);
totalChunks = upload.getParts().size();
return Response
.status(Status.ACCEPTED)
.entity(new ChunkUploadResponse(upload.getId(),
totalChunks, true,
"Chunk accepted, awaiting remaining chunks."))
.build();
} else {
HDocumentUpload previousParts =
documentUploadDAO
.findById(uploadForm.getUploadId());
totalChunks = previousParts.getParts().size();
totalChunks++; // add final part
tempFile =
Optional.of(util
.combineToTempFileAndDeleteUploadRecord(
previousParts,
uploadForm));
}
}
TranslationsResource transRes;
if (uploadForm.getFileType().equals(".po")) {
InputStream poStream = getInputStream(tempFile, uploadForm);
transRes =
translationFileServiceImpl.parsePoFile(poStream,
id.getProjectSlug(), id.getVersionSlug(),
id.getDocId());
} else {
if (!tempFile.isPresent()) {
tempFile =
Optional.of(util
.persistTempFileFromUpload(uploadForm));
}
// FIXME this is misusing the 'filename' field. the method
// should probably take a
// type anyway
transRes =
translationFileServiceImpl.parseAdapterTranslationFile(
tempFile.get(), id.getProjectSlug(),
id.getVersionSlug(), id.getDocId(), localeId,
uploadForm.getFileType());
}
if (tempFile.isPresent()) {
tempFile.get().delete();
}
Set<String> extensions =
newExtensions(uploadForm.getFileType().equals(".po"));
// TODO useful error message for failed saving?
List<String> warnings =
translationServiceImpl.translateAllInDoc(
id.getProjectSlug(), id.getVersionSlug(),
id.getDocId(), locale.getLocaleId(), transRes,
extensions, mergeTypeFromString(mergeType));
return transUploadResponse(totalChunks, warnings);
} catch (FileNotFoundException e) {
log.error("failed to create input stream from temp file", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e)
.build();
} catch (ChunkUploadException e) {
return Response.status(e.getStatusCode())
.entity(new ChunkUploadResponse(e.getMessage())).build();
}
}