Package org.zanata.model

Examples of org.zanata.model.HGlossaryTerm


        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


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

            return new UpdateGlossaryTermResult(details);
        }
    }
View Full Code Here

                            action.getSrcLocaleId(), MAX_RESULTS);

            Map<GlossaryKey, GlossaryResultItem> matchesMap =
                    new LinkedHashMap<GlossaryKey, GlossaryResultItem>();
            for (Object[] match : matches) {
                HGlossaryTerm sourceTerm = (HGlossaryTerm) match[1];
                HGlossaryTerm targetTerm = null;
                if (sourceTerm != null) {
                    targetTerm =
                            glossaryDAO.getTermByEntryAndLocale(sourceTerm
                                    .getGlossaryEntry().getId(), localeID);
                }
                if (targetTerm == null) {
                    continue;
                }
                String srcTermContent = sourceTerm.getContent();
                String targetTermContent = targetTerm.getContent();
                GlossaryResultItem item =
                        getOrCreateGlossaryResultItem(matchesMap,
                                srcTermContent, targetTermContent,
                                (Float) match[0], searchText);
                item.addSourceId(sourceTerm.getId());
View Full Code Here

                        selectedDetailEntry.getSource())).thenReturn(
                hGlossaryEntry);
        when(
                localeServiceImpl.getByLocaleId(selectedDetailEntry
                        .getTargetLocale())).thenReturn(targetHLocale);
        HGlossaryTerm targetTerm = new HGlossaryTerm("target");
        targetTerm.setVersionNum(0);
        targetTerm.setLastChanged(new Date());
        hGlossaryEntry.getGlossaryTerms().put(targetHLocale, targetTerm);
        hGlossaryEntry.setSrcLocale(srcLocale);
        hGlossaryEntry.getGlossaryTerms().put(srcLocale,
                new HGlossaryTerm("source")); // source term
        when(glossaryDAO.makePersistent(hGlossaryEntry)).thenReturn(
                hGlossaryEntry);

        UpdateGlossaryTermResult result = handler.execute(action, null);

        verify(identity).checkLoggedIn();
        assertThat(targetTerm.getComments(), Matchers.hasSize(1));
        assertThat(targetTerm.getComments().get(0).getComment(),
                Matchers.equalTo("new comment"));
        assertThat(targetTerm.getContent(), Matchers.equalTo("new target"));
        verify(glossaryDAO).makePersistent(hGlossaryEntry);
        verify(glossaryDAO).flush();
        assertThat(result.getDetail().getTarget(),
                Matchers.equalTo("new target"));
View Full Code Here

                        selectedDetailEntry.getSource())).thenReturn(
                hGlossaryEntry);
        when(
                localeServiceImpl.getByLocaleId(selectedDetailEntry
                        .getTargetLocale())).thenReturn(targetHLocale);
        HGlossaryTerm targetTerm = new HGlossaryTerm("target");
        targetTerm.setVersionNum(1); // different version
        hGlossaryEntry.getGlossaryTerms().put(targetHLocale, targetTerm);

        handler.execute(action, null);
    }
View Full Code Here

                targetHLocale);
        GetGlossary action =
                new GetGlossary("fedora", TARGET_LOCALE_ID, LocaleId.EN_US,
                        HasSearchType.SearchType.FUZZY);
        // hibernate search result
        HGlossaryTerm srcGlossaryTerm1 = getEm().find(HGlossaryTerm.class, 42L);
        HGlossaryTerm srcGlossaryTerm2 = getEm().find(HGlossaryTerm.class, 46L);
        List<Object[]> matches =
                Lists.newArrayList(new Object[] { 1.0F, srcGlossaryTerm1 },
                        new Object[] { 1.1F, srcGlossaryTerm2 });
        doReturn(matches).when(glossaryDAOSpy).getSearchResult("fedora",
                HasSearchType.SearchType.FUZZY, LocaleId.EN_US, 20);
View Full Code Here

                    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

    }

    private HGlossaryTerm getOrCreateGlossaryTerm(
            HGlossaryEntry hGlossaryEntry, HLocale termHLocale,
            GlossaryTerm newTerm) {
        HGlossaryTerm hGlossaryTerm =
                hGlossaryEntry.getGlossaryTerms().get(termHLocale);

        if (hGlossaryTerm == null) {
            hGlossaryTerm = new HGlossaryTerm(newTerm.getContent());
            hGlossaryTerm.setLocale(termHLocale);
            hGlossaryTerm.setGlossaryEntry(hGlossaryEntry);
        } else if (!hGlossaryTerm.getContent().equals(newTerm.getContent())) {
            hGlossaryTerm.setContent(newTerm.getContent());
        }

        return hGlossaryTerm;
    }
View Full Code Here

    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

            .autowire(GetGlossaryDetailsHandler.class);
      // @formatter:on
    }

    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.HGlossaryTerm

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.