Package org.zanata.webtrans.shared.model

Examples of org.zanata.webtrans.shared.model.GlossaryDetails


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


    @Override
    public UpdateGlossaryTermResult execute(UpdateGlossaryTermAction action,
            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(),
View Full Code Here

        hGlossaryEntry = new HGlossaryEntry();
    }

    @Test
    public void testExecute() throws Exception {
        GlossaryDetails selectedDetailEntry =
                new GlossaryDetails("source", "target", null, null,
                        "sourceRef", srcLocale.getLocaleId(),
                        targetHLocale.getLocaleId(), 0, new Date());
        UpdateGlossaryTermAction action =
                new UpdateGlossaryTermAction(selectedDetailEntry, "new target",
                        Lists.newArrayList("new comment"));
        when(
                glossaryDAO.getEntryBySrcLocaleAndContent(
                        selectedDetailEntry.getSrcLocale(),
                        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);
View Full Code Here

    }

    @Test(expectedExceptions = ActionException.class)
    public void testExecuteWhenTargetTermNotFound() throws Exception {
        GlossaryDetails selectedDetailEntry =
                new GlossaryDetails("source", "target", null, null,
                        "sourceRef", srcLocale.getLocaleId(),
                        targetHLocale.getLocaleId(), 0, new Date());
        UpdateGlossaryTermAction action =
                new UpdateGlossaryTermAction(selectedDetailEntry, "new target",
                        Lists.newArrayList("new comment"));
        when(
                glossaryDAO.getEntryBySrcLocaleAndContent(
                        selectedDetailEntry.getSrcLocale(),
                        selectedDetailEntry.getSource())).thenReturn(
                hGlossaryEntry);
        when(
                localeServiceImpl.getByLocaleId(selectedDetailEntry
                        .getTargetLocale())).thenReturn(targetHLocale);
        when(glossaryDAO.makePersistent(hGlossaryEntry)).thenReturn(
                hGlossaryEntry);

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

        handler.execute(action, null);
    }

    @Test(expectedExceptions = ActionException.class)
    public void testExecuteWhenTargetTermVersionNotMatch() throws Exception {
        GlossaryDetails selectedDetailEntry =
                new GlossaryDetails("source", "target", null, null,
                        "sourceRef", srcLocale.getLocaleId(),
                        targetHLocale.getLocaleId(), 0, new Date());
        UpdateGlossaryTermAction action =
                new UpdateGlossaryTermAction(selectedDetailEntry, "new target",
                        Lists.newArrayList("new comment"));
        when(
                glossaryDAO.getEntryBySrcLocaleAndContent(
                        selectedDetailEntry.getSrcLocale(),
                        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);
View Full Code Here

            targetComments.add("Target Comment " + (3 + i));
            targetComments.add("Target Comment " + (4 + i));
            targetComments.add("Target Comment " + (5 + i));
            targetComments.add("Target Comment " + (6 + i));

            GlossaryDetails details =
                    new GlossaryDetails("source content:" + (i + 1),
                            "target content:" + (i + 1), srcComments,
                            targetComments, "Dummy source ref " + (i + 1),
                            new LocaleId("en-us"), action.getWorkspaceId()
                                    .getLocaleId(), i, new Date());
            items.add(details);
View Full Code Here

    public void onSaveClick() {
        String targetText = "target Text";
        String newTargetText = "new target Text";
        List<String> targetComments = Lists.newArrayList("new comment");

        GlossaryDetails glossaryDetails = mock(GlossaryDetails.class);
        when(
                mockUserWorkspaceContext.getWorkspaceRestrictions()
                        .isHasGlossaryUpdateAccess()).thenReturn(true);
        when(display.getTargetText()).thenReturn(this.targetText);
        when(this.targetText.getText()).thenReturn(newTargetText);
        when(glossaryDetails.getTarget()).thenReturn(targetText);
        when(display.getCurrentTargetComments()).thenReturn(targetComments);
        glossaryDetailsPresenter.setStatesForTest(glossaryDetails);

        glossaryDetailsPresenter.onSaveClick();
View Full Code Here

                Matchers.equalTo(glossaryDetails));
    }

    @Test
    public void onSaveClickAndCallbackSuccess() {
        GlossaryDetails glossaryDetails = mock(GlossaryDetails.class);
        when(
                mockUserWorkspaceContext.getWorkspaceRestrictions()
                        .isHasGlossaryUpdateAccess()).thenReturn(true);
        when(display.getTargetText()).thenReturn(targetText);
        when(targetText.getText()).thenReturn("new target Text");
        when(glossaryDetails.getTarget()).thenReturn("target Text");
        glossaryDetailsPresenter.setStatesForTest(glossaryDetails);

        glossaryDetailsPresenter.onSaveClick();

        verify(display).showLoading(true);
        verify(mockDispatcher).execute(updateGlossaryTermCaptor.capture(),
                updateGlossarycallbackCaptor.capture());
        AsyncCallback<UpdateGlossaryTermResult> callback =
                updateGlossarycallbackCaptor.getValue();
        GlossaryDetails newDetails = mock(GlossaryDetails.class);
        when(display.getSrcRef()).thenReturn(srcRef);
        callback.onSuccess(new UpdateGlossaryTermResult(newDetails));

        verify(glossaryListener).fireSearchEvent();
        verify(srcRef).setText(newDetails.getSourceRef());
        verify(display).setSourceComment(newDetails.getSourceComment());
        verify(display).setTargetComment(newDetails.getTargetComment());
        verify(display).setLastModifiedDate(newDetails.getLastModifiedDate());
        verify(display).showLoading(false);
    }
View Full Code Here

        verify(display).showLoading(false);
    }

    @Test
    public void onSaveClickAndCallbackFailure() {
        GlossaryDetails glossaryDetails = mock(GlossaryDetails.class);
        when(
                mockUserWorkspaceContext.getWorkspaceRestrictions()
                        .isHasGlossaryUpdateAccess()).thenReturn(true);
        when(display.getTargetText()).thenReturn(targetText);
        when(targetText.getText()).thenReturn("new target Text");
        when(glossaryDetails.getTarget()).thenReturn("target Text");
        glossaryDetailsPresenter.setStatesForTest(glossaryDetails);

        glossaryDetailsPresenter.onSaveClick();

        verify(display).showLoading(true);
View Full Code Here

        verify(display).showLoading(false);
    }

    @Test
    public void onSaveClickNoWriteAccess() {
        GlossaryDetails glossaryDetails = mock(GlossaryDetails.class);
        when(
                mockUserWorkspaceContext.getWorkspaceRestrictions()
                        .isHasGlossaryUpdateAccess()).thenReturn(false);
        when(display.getTargetText()).thenReturn(targetText);
        when(targetText.getText()).thenReturn("new target Text");
        when(glossaryDetails.getTarget()).thenReturn("target Text");
        glossaryDetailsPresenter.setStatesForTest(glossaryDetails);

        glossaryDetailsPresenter.onSaveClick();

        verifyZeroInteractions(mockDispatcher);
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.shared.model.GlossaryDetails

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.