Package org.zanata.model

Examples of org.zanata.model.HTextFlow$EntityListener


        dummyDoc.setDocId("dummy-doc");
        return dummyDoc;
    }

    private HTextFlow getDummyTextFlow() {
        HTextFlow dummyTf = new HTextFlow();
        dummyTf.setContents(Lists.newArrayList("dummy content"));
        dummyTf.setRevision(100);
     return dummyTf;
    }
View Full Code Here


        }
    }

    private void printTestData() {
        // single text flow with 4 targets
        HTextFlow textFlow = dao.findById(1L, false);
        log.info("text flow: {}", textFlow);
        for (Map.Entry<Long, HTextFlowTarget> entry : textFlow.getTargets()
                .entrySet()) {
            log.debug("locale id: {} - target state: {}", entry.getKey(), entry
                    .getValue().getState());
        }

        // 3 text flows with single en-US fuzzy target
        // List<HTextFlow> doc2TextFlows = dao.getTextFlowsByDocumentId(new
        // DocumentId(2L, ""), hLocale, 0, 9999);
        // for (HTextFlow doc2tf : doc2TextFlows)
        // {
        // log.debug("text flow id {} - targets {}", doc2tf.getId(),
        // doc2tf.getTargets());
        // }

        // single text flow no target
        HTextFlow textFlow6 = dao.findById(6L, false);
        log.debug("text flow {} target: {}", textFlow6.getId(),
                textFlow6.getTargets());

    }
View Full Code Here

                projectIterationDAO.getBySlug("same-project", "same-version");
        assert version != null;

        HDocument hDoc = version.getDocuments().get("/same/document0");

        HTextFlow textFlow = hDoc.getTextFlows().get(0);
        Optional<HTextFlowTarget> match =
                service.searchBestMatchTransMemory(textFlow,
                        LocaleId.DE,
                        hDoc.getSourceLocaleId(), true, true,
                        true);
View Full Code Here

        queryDoc.setLocale(sourceLocale);
        queryDoc.setProjectIteration(queryProjIter);
        queryDoc.setFullPath(execution.getDocument());

        // Create the text Flow
        HTextFlow queryTextFlow = new HTextFlow();
        // TODO test that the query textflow is excluded from results
        // (when the query textflow has been persisted and indexed)
        queryTextFlow.setId(-999L);
        queryTextFlow.setContents(execution.getContent()); // Source content matches
        queryTextFlow.setPlural(false);
        queryTextFlow.setObsolete(false);
        queryTextFlow.setDocument(queryDoc);
        queryTextFlow.setResId(execution.getContext());

        // For all the executions whose queries are expected to find a match,
        // the target which is expected to match is HTextFlowTarget 100
        // (which belongs to HTextFlow 100, HDocument 100,
        // HProjectIteration 100, HProject 100)

        Optional<HTextFlowTarget> matchingTarget =
                service.searchBestMatchTransMemory(
                        queryTextFlow, LocaleId.DE, LocaleId.EN_US,
                        execution.isCheckContext(), execution.isCheckDocument(),
                        execution.isCheckProject());

        assertThat(matchingTarget.isPresent()).as("match present").isEqualTo(
                execution.expectMatch());

        if (matchingTarget.isPresent()) {
            HTextFlowTarget target = matchingTarget.get();
            HTextFlow tf = target.getTextFlow();
            assertThat(target.getLocaleId()).isEqualTo(LocaleId.DE);
            assertThat(tf.getContents()).containsExactly(execution.getContent());

            if (execution.isCheckContext()) {
                assertThat(tf.getResId()).isEqualTo(execution.getContext());
            }

            if (execution.isCheckDocument()) {
                assertThat(tf.getDocument().getDocId()).isEqualTo(execution.getDocument());
            }

            if (execution.isCheckProject()) {
                assertThat(tf.getDocument().getProjectIteration().getProject().getSlug()).isEqualTo(
                        execution.getProject());
            }
        }

View Full Code Here

    public void translationChangesHash() throws Exception {
        testHashChange(new Function<HDocument, Void>() {
            @Override
            @Nullable
            public Void apply(@Nullable HDocument doc) {
                HTextFlow tf = doc.getTextFlows().get(0);
                HTextFlowTarget tft = tf.getTargets().get(as.getId());
                tft.setContent0("new Translation for as");
                return null;
            }
        }, true);
    }
View Full Code Here

    public void otherLangDoesNotChangeHash() throws Exception {
        testHashChange(new Function<HDocument, Void>() {
            @Override
            @Nullable
            public Void apply(@Nullable HDocument doc) {
                HTextFlow tf = doc.getTextFlows().get(0);
                HTextFlowTarget tft = tf.getTargets().get(de.getId());
                tft.setContent0("new Translation for de");
                return null;
            }
        }, false);
    }
View Full Code Here

    public void tftNewCommentChangesHash() throws Exception {
        testHashChange(new Function<HDocument, Void>() {
            @Override
            @Nullable
            public Void apply(@Nullable HDocument doc) {
                HTextFlow tf = doc.getTextFlows().get(0);
                HTextFlowTarget tft = tf.getTargets().get(as.getId());
                tft.setComment(new HSimpleComment("This is a new comment"));
                return null;
            }
        }, true);
    }
View Full Code Here

        // Given:
        // an action with threshold 80% and trans unit id is 1
        final long transUnitId = 1L;
        TransMemoryMerge action = prepareAction(80, transUnitId);

        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(transUnitId, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        when(textFlowDAO.findByIdList(newArrayList(transUnitId))).thenReturn(
                newArrayList(hTextFlow));
        // Given: there are three TM results returned for text flow id 1, and
        // the most matched one is text flow id 11
        HTextFlow tmResultSource =
                TestFixture.makeApprovedHTextFlow(11L, targetLocale);
        TransMemoryResultItem mostSimilarTM =
                tmResult(tmResultSource.getId(), 100);

        when(textFlowDAO.findById(tmResultSource.getId(), false)).thenReturn(
                tmResultSource);

        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);
View Full Code Here

    @Test
    public void willNotTranslateIfNoMatches() throws ActionException {
        final long transUnitId = 1L;
        TransMemoryMerge action = prepareAction(80, transUnitId);

        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(transUnitId, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        when(textFlowDAO.findByIdList(newArrayList(transUnitId))).thenReturn(
View Full Code Here

        final long idWith90MatchTM = 4L;
        TransMemoryMerge action =
                prepareAction(90, idWith100MatchTM, idWithoutTM,
                        idWith80MatchTM, idWith90MatchTM);

        HTextFlow textFlow100TM =
                TestFixture.makeHTextFlow(idWith100MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        HTextFlow textFlowNoTM =
                TestFixture.makeHTextFlow(idWithoutTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        HTextFlow textFlow80TM =
                TestFixture.makeHTextFlow(idWith80MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        HTextFlow textFLow90TM =
                TestFixture.makeHTextFlow(idWith90MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);

        when(
                textFlowDAO.findByIdList(newArrayList(idWith100MatchTM,
                        idWithoutTM, idWith80MatchTM, idWith90MatchTM)))
                .thenReturn(
                        newArrayList(textFlow100TM, textFlowNoTM, textFlow80TM,
                                textFLow90TM));
        // Given: TM results
        HTextFlow tmResultSource =
                TestFixture.makeApprovedHTextFlow(11L, targetLocale);

        Optional<TransMemoryResultItem> tm100 =
                Optional.of(tmResult(tmResultSource.getId(), 100));
        Optional<TransMemoryResultItem> tm90 =
                Optional.of(tmResult(tmResultSource.getId(), 90));
        Optional<TransMemoryResultItem> tm80 =
                Optional.of(tmResult(tmResultSource.getId(), 80));
        Optional<TransMemoryResultItem> noMatch = Optional.absent();

        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlow100TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm100);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFLow90TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm90);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlow80TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm80);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlowNoTM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(noMatch);

        when(textFlowDAO.findById(tmResultSource.getId(), false)).thenReturn(
                tmResultSource);
        // Given: tm detail of text flow id 11
        when(
                translationMemoryService.getTransMemoryDetail(targetLocale,
                        tmResultSource)).thenReturn(tmDetail());
View Full Code Here

TOP

Related Classes of org.zanata.model.HTextFlow$EntityListener

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.