Package org.zanata.model

Examples of org.zanata.model.HGlossaryEntry


        List<HGlossaryTerm> srcTerms = glossaryDAO.findByIdList(sourceIds);
        ArrayList<GlossaryDetails> items =
                new ArrayList<GlossaryDetails>(srcTerms.size());

        for (HGlossaryTerm srcTerm : srcTerms) {
            HGlossaryEntry entry = srcTerm.getGlossaryEntry();
            List<String> srcComments = new ArrayList<String>();
            List<String> targetComments = new ArrayList<String>();

            HGlossaryTerm hGlossaryTerm = entry.getGlossaryTerms().get(hLocale);
            for (HTermComment termComment : srcTerm.getComments()) {
                srcComments.add(termComment.getComment());
            }

            for (HTermComment termComment : hGlossaryTerm.getComments()) {
                targetComments.add(termComment.getComment());
            }

            items.add(new GlossaryDetails(srcTerm.getContent(), hGlossaryTerm
                    .getContent(), srcComments, targetComments, entry
                    .getSourceRef(), entry.getSrcLocale().getLocaleId(),
                    hLocale.getLocaleId(), hGlossaryTerm.getVersionNum(),
                    hGlossaryTerm.getLastChanged()));
        }

        return new GetGlossaryDetailsResult(items);
View Full Code Here


            ExecutionContext context) throws ActionException {
        identity.checkLoggedIn();

        GlossaryDetails selectedDetailEntry = action.getSelectedDetailEntry();

        HGlossaryEntry entry =
                glossaryDAO.getEntryBySrcLocaleAndContent(
                        selectedDetailEntry.getSrcLocale(),
                        selectedDetailEntry.getSource());

        HLocale targetLocale =
                localeServiceImpl.getByLocaleId(selectedDetailEntry
                        .getTargetLocale());

        HGlossaryTerm targetTerm = entry.getGlossaryTerms().get(targetLocale);
        if (targetTerm == null) {
            throw new ActionException(
                    "Update failed for glossary term with source content: "
                            + selectedDetailEntry.getSrcLocale()
                            + " and target locale: "
                            + selectedDetailEntry.getTargetLocale());
        } else if (selectedDetailEntry.getTargetVersionNum().compareTo(
                targetTerm.getVersionNum()) != 0) {
            throw new ActionException("Update failed for glossary term "
                    + selectedDetailEntry.getTarget() + " base versionNum "
                    + selectedDetailEntry.getTargetVersionNum()
                    + " does not match current versionNum "
                    + targetTerm.getVersionNum());
        } else {
            targetTerm.setContent(action.getNewTargetTerm());
            targetTerm.getComments().clear();

            for (String newComment : action.getNewTargetComment()) {
                targetTerm.getComments().add(new HTermComment(newComment));
            }

            HGlossaryEntry entryResult = glossaryDAO.makePersistent(entry);
            glossaryDAO.flush();

            ArrayList<String> srcComments = new ArrayList<String>();
            ArrayList<String> targetComments = new ArrayList<String>();

            for (HTermComment termComment : entryResult.getGlossaryTerms()
                    .get(entryResult.getSrcLocale()).getComments()) {
                srcComments.add(termComment.getComment());
            }

            for (HTermComment termComment : targetTerm.getComments()) {
                targetComments.add(termComment.getComment());
            }

            GlossaryDetails details =
                    new GlossaryDetails(entryResult.getGlossaryTerms()
                            .get(entryResult.getSrcLocale()).getContent(),
                            entryResult.getGlossaryTerms().get(targetLocale)
                                    .getContent(), srcComments, targetComments,
                            entryResult.getSourceRef(),
                            selectedDetailEntry.getSrcLocale(),
                            selectedDetailEntry.getTargetLocale(),
                            targetTerm.getVersionNum(),
                            targetTerm.getLastChanged());
View Full Code Here

            .use("glossaryDAO", glossaryDAO)
            .use("localeServiceImpl", localeServiceImpl)
            .ignoreNonResolvable()
            .autowire(UpdateGlossaryTermHandler.class);
      // @formatter:on
        hGlossaryEntry = new HGlossaryEntry();
    }
View Full Code Here

        glossaryDAO.flush();
        glossaryDAO.clear();
    }

    private void transferGlossaryEntry(GlossaryEntry from) {
        HGlossaryEntry to =
                getOrCreateGlossaryEntry(from.getSrcLang(),
                        getSrcGlossaryTerm(from));

        to.setSourceRef(from.getSourcereference());

        for (GlossaryTerm glossaryTerm : from.getGlossaryTerms()) {
            HLocale termHLocale =
                    localeServiceImpl.validateSourceLocale(glossaryTerm
                            .getLocale());

            // check if there's existing term with same content, overrides
            // comments
            HGlossaryTerm hGlossaryTerm =
                    getOrCreateGlossaryTerm(to, termHLocale, glossaryTerm);

            hGlossaryTerm.getComments().clear();

            for (String comment : glossaryTerm.getComments()) {
                hGlossaryTerm.getComments().add(new HTermComment(comment));
            }

            to.getGlossaryTerms().put(termHLocale, hGlossaryTerm);
        }
        glossaryDAO.makePersistent(to);
    }
View Full Code Here

        glossaryDAO.makePersistent(to);
    }

    public HGlossaryEntry getOrCreateGlossaryEntry(LocaleId srcLocale,
            String srcContent) {
        HGlossaryEntry hGlossaryEntry =
                glossaryDAO
                        .getEntryBySrcLocaleAndContent(srcLocale, srcContent);

        if (hGlossaryEntry == null) {
            hGlossaryEntry = new HGlossaryEntry();
            HLocale srcHLocale = localeServiceImpl.getByLocaleId(srcLocale);
            hGlossaryEntry.setSrcLocale(srcHLocale);
        }
        return hGlossaryEntry;
    }
View Full Code Here

    }

    @Test
    public void testGetEntryById() {
        log.debug("testGetEntryById");
        HGlossaryEntry entry = dao.getEntryById(1L);

        Assert.assertNotNull(entry);
        assertThat(entry.getGlossaryTerms().size(), is(3));
    }
View Full Code Here

        assertThat(entryList.size(), is(1));
    }

    @Test
    public void testGetTermEntryAndLocale() {
        HGlossaryEntry mockEntry = mock(HGlossaryEntry.class);
        when(mockEntry.getId()).thenReturn(1L);

        log.debug("testGetTermEntryAndLocale");
        HGlossaryTerm term =
                dao.getTermByEntryAndLocale(mockEntry.getId(), LocaleId.DE);
        Assert.assertNotNull(term);

    }
View Full Code Here

    }

    @Test
    public void testGetEntryBySrcContentLocale() {
        log.debug("testGetEntryBySrcContentLocale");
        HGlossaryEntry entry =
                dao.getEntryBySrcLocaleAndContent(LocaleId.EN_US,
                        "test data content 1 (source lang)");
        Assert.assertNotNull(entry);
        assertThat(entry.getSrcLocale().getLocaleId(), is(LocaleId.EN_US));
    }
View Full Code Here

    private HGlossaryTerm glossaryTerm(String content, HLocale srcLocale) {
        HGlossaryTerm glossaryTerm = new HGlossaryTerm(content);
        glossaryTerm.setVersionNum(0);
        glossaryTerm.setLastChanged(new Date());
        HGlossaryEntry glossaryEntry = new HGlossaryEntry();
        glossaryTerm.setGlossaryEntry(glossaryEntry);
        glossaryEntry.setSrcLocale(srcLocale);
        return glossaryTerm;
    }
View Full Code Here

TOP

Related Classes of org.zanata.model.HGlossaryEntry

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.