Package org.zanata.webtrans.shared.rpc

Examples of org.zanata.webtrans.shared.rpc.GetProjectTransUnitListsResult


        if (Strings.isNullOrEmpty(action.getSearchString())) {
            // TODO empty searches shouldn't be requested, consider replacing
            // this
            // with an error, or making behaviour return all targets for the
            // project (consider performance).
            return new GetProjectTransUnitListsResult(action, docPaths,
                    matchingTUs);
        }

        FilterConstraints filterConstraints =
                FilterConstraints.builder().filterBy(action.getSearchString())
                        .caseSensitive(action.isCaseSensitive())
                        .checkInSource(action.isSearchInSource())
                        .checkInTarget(action.isSearchInTarget()).build();

        List<HTextFlow> matchingFlows =
                textFlowSearchServiceImpl.findTextFlows(
                        action.getWorkspaceId(), action.getDocumentPaths(),
                        filterConstraints);
        log.info("Returned {} results for search", matchingFlows.size());

        // FIXME remove when analyzer handles leading & trailing whitespace
        boolean needsWhitespaceCheck =
                !action.getSearchString().equals(
                        action.getSearchString().trim());
        Iterable<HTextFlow> result = matchingFlows;
        if (needsWhitespaceCheck) {
            // FIXME temporary check for leading and trailing whitespace to
            // compensate
            // for NGramAnalyzer trimming strings before tokenization. This
            // should
            // be removed when updating to a lucene version with the whitespace
            // issue resolved.
            result =
                    Iterables.filter(
                            matchingFlows,
                            new WhitespaceMatchPredicate(action, hLocale
                                    .getId()));
        }

        for (HTextFlow textFlow : result) {
            List<TransUnit> listForDoc =
                    matchingTUs.get(textFlow.getDocument().getId());
            if (listForDoc == null) {
                listForDoc = new ArrayList<TransUnit>();
            }

            TransUnit transUnit =
                    transUnitTransformer.transform(textFlow, hLocale);
            listForDoc.add(transUnit);
            matchingTUs.put(textFlow.getDocument().getId(), listForDoc);
            docPaths.put(textFlow.getDocument().getId(), textFlow.getDocument()
                    .getDocId());
        }
        return new GetProjectTransUnitListsResult(action, docPaths, matchingTUs);
    }
View Full Code Here


                localeService.validateLocaleByProjectIteration(localeId,
                        workspaceId.getProjectIterationId().getProjectSlug(),
                        workspaceId.getProjectIterationId().getIterationSlug()))
                .thenThrow(new ZanataServiceException("bad"));

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

    public void emptySearchTermWillReturnEmpty() throws Exception {
        GetProjectTransUnitLists action =
                new GetProjectTransUnitLists("", true, true, false);
        action.setWorkspaceId(workspaceId);

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

        verify(identity).checkLoggedIn();
        assertThat(result.getDocumentIds(), Matchers.<Long> emptyIterable());
        verifyZeroInteractions(textFlowSearchServiceImpl);
    }
View Full Code Here

                        eq(action.getWorkspaceId()),
                        eq(action.getDocumentPaths()),
                        constraintCaptor.capture())).thenReturn(textFlows);

        // When: search in target only and case sensitive
        GetProjectTransUnitListsResult result = handler.execute(action, null);

        verify(identity).checkLoggedIn();
        FilterConstraints constraints = constraintCaptor.getValue();
        assertThat(constraints.isSearchInSource(), Matchers.equalTo(true));
        assertThat(constraints.isSearchInTarget(), Matchers.equalTo(true));
        assertThat(constraints.isCaseSensitive(), Matchers.equalTo(true));
        assertThat(result.getDocumentIds(), Matchers.contains(DOC_ID));
        assertThat(TestFixture.asIds(result.getUnits(DOC_ID)),
                Matchers.contains(1, 2, 3, 4));
    }
View Full Code Here

                        eq(action.getWorkspaceId()),
                        eq(action.getDocumentPaths()),
                        constraintCaptor.capture())).thenReturn(textFlows);

        // When: search in source and target and case sensitive
        GetProjectTransUnitListsResult result = handler.execute(action, null);

        verify(identity).checkLoggedIn();
        FilterConstraints constraints = constraintCaptor.getValue();
        assertThat(constraints.isSearchInSource(), Matchers.equalTo(true));
        assertThat(constraints.isSearchInTarget(), Matchers.equalTo(true));
        assertThat(constraints.isCaseSensitive(), Matchers.equalTo(true));
        assertThat(result.getDocumentIds(), Matchers.contains(DOC_ID));
        assertThat(TestFixture.asIds(result.getUnits(DOC_ID)),
                Matchers.contains(2, 3));
    }
View Full Code Here

                        eq(action.getWorkspaceId()),
                        eq(action.getDocumentPaths()),
                        constraintCaptor.capture())).thenReturn(textFlows);

        // When: search in source only and case insensitive
        GetProjectTransUnitListsResult result = handler.execute(action, null);

        verify(identity).checkLoggedIn();
        FilterConstraints constraints = constraintCaptor.getValue();
        assertThat(constraints.isSearchInSource(), Matchers.equalTo(true));
        assertThat(constraints.isSearchInTarget(), Matchers.equalTo(false));
        assertThat(constraints.isCaseSensitive(), Matchers.equalTo(false));
        assertThat(result.getDocumentIds(), Matchers.contains(DOC_ID));
        assertThat(TestFixture.asIds(result.getUnits(DOC_ID)),
                Matchers.contains(1, 3));
    }
View Full Code Here

                new Answer<GetProjectTransUnitListsResult>() {

                    @Override
                    public GetProjectTransUnitListsResult answer(
                            InvocationOnMock invocation) throws Throwable {
                        GetProjectTransUnitListsResult result =
                                new GetProjectTransUnitListsResult(
                                        capturedDispatchedSearch.getValue(),
                                        docPaths, documents);
                        capturedDispatchedSearchCallback.getValue().onSuccess(
                                result);
                        return null;
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.shared.rpc.GetProjectTransUnitListsResult

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.