Package org.zanata.exception

Examples of org.zanata.exception.ZanataServiceException


        try {
            transRes =
                    getAdapterFor(fileName).parseTranslationFile(
                            tempFile.toURI(), localeId, params);
        } catch (FileFormatAdapterException e) {
            throw new ZanataServiceException("Error parsing translation file: "
                    + fileName, e);
        } catch (RuntimeException e) {
            throw new ZanataServiceException(e);
        }
        return transRes;
    }
View Full Code Here


            String fileName, boolean offlinePo) {
        if (fileName.endsWith(".pot")) {
            try {
                return parsePotFile(fileContents, docId, offlinePo);
            } catch (Exception e) {
                throw new ZanataServiceException(
                        "Invalid POT file contents on file: " + fileName, e);
            }
        } else {
            throw new ZanataServiceException("Unsupported Document file: "
                    + fileName);
        }
    }
View Full Code Here

    HLocale validateLocaleByProject(@Nonnull LocaleId locale,
            @Nonnull String project) throws ZanataServiceException {
        List<HLocale> allList = getSupportedLanguageByProject(project);
        HLocale hLocale = localeDAO.findByLocaleId(locale);
        if (hLocale == null || !hLocale.isActive()) {
            throw new ZanataServiceException("Locale " + locale.getId()
                    + " is not enabled on this server. Please contact admin.",
                    403);
        }
        if (!allList.contains(hLocale)) {
            throw new ZanataServiceException("Locale " + locale.getId()
                    + " is not allowed for project " + project
                    + ". Please contact project maintainer.", 403);
        }
        return hLocale;
    }
View Full Code Here

            throws ZanataServiceException {
        List<HLocale> allList =
                getSupportedLanguageByProjectIteration(project, iterationSlug);
        HLocale hLocale = localeDAO.findByLocaleId(locale);
        if (hLocale == null || !hLocale.isActive()) {
            throw new ZanataServiceException("Locale " + locale.getId()
                    + " is not enabled on this server. Please contact admin.",
                    403);
        }
        if (!allList.contains(hLocale)) {
            throw new ZanataServiceException("Locale " + locale.getId()
                    + " is not allowed for project " + project
                    + " and version " + iterationSlug
                    + ". Please contact project maintainer.", 403);
        }
        return hLocale;
View Full Code Here

    @Override
    public HLocale validateSourceLocale(LocaleId locale)
            throws ZanataServiceException {
        HLocale hLocale = getByLocaleId(locale);
        if (hLocale == null || !hLocale.isActive()) {
            throw new ZanataServiceException("Locale " + locale.getId()
                    + " is not enabled on this server. Please contact admin.",
                    403);
        }
        return hLocale;
    }
View Full Code Here

        try {
            hLocale =
                    localeServiceImpl.validateLocaleByProjectIteration(
                            localeId, projectSlug, iterationSlug);
        } catch (ZanataServiceException e) {
            throw new ZanataServiceException("Failed to validate locale", e);
        }

        if (!constraints.isSearchInSource() && !constraints.isSearchInTarget()) {
            // searching nowhere
            return Collections.emptyList();
View Full Code Here

                tgtContentPhraseQuery =
                        contentQueryParser.parse("\""
                                + QueryParser.escape(constraints
                                        .getSearchString()) + "\"");
            } catch (ParseException e) {
                throw new ZanataServiceException("Failed to parse query", e);
            }

            // Target Query
            BooleanQuery targetQuery = new BooleanQuery();
            targetQuery.add(projectQuery, Occur.MUST);
            targetQuery.add(iterationQuery, Occur.MUST);
            targetQuery.add(tgtContentPhraseQuery, Occur.MUST);
            if (documentsQuery.getTermArrays().size() > 0) {
                targetQuery.add(documentsQuery, Occur.MUST);
            }
            targetQuery.add(localeQuery, Occur.MUST);

            if (!constraints.getIncludedStates().hasTranslated()) {
                TermQuery approvedStateQuery =
                        new TermQuery(new Term(
                                IndexFieldLabels.CONTENT_STATE_FIELD,
                                ContentState.Approved.toString()));
                targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
            }

            if (!constraints.getIncludedStates().hasFuzzy()) {
                TermQuery approvedStateQuery =
                        new TermQuery(new Term(
                                IndexFieldLabels.CONTENT_STATE_FIELD,
                                ContentState.NeedReview.toString()));
                targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
            }

            if (!constraints.getIncludedStates().hasNew()) {
                TermQuery approvedStateQuery =
                        new TermQuery(new Term(
                                IndexFieldLabels.CONTENT_STATE_FIELD,
                                ContentState.New.toString()));
                targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
            }

            FullTextQuery ftQuery =
                    entityManager.createFullTextQuery(targetQuery,
                            HTextFlowTarget.class);
            @SuppressWarnings("unchecked")
            List<HTextFlowTarget> matchedTargets =
                    (List<HTextFlowTarget>) ftQuery.getResultList();
            log.info("got {} HTextFLowTarget results", matchedTargets.size());
            for (HTextFlowTarget htft : matchedTargets) {
                // manually check for case sensitive matches
                if (!constraints.isCaseSensitive()
                        || (contentIsValid(htft.getContents(), constraints))) {
                    if (!htft.getTextFlow().getDocument().isObsolete()) {
                        resultList.add(htft.getTextFlow());
                    }
                }
            }
        }

        if (constraints.isSearchInSource()) {
            // Source locale
            // NB: Assume the first document's locale, or the same target locale
            // if there are no documents
            // TODO Move source locale to the Project iteration level
            LocaleId sourceLocaleId = localeId;
            HProjectIteration projectIteration =
                    projectIterationDAO.getBySlug(projectSlug, iterationSlug);
            if (!projectIteration.getDocuments().isEmpty()) {
                sourceLocaleId =
                        projectIteration.getDocuments().values().iterator()
                                .next().getLocale().getLocaleId();
            }

            // Content query for source
            String sourceAnalyzerName =
                    TextContainerAnalyzerDiscriminator
                            .getAnalyzerDefinitionName(sourceLocaleId.getId());
            Analyzer sourceAnalyzer =
                    entityManager.getSearchFactory().getAnalyzer(
                            sourceAnalyzerName);

            Query srcContentPhraseQuery;
            QueryParser srcContentQueryParser =
                    new MultiFieldQueryParser(Version.LUCENE_29,
                            IndexFieldLabels.CONTENT_FIELDS, sourceAnalyzer);
            try {
                srcContentPhraseQuery =
                        srcContentQueryParser.parse("\""
                                + QueryParser.escape(constraints
                                        .getSearchString()) + "\"");
            } catch (ParseException e) {
                throw new ZanataServiceException("Failed to parse query", e);
            }

            // Source Query
            BooleanQuery sourceQuery = new BooleanQuery();
            sourceQuery.add(projectQuery, Occur.MUST);
View Full Code Here

        boolean alreadyJoined =
                localeMemberDAO.isLocaleMember(personId, localeId);
        HLocaleMember localeMember;
        if (!alreadyJoined) {
            if (currentPerson.getLanguageMemberships().size() >= MAX_NUMBER_MEMBERSHIP) {
                throw new ZanataServiceException(
                        "You can only be a member of up to "
                                + MAX_NUMBER_MEMBERSHIP
                                + " languages at one time.");
            }
            HLocale lang = localeDAO.findByLocaleId(localeId);
View Full Code Here

                return parseCsvFile(fileContents, commentsColumn);
            } else if (StringUtils.endsWithIgnoreCase(fileName, ".po")) {
                return parsePoFile(fileContents, sourceLang, transLang,
                        treatSourceCommentsAsTarget);
            } else {
                throw new ZanataServiceException("Unsupported Glossary file: "
                        + fileName);
            }
        } catch (Exception e) {
            throw new ZanataServiceException("Unsupported Glossary file: "
                    + fileName);
        }
    }
View Full Code Here

    private List<Glossary> parsePoFile(InputStream fileContents,
            LocaleId sourceLang, LocaleId transLang,
            boolean treatSourceCommentsAsTarget) throws IOException {
        if (sourceLang == null || transLang == null) {
            throw new ZanataServiceException(
                    "Mandatory fields for PO file format: Source Language and Target Language");
        }
        GlossaryPoReader poReader =
                new GlossaryPoReader(sourceLang, transLang,
                        treatSourceCommentsAsTarget, BATCH_SIZE);
View Full Code Here

TOP

Related Classes of org.zanata.exception.ZanataServiceException

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.