Package org.zanata.exception

Examples of org.zanata.exception.ZanataServiceException


            try {
                doc =
                        adapter.parseDocumentFile(documentFile, new LocaleId(
                                "en"), params);
            } catch (FileFormatAdapterException e) {
                throw new ZanataServiceException(
                        "Error parsing document file: " + fileName, e);
            }
            doc.setName(docId);
            return doc;
        } else {
            throw new ZanataServiceException("Unsupported Document file: "
                    + fileName);
        }
    }
View Full Code Here


            while ((bytesRead = fileContents.read(buffer)) != -1) {
                output.write(buffer, 0, bytesRead);
            }
            output.close();
        } catch (IOException e) {
            throw new ZanataServiceException(
                    "Error while writing uploaded file to temporary location",
                    e);
        }
        return tempFile;
    }
View Full Code Here

            AsyncTaskHandle handle) {
        final HProjectIteration hProjectIteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);

        if (hProjectIteration == null) {
            throw new ZanataServiceException("Version '" + iterationSlug
                    + "' for project '" + projectSlug + "' ");
        }

        if (mergeType == MergeType.IMPORT) {
            identity.checkPermission("import-translation", hProjectIteration);
        }

        ResourceUtils.validateExtensions(extensions);

        log.debug("pass evaluate");
        final HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, docId);
        if (document == null || document.isObsolete()) {
            throw new ZanataServiceException("A document was not found.", 404);
        }

        log.debug("start put translations entity:{}", translations);

        boolean changed = false;

        final HLocale hLocale =
                localeServiceImpl.validateLocaleByProjectIteration(locale,
                        projectSlug, iterationSlug);
        final Optional<AsyncTaskHandle> handleOp =
                Optional.fromNullable(handle);

        if (handleOp.isPresent()) {
            handleOp.get().setMaxProgress(
                    translations.getTextFlowTargets().size());
        }

        try {
            changed |= new Work<Boolean>() {
                @Override
                protected Boolean work() throws Exception {
                    // handle extensions
                    boolean changed =
                            resourceUtils
                                    .transferFromTranslationsResourceExtensions(
                                            translations.getExtensions(true),
                                            document, extensions, hLocale,
                                            mergeType);
                    return changed;
                }
            }.workInTransaction();
        } catch (Exception e) {
            throw new ZanataServiceException("Error during translation.", 500,
                    e);
        }

        // NB: removedTargets only applies for MergeType.IMPORT
        final Collection<HTextFlowTarget> removedTargets =
                new HashSet<HTextFlowTarget>();
        final List<String> warnings = new ArrayList<String>();

        if (mergeType == MergeType.IMPORT) {
            for (HTextFlow textFlow : document.getTextFlows()) {
                HTextFlowTarget hTarget =
                        textFlow.getTargets().get(hLocale.getId());
                if (hTarget != null) {
                    removedTargets.add(hTarget);
                }
            }
        }

        // Break the target into batches
        List<List<TextFlowTarget>> batches =
                Lists.partition(translations.getTextFlowTargets(), BATCH_SIZE);

        for (final List<TextFlowTarget> batch : batches) {
            try {
                SaveBatchWork work = new SaveBatchWork();
                work.setExtensions(extensions);
                work.setWarnings(warnings);
                work.setLocale(hLocale);
                work.setDocument(document);
                work.setMergeType(mergeType);
                work.setRemovedTargets(removedTargets);
                work.setHandleOp(handleOp);
                work.setProjectIterationId(hProjectIteration.getId());
                work.setBatch(batch);
                changed |= work.workInTransaction();
            } catch (Exception e) {
                throw new ZanataServiceException("Error during translation.",
                        500, e);
            }

        }

        if (changed || !removedTargets.isEmpty()) {
            try {
                new Work<Void>() {
                    @Override
                    protected Void work() throws Exception {
                        for (HTextFlowTarget target : removedTargets) {
                            target =
                                    textFlowTargetDAO.findById(target.getId(),
                                            true); // need to refresh from
                                                   // persistence
                            target.clear();
                        }
                        textFlowTargetDAO.flush();

                        documentDAO.flush();
                        return null;
                    }
                }.workInTransaction();

                if (Events.exists()) {
                    Long actorId = authenticatedAccount.getPerson().getId();
                    Events.instance().raiseEvent(
                            DocumentUploadedEvent.EVENT_NAME,
                            new DocumentUploadedEvent(actorId,
                                    document.getId(), false, hLocale
                                            .getLocaleId()));
                }
            } catch (Exception e) {
                throw new ZanataServiceException("Error during translation.",
                        500, e);
            }
        }

        return warnings;
View Full Code Here

    }

    @Override
    public ReindexStatus getReindexStatus() {
        if (searchIndexManager.getProcessHandle().isDone()) {
            throw new ZanataServiceException(
                    "Reindexing not in currently in progress", 404);
        }

        ReindexStatus status = new ReindexStatus();
        status.setCurrentElementType(searchIndexManager.getCurrentClassName());
View Full Code Here

        when(
                localeServiceImpl.validateLocaleByProjectIteration(
                        workspaceId.getLocaleId(),
                        projectIterationId.getProjectSlug(),
                        projectIterationId.getIterationSlug())).thenThrow(
                new ZanataServiceException("test"));

        handler.execute(action, null);
    }
View Full Code Here

        when(
                localeServiceImpl.validateLocaleByProjectIteration(
                        workspaceId.getLocaleId(),
                        projectIterationId.getProjectSlug(),
                        projectIterationId.getIterationSlug())).thenThrow(
                new ZanataServiceException("test"));

        handler.execute(action, null);
    }
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.