Examples of HLocale


Examples of org.zanata.model.HLocale

        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);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.