Package org.zanata.model

Examples of org.zanata.model.HTextFlow$EntityListener


            final int numPlurals = resourceUtils
                    .getNumPlurals(document, locale);
            for (TextFlowTarget incomingTarget : batch) {
                String resId = incomingTarget.getResId();
                String sourceHash = incomingTarget.getSourceHash();
                HTextFlow textFlow = resIdToTextFlowMap.get(resId);
                if (textFlow == null) {
                    // return warning for unknown resId to caller
                    String warning =
                            "Could not find TextFlow for TextFlowTarget "
                                    + resId + " with contents: "
                                    + incomingTarget.getContents();
                    warnings.add(warning);
                    log.warn("skipping TextFlowTarget with unknown resId: {}",
                            resId);
                } else if (sourceHash != null
                        && !sourceHash.equals(textFlow.getContentHash())) {
                    String warning =
                            MessageFormat
                                    .format("TextFlowTarget {0} may be obsolete; "
                                            + "associated source hash: {1}; "
                                            + "expected hash is {2} for source: {3}",
                                            resId, sourceHash,
                                            textFlow.getContentHash(),
                                            textFlow.getContents());
                    warnings.add(warning);
                    log.warn(
                            "skipping TextFlowTarget {} with unknown sourceHash: {}",
                            resId, sourceHash);
                } else {
                    String validationMessage =
                            validateTranslations(incomingTarget.getState(),
                                    iteration,
                                    incomingTarget.getResId(),
                                    textFlow.getContents(),
                                    incomingTarget.getContents());

                    if (!StringUtils.isEmpty(validationMessage)) {
                        warnings.add(validationMessage);
                        log.warn(validationMessage);
                        continue;
                    }

                    int nPlurals = textFlow.isPlural() ? numPlurals : 1;
                    // we have eagerly loaded all targets upfront
                    HTextFlowTarget hTarget = textFlow.getTargets().get(locale.getId());
                    ContentState currentState = ContentState.New;
                    if (hTarget != null) {
                        currentState = hTarget.getState();
                    }

                    if (mergeType == MergeType.IMPORT) {
                        removedTargets.remove(hTarget);
                    }

                    TranslationMergeServiceFactory.MergeContext mergeContext =
                            new TranslationMergeServiceFactory.MergeContext(
                                    mergeType, textFlow, locale, hTarget,
                                    nPlurals);
                    TranslationMergeService mergeService =
                            translationMergeServiceFactory
                                    .getMergeService(mergeContext);

                    boolean targetChanged =
                            mergeService.merge(incomingTarget, hTarget,
                                    extensions);
                    if (hTarget == null) {
                        // in case hTarget was null, we need to
                        // retrieve it after merge
                        hTarget = textFlow.getTargets().get(locale.getId());
                    }
                    targetChanged |=
                            adjustContentsAndState(hTarget, nPlurals, warnings);
                    // update translation information if applicable
                    if (targetChanged) {
View Full Code Here


        List<HTextFlow> textFlows = textFlowDAO.getTextFlowsByDocumentId(
                documentId, batchStart, batchLength);

        HDocument newDocument = documentDAO.getById(newDocumentId);
        for (HTextFlow textFlow : textFlows) {
            HTextFlow newTextFlow =
                    copyVersionService.copyTextFlow(newDocument,
                            textFlow);

            newDocument.getTextFlows().add(newTextFlow);
            newDocument.getAllTextFlows()
                    .put(newTextFlow.getResId(), newTextFlow);
            tfMap.put(textFlow.getId(), newTextFlow);
        }
        documentDAO.makePersistent(newDocument);
        documentDAO.flush();
View Full Code Here

            doc.setFullPath("/different/document");
        }
        projectIteration.getDocuments().put(doc.getDocId(), doc);

        // Create the text Flow
        HTextFlow textFlow = new HTextFlow();
        textFlow.setContents("Source Content"); // Source content matches
        textFlow.setPlural(false);
        textFlow.setObsolete(false);
        textFlow.setDocument(doc);
        if (execution.contextMatches) {
            textFlow.setResId("same-context");
        } else {
            textFlow.setResId("different-context");
        }
        doc.getTextFlows().add(textFlow);

        projectIteration = iterationDAO.makePersistent(projectIteration);
        getEm().flush(); // So the rest of the test sees the results

        HCopyTransOptions options =
                new HCopyTransOptions(execution.getContextMismatchAction(),
                        execution.getDocumentMismatchAction(),
                        execution.getProjectMismatchAction());
        CopyTransService copyTransService =
                seam.autowire(CopyTransServiceImpl.class);
        copyTransService.copyTransForIteration(projectIteration, options,
                new CopyTransTaskHandle());
        getEm().flush();

        // Validate execution
        HTextFlow targetTextFlow =
                (HTextFlow) getEm()
                        .createQuery(
                                "from HTextFlow tf where tf.document.projectIteration = :projectIteration "
                                        + "and tf.document.docId = :docId and tf.resId = :resId")
                        .setParameter("projectIteration", projectIteration)
                        .setParameter("docId", doc.getDocId())
                        .setParameter("resId", textFlow.getResId())
                        .getSingleResult();
        // Id: 3L for Locale de
        HTextFlowTarget target = targetTextFlow.getTargets().get(3L);

        if (execution.isExpectUntranslated()) {
            if (target != null && target.getState() != ContentState.New) {
                throw new AssertionError(
                        "Expected untranslated text flow but got state "
View Full Code Here

        targetLocale = localeDAO.findByLocaleId(LocaleId.DE);
    }

    @Test
    public void testGetTransMemoryDetail() {
        HTextFlow hTextFlow =
                TestFixture.makeApprovedHTextFlow(1, sourceLocale);
        HPotEntryData potEntryData = new HPotEntryData();
        potEntryData.setContext("msgContext");
        hTextFlow.setPotEntryData(potEntryData);
        hTextFlow.getTargets().put(sourceLocale.getId(),
                addHTextFlowTarget(sourceLocale, hTextFlow, "admin"));
        setProjectAndIterationSlug(hTextFlow, "project", "master");

        TransMemoryDetails detail =
                service.getTransMemoryDetail(sourceLocale, hTextFlow);

        assertThat(detail.getMsgContext()).isEqualTo("msgContext");
        assertThat(detail.getProjectName()).isEqualTo("project");
        assertThat(detail.getIterationName()).isEqualTo("master");
        assertThat(detail.getDocId()).isEqualTo(
                hTextFlow.getDocument().getDocId());
        assertThat(detail.getLastModifiedBy()).isEqualTo("admin");
    }
View Full Code Here

    public void searchBestMatchTMTest() {
        TextFlowDAO textFlowDAO = seam.autowire(TextFlowDAO.class);

        // content0="Yet Another File removed" content1="%d files removed"
        // best matches has 83.33% similarity
        HTextFlow textFlow = textFlowDAO.findById(105L, false);
        assert textFlow != null;

        executeFindBestTMMatch(textFlow, 70, true);
        executeFindBestTMMatch(textFlow, 80, true);
        executeFindBestTMMatch(textFlow, 90, false);
View Full Code Here

    public void searchBestMatchTMTest2() {
        TextFlowDAO textFlowDAO = seam.autowire(TextFlowDAO.class);

        // content0="One file removed" content1="%d files removed"
        // best matches has 100% similarity
        HTextFlow textFlow = textFlowDAO.findById(101L, false);
        assert textFlow != null;

        executeFindBestTMMatch(textFlow, 80, true);
        executeFindBestTMMatch(textFlow, 90, true);
        executeFindBestTMMatch(textFlow, 100, true);
View Full Code Here

            boolean insertTargets) {
        LocaleDAO localeDAO = new LocaleDAO(getSession());
        List<HLocale> localeList = localeDAO.findAll();

        for (int i = 0; i < tfSize; i++) {
            HTextFlow tf =
                    new HTextFlowBuilder().withDocument(doc).withResId(
                            "testResId:" + i)
                            .withSourceContent("source content").build();

            if (insertTargets) {
                for (int x = 0; x < localeList.size(); x++) {
                    HTextFlowTarget tft =
                            new HTextFlowTarget(tf, localeList.get(x));
                    tft.setContents(Lists.newArrayList("test data"));
                    tf.getTargets().put(localeList.get(x).getId(), tft);
                }
            }
            doc.getAllTextFlows().put(tf.getResId(), tf);
        }
        documentDAO.makePersistent(doc);
        documentDAO.flush();
        return localeList.size();
    }
View Full Code Here

            assertThat(newDoc.getTextFlows().size()).isEqualTo(
                    existingDoc.getTextFlows().size());

            for (int i = 0; i < existingDoc.getTextFlows().size(); i++) {
                HTextFlow existingTf = existingDoc.getTextFlows().get(i);
                HTextFlow newTf = newDoc.getTextFlows().get(i);

                assertTextFlow(true, existingTf, newTf, newDoc);

                assertThat(newTf.getTargets().size()).isEqualTo(
                        existingTf.getTargets().size());
                for (Map.Entry<Long, HTextFlowTarget> targetSet : existingTf
                        .getTargets().entrySet()) {

                    HTextFlowTarget existingTarget = targetSet.getValue();
                    HTextFlowTarget newTarget = newTf
                            .getTargets().get(targetSet.getKey());

                    assertTextFlowTarget(existingTarget, newTarget, newTf);

                    for (int x = 0; x < existingTarget.getReviewComments()
View Full Code Here

    }

    @Test
    public void testCopyTextFlow() throws Exception {
        HDocument dummyDoc = getDummyDocument();
        HTextFlow existingTextFlow = textFlowDAO.findById(1L);
        HTextFlow newTextFlow =
                service.copyTextFlow(dummyDoc, existingTextFlow);

        assertTextFlow(false, existingTextFlow, newTextFlow, dummyDoc);
    }
View Full Code Here

        assertTextFlow(false, existingTextFlow, newTextFlow, dummyDoc);
    }

    @Test
    public void testCopyTextFlowTarget() throws Exception {
        HTextFlow dummyTextFlow = getDummyTextFlow();
        HTextFlowTarget existingTarget = textFlowTargetDAO.findById(3L, false);

        HTextFlowTarget newTarget =
                service.copyTextFlowTarget(dummyTextFlow, existingTarget);
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.