Package org.zanata.model

Examples of org.zanata.model.HTextFlow$EntityListener


        List<Object[]> results =
                textFlowDAO.getTextFlowAndTarget(idList, locale.getId());

        for (Object[] result : results) {
            HTextFlow textFlow = (HTextFlow) result[0];
            TransUnit tu;

            if (result.length < 2 || result[1] == null) {
                tu = transUnitUtils.buildTransUnitFull(textFlow, null,
                        locale.getLocaleId());
            }
            else {
                HTextFlowTarget textFlowTarget = (HTextFlowTarget) result[1];
                tu = transUnitUtils.buildTransUnitFull(textFlow,
                        textFlowTarget, locale.getLocaleId());
            }
            transUnits.put(textFlow.getId().toString(), tu);
        }

        return Response.ok(transUnits).build();
    }
View Full Code Here


        List<Object[]> results =
                textFlowDAO.getTextFlowAndTarget(idList, locale.getId());

        for (Object[] result : results) {
            HTextFlow hTextFlow = (HTextFlow) result[0];
            TransUnit tu;
            if (result.length < 2 || result[1] == null) {
                tu = transUnitUtils.buildTargetTransUnit(
                        hTextFlow, null, locale.getLocaleId());
            } else {
                HTextFlowTarget hTarget = (HTextFlowTarget) result[1];
                tu = transUnitUtils.buildTargetTransUnit(hTextFlow, hTarget,
                        locale.getLocaleId());
            }
            transUnits.put(hTextFlow.getId().toString(), tu);
        }

        return Response.ok(transUnits).build();
    }
View Full Code Here

    @Override
    public Response put(String localeId, TranslationData data) {
        TranslationData requestData = data;
        HLocale locale = localeDAO.findByLocaleId(new LocaleId(localeId));
        HTextFlow textFlow =
                textFlowDAO.findById(requestData.getId().longValue());

        if (textFlow == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

        identity.checkPermission("modify-translation",
                textFlow.getDocument().getProjectIteration().getProject(),
                locale);

        // //Only support 1 translation update for the moment
        TransUnitUpdateRequest request =
                new TransUnitUpdateRequest(new TransUnitId(requestData.getId()
View Full Code Here

                            .getProjectIterationId().getIterationSlug());
        } catch (ZanataServiceException e) {
            throw new ActionException(e);
        }

        HTextFlow hTextFlow =
                textFlowDAO.findById(action.getTransUnitId().getId(), false);

        HTextFlowTarget hTextFlowTarget =
                hTextFlow.getTargets().get(hLocale.getId());
        Map<Integer, HTextFlowTargetHistory> history = Maps.newHashMap();
        TransHistoryItem latest = null;
        if (hTextFlowTarget != null) {
            String lastModifiedBy =
                    nameOrEmptyString(hTextFlowTarget.getLastModifiedBy());
            int nPlurals =
                    resourceUtils.getNumPlurals(hTextFlow.getDocument(),
                            hLocale);

            latest =
                    new TransHistoryItem(hTextFlowTarget.getVersionNum()
                            .toString(),
View Full Code Here

                        Response.status(Status.BAD_REQUEST)
                                .entity("encountered TextFlow with duplicate ID "
                                        + tf.getId()).build();
                throw new WebApplicationException(response);
            }
            HTextFlow textFlow;
            if (previousIds.contains(tf.getId())) {
                previousIds.remove(tf.getId());
                textFlow = to.getAllTextFlows().get(tf.getId());
                textFlow.setObsolete(false);
                to.getTextFlows().add(textFlow);
                // avoid changing revision when resurrecting an unchanged TF
                if (transferFromTextFlow(tf, textFlow, enabledExtensions)) {// content
                                                                            // has
                                                                            // changed
                    textFlow.setRevision(nextDocRev);
                    changed = true;
                    for (HTextFlowTarget targ : textFlow.getTargets().values()) {
                        // if (targ.getState() != ContentState.New)
                        if (targ.getState().isTranslated()) {
                            targ.setState(ContentState.NeedReview);
                            targ.setVersionNum(targ.getVersionNum() + 1);
                        }
                    }
                    log.debug("TextFlow with id {} has changed", tf.getId());
                }
            } else {
                textFlow = new HTextFlow();
                textFlow.setDocument(to);
                textFlow.setResId(tf.getId());
                textFlow.setRevision(nextDocRev);
                transferFromTextFlow(tf, textFlow, enabledExtensions);
                changed = true;
                to.getAllTextFlows().put(textFlow.getResId(), textFlow);
                to.getTextFlows().add(textFlow);
                entityManager.persist(textFlow);
                log.debug("TextFlow with id {} is new", tf.getId());
            }
            count++;

            if (count % 100 == 0) {
                entityManager.flush();
            }
            // FIXME we can't clear entityManager here. See
            // org.zanata.feature.rest.CopyTransTest.testPushTranslationAndCopyTrans.
            // If you clear, last copyTran REST call will trigger exception on
            // the server (hDocument.getTextFlows() will contain null entries -
            // corrupted collection.
            // see https://github.com/zanata/zanata-server/pull/571#issuecomment-55547577)

            /*
            if (count % 500 == 0) {
            // this in some cases seem to slow down overall performance
                entityManager.clear();
                to = entityManager.find(HDocument.class, to.getId());
            }
            */
        }

        // set remaining textflows to obsolete.
        for (String id : previousIds) {
            HTextFlow textFlow = to.getAllTextFlows().get(id);
            if (!textFlow.isObsolete()) {
                changed = true;
                log.debug("TextFlow with id {} is now obsolete", id);
                textFlow.setRevision(to.getRevision());
                textFlow.setObsolete(true);
            }
        }
        if (changed)
            to.setRevision(nextDocRev);
        return changed;
View Full Code Here

    }

    private void prepareTransUnitUpdatedEvent(int previousVersionNum,
            ContentState previousState, HTextFlowTarget target) {
        LocaleId localeId = target.getLocaleId();
        HTextFlow textFlow = target.getTextFlow();
        HDocument document = textFlow.getDocument();
        HProjectIteration projectIteration = document.getProjectIteration();
        String iterationSlug = projectIteration.getSlug();
        String projectSlug = projectIteration.getProject().getSlug();
        ProjectType projectType = projectIteration.getProjectType();

        WorkspaceId workspaceId =
                new WorkspaceId(new ProjectIterationId(projectSlug,
                        iterationSlug, projectType), localeId);
        Optional<TranslationWorkspace> workspaceOptional =
                translationWorkspaceManager.tryGetWorkspace(workspaceId);
        if (!workspaceOptional.isPresent()) {
            return;
        }

        TransUnitTransformer transUnitTransformer =
                serviceLocator.getInstance(TransUnitTransformer.class);
        TransUnit transUnit =
                transUnitTransformer.transform(textFlow, target,
                        target.getLocale());

        DocumentId documentId =
                new DocumentId(document.getId(), document.getDocId());
        int wordCount = textFlow.getWordCount().intValue();

        TransUnitUpdateInfo updateInfo =
                createTransUnitUpdateInfo(transUnit, documentId, wordCount,
                        previousVersionNum, previousState);
View Full Code Here

    public String getAnalyzerDefinitionName(Object value, Object entity,
            String field) {
        LocaleId localeId;

        if (entity instanceof HTextFlow) {
            HTextFlow tf = (HTextFlow) entity;
            localeId = tf.getDocument().getLocale().getLocaleId();
        } else if (entity instanceof HTextFlowTarget) {
            HTextFlowTarget tft = (HTextFlowTarget) entity;
            localeId = tft.getLocale().getLocaleId();
        } else if (entity instanceof TransMemoryUnitVariant) {
            TransMemoryUnitVariant tuv = (TransMemoryUnitVariant) entity;
View Full Code Here

        action.setWorkspaceId(new WorkspaceId(new ProjectIterationId("rhel",
                "7.0", ProjectType.Podir), localeId));
        when(
                localeService.validateLocaleByProjectIteration(localeId,
                        "rhel", "7.0")).thenReturn(hLocale);
        HTextFlow hTextFlow = createHTextFlow();
        when(textFlowDAO.findById(transUnitId.getId(), false)).thenReturn(
                hTextFlow);
        assertThat(hTextFlow.getTargets().values(),
                Matchers.<HTextFlowTarget> emptyIterable());

        // When:
        GetTranslationHistoryResult result =
                handler.execute(action, executionContext);
View Full Code Here

                "7.0", ProjectType.Podir), localeId));
        when(
                localeService.validateLocaleByProjectIteration(localeId,
                        "rhel", "7.0")).thenReturn(hLocale);
        when(hLocale.getId()).thenReturn(2L);
        HTextFlow hTextFlow = createHTextFlow();
        // two history items
        HashMap<Integer, HTextFlowTargetHistory> history = Maps.newHashMap();
        history.put(
                0,
                createHistory(createTarget(new Date(), "smith", 0,
                        Maps.<Integer, HTextFlowTargetHistory> newHashMap())));
        history.put(
                1,
                createHistory(createTarget(new Date(), "john", 1,
                        Maps.<Integer, HTextFlowTargetHistory> newHashMap())));
        HTextFlowTarget currentTranslation =
                createTarget(new Date(), "admin", 2, history);
        hTextFlow.getTargets().put(hLocale.getId(), currentTranslation);

        when(resourceUtils.getNumPlurals(hTextFlow.getDocument(), hLocale))
                .thenReturn(2);
        when(textFlowDAO.findById(transUnitId.getId(), false)).thenReturn(
                hTextFlow);

        // When:
View Full Code Here

                "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(resourceUtils.getNumPlurals(hTextFlow.getDocument(), hLocale))
                .thenReturn(2);
        when(textFlowDAO.findById(transUnitId.getId(), false)).thenReturn(
                hTextFlow);

        // When:
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.