Package org.zanata.model

Examples of org.zanata.model.HTextFlowTarget


        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
        assertThat(result.getHistoryItems(),
                Matchers.<TransHistoryItem> emptyIterable());
        assertThat(result.getLatest().getVersionNum(),
                Matchers.equalTo(currentTranslation.getVersionNum().toString()));
        assertThat(result.getLatest().getContents(),
                Matchers.contains(currentTranslation.getContents().get(0)));
        assertThat(result.getLatest().getModifiedBy(), Matchers.equalTo(""));
    }
View Full Code Here


    }

    private static HTextFlowTarget createTarget(Date lastChanged,
            String lastModifiedPerson, Integer versionNum,
            @NotNull Map<Integer, HTextFlowTargetHistory> historyMap) {
        HTextFlowTarget target = new HTextFlowTarget();
        target.setLastChanged(lastChanged);
        HPerson person = new HPerson();
        person.setName(lastModifiedPerson);
        target.setLastModifiedBy(person);
        target.setVersionNum(versionNum);
        target.setHistory(historyMap);
        target.setContents("a", "b");
        return target;
    }
View Full Code Here

                        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

            ContentState.Rejected.toString()));

    @Override
    public TransMemoryDetails
            getTransMemoryDetail(HLocale hLocale, HTextFlow tf) {
        HTextFlowTarget tft = tf.getTargets().get(hLocale.getId());

        String iterationName = tf.getDocument().getProjectIteration().getSlug();
        String projectName =
                tf.getDocument().getProjectIteration().getProject().getName();
        String msgContext =
                (tf.getPotEntryData() == null) ? null : tf.getPotEntryData()
                        .getContext();
        String username = null;
        if (tft.getLastModifiedBy() != null
                && tft.getLastModifiedBy().hasAccount()) {
            username = tft.getLastModifiedBy().getAccount().getUsername();
        }
        return new TransMemoryDetails(HSimpleComment.toString(tf.getComment()),
                HSimpleComment.toString(tft.getComment()), projectName,
                iterationName, tf.getDocument().getDocId(), tf.getResId(),
                msgContext, tft.getState(), username, tft.getLastChanged());
    }
View Full Code Here

    private void processIndexMatch(TransMemoryQuery transMemoryQuery,
            Map<TMKey, TransMemoryResultItem> matchesMap, Object[] match,
            LocaleId sourceLocaleId, LocaleId targetLocaleId) {
        Object entity = match[1];
        if (entity instanceof HTextFlowTarget) {
            HTextFlowTarget textFlowTarget = (HTextFlowTarget) entity;

            ArrayList<String> textFlowContents =
                    Lists.newArrayList(textFlowTarget.getTextFlow()
                            .getContents());
            ArrayList<String> targetContents =
                    Lists.newArrayList(textFlowTarget.getContents());
            TransMemoryResultItem.MatchType matchType =
                    fromContentState(textFlowTarget.getState());
            addOrIncrementResultItem(transMemoryQuery, matchesMap, match,
                    matchType, textFlowContents, targetContents, textFlowTarget
                            .getTextFlow().getId(), "");
        } else if (entity instanceof TransMemoryUnit) {
            TransMemoryUnit transUnit = (TransMemoryUnit) entity;
            ArrayList<String> sourceContents =
                    Lists.newArrayList(transUnit.getTransUnitVariants()
View Full Code Here

                        continue scanning_text_flows;
                    }
                }
            }
            if (constraints.isSearchInTarget()) {
                HTextFlowTarget tft = tf.getTargets().get(localeId);
                if (tft != null) {
                    for (String content : tft.getContents()) {
                        if (content.contains(search)) {
                            matchingTextFlows.add(tf);
                            continue scanning_text_flows;
                        }
                    }
View Full Code Here

                    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();

                log.warn(errorMessage);
                result.errorMessage = errorMessage;
                result.isVersionNumConflict = true;
                result.isSuccess = false;
View Full Code Here

                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);
                }
            }
View Full Code Here

                }

                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("");
                        }
                        TransUnitUpdateRequest request =
                                new TransUnitUpdateRequest(tuId, emptyContents,
View Full Code Here

                        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) {
                        hTarget.setVersionNum(hTarget.getVersionNum() + 1);

                        changed = true;
                        Long actorId;
                        if (incomingTarget.getTranslator() != null) {
                            String email =
                                    incomingTarget.getTranslator().getEmail();
                            HPerson hPerson = personDAO.findByEmail(email);
                            if (hPerson == null) {
                                hPerson = new HPerson();
                                hPerson.setEmail(email);
                                hPerson.setName(incomingTarget.getTranslator()
                                        .getName());
                                personDAO.makePersistent(hPerson);
                            }
                            hTarget.setTranslator(hPerson);
                            hTarget.setLastModifiedBy(hPerson);
                            actorId = hPerson.getId();
                        } else {
                            hTarget.setTranslator(null);
                            hTarget.setLastModifiedBy(null);
                            actorId = null;
                        }
                        textFlowTargetDAO.makePersistent(hTarget);
                        signalPostTranslateEvent(actorId, hTarget, currentState);
                    }
View Full Code Here

TOP

Related Classes of org.zanata.model.HTextFlowTarget

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.