Package org.zanata.model

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


        if (!translationsToRevert.isEmpty()) {

            HTextFlow sampleHTextFlow =
                    entityManager.find(HTextFlow.class, translationsToRevert
                            .get(0).getTransUnit().getId().getValue());
            HLocale hLocale =
                    validateLocale(localeId, sampleHTextFlow.getDocument()
                            .getProjectIteration());
            for (TransUnitUpdateInfo info : translationsToRevert) {
                if (!info.isSuccess() || !info.isTargetChanged()) {
                    continue;
View Full Code Here

        String docId = sourceDoc.getName();

        HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, docId);
        HLocale hLocale =
                this.localeServiceImpl
                        .validateSourceLocale(sourceDoc.getLang());

        boolean changed = false;
        int nextDocRev;
        if (document == null) { // must be a create operation
            nextDocRev = 1;
            changed = true;
            // TODO check that entity name matches id parameter
            document =
                    new HDocument(sourceDoc.getName(),
                            sourceDoc.getContentType(), hLocale);
            document.setProjectIteration(hProjectIteration);
            hProjectIteration.getDocuments().put(docId, document);
            document = documentDAO.makePersistent(document);
        } else if (document.isObsolete()) { // must also be a create operation
            nextDocRev = document.getRevision() + 1;
            changed = true;
            document.setObsolete(false);
            // not sure if this is needed
            hProjectIteration.getDocuments().put(docId, document);
        } else { // must be an update operation
            nextDocRev = document.getRevision() + 1;
        }

        changed |=
                resourceUtils.transferFromResource(sourceDoc, document,
                        extensions, hLocale, nextDocRev);
        documentDAO.flush();

        long actorId = authenticatedAccount.getPerson().getId();
        if (changed) {
            if (Events.exists()) {
                Events.instance().raiseTransactionSuccessEvent(
                        DocumentUploadedEvent.EVENT_NAME,
                        new DocumentUploadedEvent(actorId, document.getId(),
                                true, hLocale.getLocaleId()));
            }
            clearStatsCacheForUpdatedDocument(document);
        }

        if (copyTrans && nextDocRev == 1) {
View Full Code Here

                throw new ZanataServiceException(
                        "You can only be a member of up to "
                                + MAX_NUMBER_MEMBERSHIP
                                + " languages at one time.");
            }
            HLocale lang = localeDAO.findByLocaleId(localeId);
            localeMember =
                    new HLocaleMember(currentPerson, lang, isTranslator,
                            isReviewer, isCoordinator);
            lang.getMembers().add(localeMember);
        } else {
            localeMember =
                    localeMemberDAO.findByPersonAndLocale(personId, localeId);
            localeMember.setTranslator(isTranslator);
            localeMember.setReviewer(isReviewer);
View Full Code Here

        localeMemberDAO.makePersistent(localeMember);
        localeMemberDAO.flush();
    }

    public boolean leaveLanguageTeam(String locale, Long personId) {
        HLocale lang = localeDAO.findByLocaleId(new LocaleId(locale));
        HPerson currentPerson = personDAO.findById(personId, false);
        final HLocaleMember membership =
                localeMemberDAO.findById(new HLocaleMemberPk(currentPerson,
                        lang), true);

        if (membership != null) {
            localeMemberDAO.makeTransient(membership);
            lang.getMembers().remove(membership);
            localeMemberDAO.flush();
            return true;
        }

        return false;
View Full Code Here

    public void checkWorkspaceAction(WorkspaceId workspaceId,
            TranslationAction translationAction)
            throws NoSuchWorkspaceException {
        HProject project = checkWorkspaceStatus(workspaceId);

        HLocale locale =
                localeServiceImpl.getByLocaleId(workspaceId.getLocaleId());

        identity.checkPermission(translationAction.action(), locale, project);
    }
View Full Code Here

                        getSrcGlossaryTerm(from));

        to.setSourceRef(from.getSourcereference());

        for (GlossaryTerm glossaryTerm : from.getGlossaryTerms()) {
            HLocale termHLocale =
                    localeServiceImpl.validateSourceLocale(glossaryTerm
                            .getLocale());

            // check if there's existing term with same content, overrides
            // comments
View Full Code Here

                glossaryDAO
                        .getEntryBySrcLocaleAndContent(srcLocale, srcContent);

        if (hGlossaryEntry == null) {
            hGlossaryEntry = new HGlossaryEntry();
            HLocale srcHLocale = localeServiceImpl.getByLocaleId(srcLocale);
            hGlossaryEntry.setSrcLocale(srcHLocale);
        }
        return hGlossaryEntry;
    }
View Full Code Here

        private List<HLocale> getLocalesToAppend() {
            return removeSourceLocale(getAllLocales());
        }

        private List<HLocale> removeSourceLocale(List<HLocale> locales) {
            HLocale source =
                    localeServiceImpl.getSourceLocale(projectSlug, versionSlug);
            locales.remove(source);
            return locales;
        }
View Full Code Here

            List<HLocale> iterationLocales =
                    localeServiceImpl.getSupportedLanguageByProjectIteration(
                        projectSlug, iterationSlug);
            localeIds = new LocaleId[iterationLocales.size()];
            for (int i = 0, iterationLocalesSize = iterationLocales.size(); i < iterationLocalesSize; i++) {
                HLocale loc = iterationLocales.get(i);
                localeIds[i] = loc.getLocaleId();
            }
        } else {
            localeIds = new LocaleId[locales.length];
            for (int i = 0; i < locales.length; i++) {
                localeIds[i] = new LocaleId(locales[i]);
View Full Code Here

TOP

Related Classes of org.zanata.model.HLocale

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.