Package org.zanata.exception

Examples of org.zanata.exception.ChunkUploadException


        failIfVersionCannotAcceptUpload(id);
    }

    public void failIfHashNotPresent(DocumentFileUploadForm uploadForm) {
        if (isNullOrEmpty(uploadForm.getHash())) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Required form parameter 'hash' was not found.");
        }
    }
View Full Code Here


        }
    }

    private void failIfNotLoggedIn() throws ChunkUploadException {
        if (!identity.isLoggedIn()) {
            throw new ChunkUploadException(
                    Status.UNAUTHORIZED,
                    "Valid combination of username and "
                            + "api-key for this server were not included in the request.");
        }
    }
View Full Code Here

    private static void failIfRequiredParametersNullOrEmpty(
            GlobalDocumentId id, DocumentFileUploadForm uploadForm)
            throws ChunkUploadException {
        if (isNullOrEmpty(id.getDocId())) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Required query string parameter 'docId' was not found.");
        }

        if (uploadForm.getFileStream() == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Required form parameter 'file' containing file content was not found.");
        }

        if (uploadForm.getFirst() == null || uploadForm.getLast() == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Form parameters 'first' and 'last' must both be provided.");
        }

        if (isNullOrEmpty(uploadForm.getFileType())) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Required form parameter 'type' was not found.");
        }
    }
View Full Code Here

    }

    private void failIfUploadIdNotValidAndMatching(GlobalDocumentId id,
            DocumentFileUploadForm uploadForm) throws ChunkUploadException {
        if (uploadForm.getUploadId() == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Form parameter 'uploadId' must be provided when this is not the first part.");
        }

        HDocumentUpload upload =
                documentUploadDAO.findById(uploadForm.getUploadId());
        if (upload == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "No incomplete uploads found for uploadId '"
                            + uploadForm.getUploadId() + "'.");
        }
        if (!upload.getDocId().equals(id.getDocId())) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Supplied uploadId '" + uploadForm.getUploadId()
                            + "' in request is not valid for document '"
                            + id.getDocId() + "'.");
        }
    }
View Full Code Here

    }

    private static void failIfDocumentTypeNotRecognized(
            DocumentFileUploadForm uploadForm) throws ChunkUploadException {
        if (DocumentType.typeFor(uploadForm.getFileType()) == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Value '" + uploadForm.getFileType()
                            + "' is not a recognized document type.");
        }
    }
View Full Code Here

            throws ChunkUploadException {
        HProjectIteration projectIteration =
                projectIterationDAO.getBySlug(id.getProjectSlug(),
                        id.getVersionSlug());
        if (projectIteration == null) {
            throw new ChunkUploadException(Status.NOT_FOUND,
                    "The specified project-version \"" + id.getProjectSlug()
                            + ":" + id.getVersionSlug()
                            + "\" does not exist on this server.");
        }

        if (projectIteration.getProject().getStatus() != EntityStatus.ACTIVE) {
            throw new ChunkUploadException(Status.FORBIDDEN, "The project \""
                    + id.getProjectSlug()
                    + "\" is not active. Document upload is not allowed.");
        }

        if (projectIteration.getStatus() != EntityStatus.ACTIVE) {
            throw new ChunkUploadException(
                    Status.FORBIDDEN,
                    "The project-version \""
                            + id.getProjectSlug()
                            + ":"
                            + id.getVersionSlug()
View Full Code Here

            DocumentFileUploadForm finalPart) {
        File tempFile;
        try {
            tempFile = combineToTempFile(upload, finalPart);
        } catch (HashMismatchException e) {
            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) {
            throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
                    "Error while retrieving document upload part contents", e);
        } finally {
            // no more need for upload
            session.delete(upload);
        }
View Full Code Here

            tempFile =
                    translationFileServiceImpl.persistToTempFile(fileContents);
            String providedHash = uploadForm.getHash();
            checkAndUpdateHash(uploadForm, md, providedHash);
        } catch (NoSuchAlgorithmException e) {
            throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
                    "MD5 hash algorithm not available", e);
        }
        return tempFile;
    }
View Full Code Here

        String md5hash = new String(Hex.encodeHex(md.digest()));
        if (isNullOrEmpty(providedHash)) {
            // Web upload with no hash provided, use generated hash for metadata
            uploadForm.setHash(md5hash);
        } else if (!md5hash.equals(providedHash)) {
            throw new ChunkUploadException(Status.CONFLICT, "MD5 hash \""
                    + providedHash
                    + "\" sent with request does not match "
                    + "server-generated hash. Aborted upload operation.");
        }
    }
View Full Code Here

    }

    private void failIfDocumentDoesNotExist(GlobalDocumentId id)
            throws ChunkUploadException {
        if (util.isNewDocument(id)) {
            throw new ChunkUploadException(Status.NOT_FOUND,
                    "No document with id \"" + id.getDocId()
                            + "\" exists in project-version \""
                            + id.getProjectSlug() + ":" + id.getVersionSlug()
                            + "\".");
        }
View Full Code Here

TOP

Related Classes of org.zanata.exception.ChunkUploadException

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.