Examples of HTextFlow


Examples of org.zanata.model.HTextFlow

                "7.0", ProjectType.Podir), localeId));
        when(
                localeService.validateLocaleByProjectIteration(localeId,
                        "rhel", "7.0")).thenReturn(hLocale);
        when(hLocale.getId()).thenReturn(2L);
        HTextFlow hTextFlow = createHTextFlow();
        HTextFlowTarget currentTranslation =
                createTarget(new Date(), null, 0,
                        new HashMap<Integer, HTextFlowTargetHistory>());
        currentTranslation.setLastModifiedBy(null);
        hTextFlow.getTargets().put(hLocale.getId(), currentTranslation);

        when(textFlowDAO.findById(transUnitId.getId(), false)).thenReturn(
                hTextFlow);

        // When: number of plurals has changed to 1
        when(resourceUtils.getNumPlurals(hTextFlow.getDocument(), hLocale))
                .thenReturn(1);
        GetTranslationHistoryResult result =
                handler.execute(action, executionContext);

        // Then: the contents we get back is consistent against number of plural
View Full Code Here

Examples of org.zanata.model.HTextFlow

                Matchers.contains(currentTranslation.getContents().get(0)));
        assertThat(result.getLatest().getModifiedBy(), Matchers.equalTo(""));
    }

    private static HTextFlow createHTextFlow() {
        HTextFlow hTextFlow = new HTextFlow();
        HashMap<Long, HTextFlowTarget> targetMap = Maps.newHashMap();
        hTextFlow.setTargets(targetMap);
        hTextFlow.setPlural(true);
        return hTextFlow;
    }
View Full Code Here

Examples of org.zanata.model.HTextFlow

    private static HTextFlowTargetReviewComment makeCommentEntity(
            LocaleId localeId, String comment) {
        HLocale hLocale = new HLocale(localeId);
        TestFixture.setId(2L, hLocale);

        HTextFlow textFlow =
                TestFixture.makeHTextFlow(1L, hLocale, ContentState.Rejected);

        HPerson commenter = new HPerson();
        TestFixture.setId(3L, commenter);

        return new HTextFlowTargetReviewComment(textFlow.getTargets().get(
                hLocale.getId()), comment, commenter);
    }
View Full Code Here

Examples of org.zanata.model.HTextFlow

        when(translationResult.isTargetChanged()).thenReturn(true);
        when(translationResult.isTranslationSuccessful()).thenReturn(true);
        when(translationResult.getBaseContentState()).thenReturn(
                baseContentState);
        when(translationResult.getBaseVersionNum()).thenReturn(baseVersionNum);
        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(1, new HLocale(LocaleId.EN_US),
                        ContentState.Approved);
        HDocument spy = spy(new HDocument());
        when(spy.getId()).thenReturn(1L);
        hTextFlow.setDocument(spy);
        when(translationResult.getTranslatedTextFlowTarget()).thenReturn(
                new HTextFlowTarget(hTextFlow, new HLocale(LocaleId.DE)));

        return translationResult;
    }
View Full Code Here

Examples of org.zanata.model.HTextFlow

                .thenReturn(hLocale);
    }

    private HTextFlow textFlow(long id, String sourceContent,
            String targetContent) {
        HTextFlow hTextFlow =
                makeHTextFlow(id, hLocale, ContentState.NeedReview);
        TestFixture.setId(DOC_ID, hTextFlow.getDocument());
        hTextFlow.setContent0(sourceContent);
        if (targetContent != null) {
            hTextFlow.getTargets().get(hLocale.getId())
                    .setContent0(targetContent);
        }
        log.debug("text flow - id: {}, source : [{}], target: [{}]",
                new Object[] { id, sourceContent, targetContent });
        return hTextFlow;
View Full Code Here

Examples of org.zanata.model.HTextFlow

                new VersionLocaleKey(event.getProjectIterationId(),
                        event.getLocaleId());
        WordStatistic stats = versionStatisticCache.get(key);
        if (stats != null) {
            TextFlowDAO textFlowDAO = serviceLocator.getInstance(TextFlowDAO.class);
            HTextFlow textFlow = textFlowDAO.findById(event.getTextFlowId());

            stats.decrement(event.getPreviousState(),
                    textFlow.getWordCount().intValue());
            stats.increment(event.getNewState(),
                    textFlow.getWordCount().intValue());
            versionStatisticCache.put(key, stats);
        }
    }
View Full Code Here

Examples of org.zanata.model.HTextFlow

            return results;
        }

        // single locale check - assumes update requests are all from the same
        // project-iteration
        HTextFlow sampleHTextFlow =
                entityManager.find(HTextFlow.class, translationRequests.get(0)
                        .getTransUnitId().getValue());
        HProjectIteration projectIteration =
                sampleHTextFlow.getDocument().getProjectIteration();
        HLocale hLocale = validateLocale(localeId, projectIteration);

        // single permission check - assumes update requests are all from same
        // project
        validateReviewPermissionIfApplicable(translationRequests,
                projectIteration, hLocale);

        for (TransUnitUpdateRequest request : translationRequests) {
            HTextFlow hTextFlow =
                    entityManager.find(HTextFlow.class, request
                            .getTransUnitId().getValue());

            TranslationResultImpl result = new TranslationResultImpl();

            if (runValidation) {
                String validationMessage =
                        validateTranslations(request.getNewContentState(),
                                projectIteration, request.getTransUnitId()
                                        .toString(), hTextFlow.getContents(),
                                request.getNewContents());

                if (!StringUtils.isEmpty(validationMessage)) {
                    log.warn(validationMessage);
                    result.isSuccess = false;
                    result.errorMessage = validationMessage;
                    continue;
                }
            }

            HTextFlowTarget hTextFlowTarget =
                    textFlowTargetDAO.getOrCreateTarget(hTextFlow, hLocale);
            // if hTextFlowTarget is created, any further hibernate fetch will
            // trigger an implicit flush
            // (which will save this target even if it's not fully ready!!!)
            if (request.hasTargetComment()) {
                // FIXME this creates orphan comments, and replaces identical
                // comments with copies
                hTextFlowTarget.setComment(new HSimpleComment(request
                        .getTargetComment()));
            }

            result.baseVersion = hTextFlowTarget.getVersionNum();
            result.baseContentState = hTextFlowTarget.getState();

            if (request.getBaseTranslationVersion() == hTextFlowTarget
                    .getVersionNum()) {
                try {
                    int nPlurals = getNumPlurals(hLocale, hTextFlow);
                    result.targetChanged =
                            translate(hTextFlowTarget,
                                    request.getNewContents(),
                                    request.getNewContentState(), nPlurals,
                                    projectIteration
                                            .getRequireTranslationReview());
                    result.isSuccess = true;
                } catch (HibernateException e) {
                    result.isSuccess = false;
                    log.warn("HibernateException while translating");
                }
            } else {
                // concurrent edits not allowed
                String errorMessage =
                        "translation failed for textflow " + hTextFlow.getId()
                                + ": base versionNum + "
                                + request.getBaseTranslationVersion()
                                + " does not match current versionNum "
                                + hTextFlowTarget.getVersionNum();
View Full Code Here

Examples of org.zanata.model.HTextFlow

     * Sends out an event to signal that a Text Flow target has been translated
     */
    private void signalPostTranslateEvent(Long actorId,
            HTextFlowTarget hTextFlowTarget, ContentState oldState) {
        if (Events.exists()) {
            HTextFlow textFlow = hTextFlowTarget.getTextFlow();
            Long documentId = textFlow.getDocument().getId();
            Long versionId =
                    textFlow.getDocument().getProjectIteration().getId();
            // TODO remove hasError from DocumentStatus, so that we can pass
            // everything else directly to cache
            // DocumentStatus docStatus = new DocumentStatus(
            // new DocumentId(document.getId(), document.getDocId()), hasError,
            // hTextFlowTarget.getLastChanged(),
            // hTextFlowTarget.getLastModifiedBy().getAccount().getUsername());
            Events.instance().raiseTransactionSuccessEvent(
                    TextFlowTargetStateEvent.EVENT_NAME,
                    new TextFlowTargetStateEvent(actorId, versionId,
                            documentId, textFlow.getId(), hTextFlowTarget
                                    .getLocale().getLocaleId(), hTextFlowTarget
                                    .getId(), hTextFlowTarget.getState(),
                            oldState));
        }
    }
View Full Code Here

Examples of org.zanata.model.HTextFlow

        targetChanged |=
                setContentStateIfChanged(requestedState, hTextFlowTarget,
                        nPlurals, requireTranslationReview);

        if (targetChanged || hTextFlowTarget.getVersionNum() == 0) {
            HTextFlow textFlow = hTextFlowTarget.getTextFlow();
            hTextFlowTarget.setVersionNum(hTextFlowTarget.getVersionNum() + 1);
            hTextFlowTarget.setTextFlowRevision(textFlow.getRevision());
            hTextFlowTarget.setLastModifiedBy(authenticatedAccount.getPerson());
            log.debug("last modified by :{}", authenticatedAccount.getPerson()
                    .getName());
        }
View Full Code Here

Examples of org.zanata.model.HTextFlow

        List<TranslationResult> results = new ArrayList<TranslationResult>();
        List<TransUnitUpdateRequest> updateRequests =
                new ArrayList<TransUnitUpdateRequest>();
        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;
                }

                TransUnitId tuId = info.getTransUnit().getId();
                HTextFlow hTextFlow =
                        entityManager.find(HTextFlow.class, tuId.getValue());
                HTextFlowTarget hTextFlowTarget =
                        textFlowTargetDAO.getOrCreateTarget(hTextFlow, hLocale);

                // check that version has not advanced
                // TODO probably also want to check that source has not been
                // updated
                Integer versionNum = hTextFlowTarget.getVersionNum();
                log.debug(
                        "about to revert hTextFlowTarget version {} to TransUnit version {}",
                        versionNum, info.getTransUnit().getVerNum());
                if (versionNum.equals(info.getTransUnit().getVerNum())) {
                    // look up replaced version
                    HTextFlowTargetHistory oldTarget =
                            hTextFlowTarget.getHistory().get(
                                    info.getPreviousVersionNum());
                    if (oldTarget != null) {
                        // generate request
                        List<String> oldContents = oldTarget.getContents();
                        ContentState oldState = oldTarget.getState();
                        TransUnitUpdateRequest request =
                                new TransUnitUpdateRequest(tuId, oldContents,
                                        oldState, versionNum);
                        // add to list
                        updateRequests.add(request);
                    } else {
                        log.info(
                                "got null previous target for tu with id {}, version {}. Assuming previous state is untranslated",
                                hTextFlow.getId(), info.getPreviousVersionNum());
                        List<String> emptyContents = Lists.newArrayList();
                        for (int i = 0; i < hTextFlowTarget.getContents()
                                .size(); i++) {
                            emptyContents.add("");
                        }
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.