Package org.zanata.exception

Examples of org.zanata.exception.ChunkUploadException


            throws ChunkUploadException {
        String fileType = uploadForm.getFileType();
        if (!fileType.equals(".po")
                && !translationFileServiceImpl.hasAdapterFor(DocumentType
                        .typeFor(fileType))) {
            throw new ChunkUploadException(Status.BAD_REQUEST, "The type \""
                    + fileType + "\" specified in form parameter 'type' "
                    + "is not valid for a translation file on this server.");
        }
    }
View Full Code Here


    private void failIfTranslationUploadNotAllowed(GlobalDocumentId id,
            String localeId) throws ChunkUploadException {
        HLocale locale = findHLocale(localeId);
        if (!isTranslationUploadAllowed(id, locale)) {
            throw new ChunkUploadException(Status.FORBIDDEN,
                    "You do not have permission to upload translations for locale \""
                            + localeId + "\" to project-version \""
                            + id.getProjectSlug() + ":" + id.getVersionSlug()
                            + "\".");
        }
View Full Code Here

    private HLocale findHLocale(String localeString) {
        LocaleId localeId;
        try {
            localeId = new LocaleId(localeString);
        } catch (IllegalArgumentException e) {
            throw new ChunkUploadException(Status.BAD_REQUEST,
                    "Invalid value for locale", e);
        }

        HLocale locale = localeDAO.findByLocaleId(localeId);
        if (locale == null) {
            throw new ChunkUploadException(Status.NOT_FOUND,
                    "The specified locale \"" + localeString
                            + "\" does not exist on this server.");
        }
        return locale;
    }
View Full Code Here

    }

    private void failIfSourceUploadNotAllowed(GlobalDocumentId id)
            throws ChunkUploadException {
        if (!isDocumentUploadAllowed(id)) {
            throw new ChunkUploadException(Status.FORBIDDEN,
                    "You do not have permission to upload source documents to project-version \""
                            + id.getProjectSlug() + ":" + id.getVersionSlug()
                            + "\".");
        }
    }
View Full Code Here

    private void failIfFileTypeNotValid(DocumentFileUploadForm uploadForm)
            throws ChunkUploadException {
        DocumentType type = DocumentType.typeFor(uploadForm.getFileType());
        if (!isSourceDocumentType(type)) {
            throw new ChunkUploadException(Status.BAD_REQUEST, "The type \""
                    + uploadForm.getFileType()
                    + "\" specified in form parameter 'type' "
                    + "is not valid for a source file on this server.");
        }
    }
View Full Code Here

                        + id.getDocId();
        try {
            virusScanner.scan(tempFile, name);
        } catch (VirusDetectedException e) {
            log.warn("File failed virus scan: {}", e.getMessage());
            throw new ChunkUploadException(Status.BAD_REQUEST,
                    "Uploaded file did not pass virus scan");
        }

        HDocument document;
        Optional<String> params;
        params =
                Optional.fromNullable(Strings.emptyToNull(uploadForm
                        .getAdapterParams()));
        if (!params.isPresent()) {
            params =
                    documentDAO.getAdapterParams(id.getProjectSlug(),
                            id.getVersionSlug(), id.getDocId());
        }
        try {
            Resource doc =
                    translationFileServiceImpl.parseUpdatedAdapterDocumentFile(
                            tempFile.toURI(), id.getDocId(),
                            uploadForm.getFileType(), params);
            doc.setLang(LocaleId.EN_US);
            // TODO Copy Trans values
            document =
                    documentServiceImpl.saveDocument(id.getProjectSlug(),
                            id.getVersionSlug(), doc,
                            Collections.<String> emptySet(), false);
        } catch (SecurityException e) {
            throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
                    e.getMessage(), e);
        } catch (ZanataServiceException e) {
            throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR,
                    e.getMessage(), e);
        }

        String contentHash = uploadForm.getHash();
        DocumentType documentType =
View Full Code Here

        response = null;
    }

    public void checksValidityAndFailsIfNotValid() {
        conf = defaultUpload().build();
        doThrow(new ChunkUploadException(NOT_ACCEPTABLE, "Test message")).when(
                documentUploadUtil).failIfUploadNotValid(conf.id,
                conf.uploadForm);
        response =
                transUpload.tryUploadTranslationFile(conf.id, ANY_LOCALE,
                        ANY_MERGETYPE, conf.uploadForm);
View Full Code Here

                .thenReturn(conf.hasImportTemplatePermission);
    }

    public void checksValidityAndFailsIfNotValid() {
        conf = defaultUpload().build();
        doThrow(new ChunkUploadException(NOT_ACCEPTABLE, "Test message")).when(
                documentUploadUtil).failIfUploadNotValid(conf.id,
                conf.uploadForm);
        response = sourceUpload.tryUploadSourceFile(conf.id, conf.uploadForm);
        assertResponseHasStatus(NOT_ACCEPTABLE);
        assertResponseHasErrorMessage("Test message");
View Full Code Here

        mockProjectAndVersionStatus();
        mockHasUploadPermission();
        mockHasPlainTextAdapter();

        doThrow(new ChunkUploadException(NOT_ACCEPTABLE, "Test message")).when(
                documentUploadUtil).persistTempFileFromUpload(conf.uploadForm);

        response = sourceUpload.tryUploadSourceFile(conf.id, conf.uploadForm);
        assertResponseHasErrorMessage("Test message");
        assertResponseHasStatus(NOT_ACCEPTABLE);
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.