Package org.zanata.rest.dto

Examples of org.zanata.rest.dto.ChunkUploadResponse


            Optional<String> concurrentUploadError = Optional.of("failed: someone else is already uploading this file");

            try {
                DocumentFileUploadForm form = createUploadFormForItem(item);
                Response response = sourceUploader.tryUploadSourceFileWithoutHash(id, form);
                ChunkUploadResponse responseEntity = (ChunkUploadResponse) response.getEntity();
                errorMessage = optionalStringEmptyIsAbsent(responseEntity.getErrorMessage());
                successMessage = optionalStringEmptyIsAbsent(responseEntity.getSuccessMessage());
            } catch (IOException e) {
                errorMessage = Optional.of("could not access file data");
            } catch (OptimisticLockException e) {
                errorMessage = concurrentUploadError;
            } catch (StaleStateException e) {
View Full Code Here


                    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();
        }
    }
View Full Code Here

        return extensions;
    }

    private static Response transUploadResponse(int totalChunks,
            List<String> warnings) {
        ChunkUploadResponse response = new ChunkUploadResponse();
        response.setExpectingMore(false);
        response.setAcceptedChunks(totalChunks);
        if (warnings != null && !warnings.isEmpty()) {
            response.setSuccessMessage(buildWarningString(warnings));
        } else {
            response.setSuccessMessage("Translations uploaded successfully");
        }
        return Response.status(Status.OK).entity(response).build();
    }
View Full Code Here

            DocumentFileUploadForm uploadForm) {
        try {
            failIfSourceUploadNotValid(id, uploadForm);
        } catch (ChunkUploadException e) {
            return Response.status(e.getStatusCode())
                    .entity(new ChunkUploadResponse(e.getMessage())).build();
        }

        return tryValidatedUploadSourceFile(id, uploadForm);
    }
View Full Code Here

        try {
            failIfSourceUploadNotValid(id, uploadForm);
            util.failIfHashNotPresent(uploadForm);
        } catch (ChunkUploadException e) {
            return Response.status(e.getStatusCode())
                    .entity(new ChunkUploadResponse(e.getMessage())).build();
        }

        return tryValidatedUploadSourceFile(id, uploadForm);
    }
View Full Code Here

                HDocumentUpload upload =
                        util.saveUploadPart(id, NULL_LOCALE, uploadForm);
                totalChunks = upload.getParts().size();
                return Response
                        .status(Status.ACCEPTED)
                        .entity(new ChunkUploadResponse(upload.getId(),
                                totalChunks, true,
                                "Chunk accepted, awaiting remaining chunks."))
                        .build();
            }

            if (isSinglePart(uploadForm)) {
                totalChunks = 1;
                tempFile = Optional.<File> absent();
            } else {
                HDocumentUpload previousParts =
                        documentUploadDAO.findById(uploadForm.getUploadId());
                totalChunks = previousParts.getParts().size();
                totalChunks++; // add final part
                tempFile =
                        Optional.of(util
                                .combineToTempFileAndDeleteUploadRecord(
                                        previousParts,
                                        uploadForm));
            }

            if (DocumentType.typeFor(uploadForm.getFileType()) == DocumentType.GETTEXT_PORTABLE_OBJECT_TEMPLATE) {
                InputStream potStream = getInputStream(tempFile, uploadForm);
                parsePotFile(potStream, id, uploadForm);
            } else {
                if (!tempFile.isPresent()) {
                    tempFile =
                            Optional.of(util
                                    .persistTempFileFromUpload(uploadForm));
                }
                processAdapterFile(tempFile.get(), id, uploadForm);
            }
            if (tempFile.isPresent()) {
                tempFile.get().delete();
            }
            return sourceUploadSuccessResponse(util.isNewDocument(id),
                    totalChunks);
        } catch (ChunkUploadException e) {
            return Response.status(e.getStatusCode())
                    .entity(new ChunkUploadResponse(e.getMessage())).build();
        } catch (FileNotFoundException e) {
            log.error("failed to create input stream from temp file", e);
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e)
                    .build();
        }
View Full Code Here

    }

    private static Response sourceUploadSuccessResponse(boolean isNewDocument,
            int acceptedChunks) {
        Response response;
        ChunkUploadResponse uploadResponse = new ChunkUploadResponse();
        uploadResponse.setAcceptedChunks(acceptedChunks);
        uploadResponse.setExpectingMore(false);
        if (isNewDocument) {
            uploadResponse
                    .setSuccessMessage("Upload of new source document successful.");
            response =
                    Response.status(Status.CREATED).entity(uploadResponse)
                            .build();
        } else {
            uploadResponse
                    .setSuccessMessage("Upload of new version of source document successful.");
            response =
                    Response.status(Status.OK).entity(uploadResponse).build();
        }
        return response;
View Full Code Here

TOP

Related Classes of org.zanata.rest.dto.ChunkUploadResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.