Search in sources :

Example 1 with SearchResult

use of org.activityinfo.shared.command.result.SearchResult in project activityinfo by bedatadriven.

the class SearchHandler method processFilter.

private void processFilter(final ExecutionContext context, final AsyncCallback<SearchResult> callback, final Filter resultFilter) {
    final SearchResult searchResult = new SearchResult();
    if (resultFilter.getRestrictedDimensions().size() > 0) {
        // pivot data query
        final PivotTableReportElement pivotTable = createSearchPivotTableElement();
        pivotTable.setFilter(resultFilter);
        GenerateElement<PivotContent> zmd = new GenerateElement<PivotContent>(pivotTable);
        context.execute(zmd, new AsyncCallback<PivotContent>() {

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }

            @Override
            public void onSuccess(PivotContent content) {
                content.setEffectiveFilter(resultFilter);
                searchResult.setPivotTabelData(content);
                // recent sites query
                GetSites getSites = createGetSitesCommand(resultFilter);
                context.execute(getSites, new AsyncCallback<SiteResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(SiteResult resultSites) {
                        searchResult.setRecentAdditions(resultSites.getData());
                        callback.onSuccess(searchResult);
                    }
                });
            }
        });
    } else {
        // Return empty searchresult when no filtered entities found
        callback.onSuccess(searchResult);
    }
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) PivotContent(org.activityinfo.shared.report.content.PivotContent) GetSites(org.activityinfo.shared.command.GetSites) GenerateElement(org.activityinfo.shared.command.GenerateElement) SearchResult(org.activityinfo.shared.command.result.SearchResult) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 2 with SearchResult

use of org.activityinfo.shared.command.result.SearchResult in project activityinfo by bedatadriven.

the class SearchTest method testSearchAll.

@Test
@Ignore
public void testSearchAll() throws CommandException {
    Logger.getLogger("com.bedatadriven.rebar").setLevel(Level.ALL);
    SearchResult result = execute(new Search("kivu"));
    assertTrue("Expected all searchers to succeed", result.getFailedSearchers().isEmpty());
    for (Searcher searcher : AllSearcher.supportedSearchers()) {
        assertHasDimension(searcher.getDimensionType(), result);
    }
    assertHasRestrictionWithIds(DimensionType.AdminLevel, result, 2, 3);
    assertHasRestrictionWithIds(DimensionType.Partner, result, 3);
    assertHasRestrictionWithIds(DimensionType.Project, result, 4);
    assertHasRestrictionWithIds(DimensionType.AttributeGroup, result, 3);
    assertHasRestrictionWithIds(DimensionType.Indicator, result, 675);
    assertHasRestrictionWithIds(DimensionType.Location, result, 1);
}
Also used : AllSearcher(org.activityinfo.shared.command.handler.search.AllSearcher) Searcher(org.activityinfo.shared.command.handler.search.Searcher) SearchResult(org.activityinfo.shared.command.result.SearchResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SearchResult

use of org.activityinfo.shared.command.result.SearchResult in project activityinfo by bedatadriven.

the class SearchPresenter method onSearch.

@Override
public void onSearch(SearchEvent searchEvent) {
    if (!Strings.isNullOrEmpty(searchEvent.getQuery())) {
        view.setSearchQuery(searchEvent.getQuery());
        view.getLoadingMonitor().beforeRequest();
        service.execute(new Search(searchEvent.getQuery()), view.getLoadingMonitor(), new AsyncCallback<SearchResult>() {

            @Override
            public void onFailure(Throwable caught) {
                // TODO handle failure
                view.getLoadingMonitor().onServerError();
            }

            @Override
            public void onSuccess(SearchResult result) {
                view.setSearchResults(result.getPivotTabelData());
                Filter filter = result.getPivotTabelData() == null ? null : result.getPivotTabelData().getEffectiveFilter();
                view.setFilter(createFilter(filter, result.getPivotTabelData()));
                view.getLoadingMonitor().onCompleted();
                view.setSitePoints(SitePointList.fromSitesList(result.getRecentAdditions()));
                view.setSites(fromSitesList(result.getRecentAdditions()));
            }

            private Map<DimensionType, List<SearchResultEntity>> createFilter(Filter effectiveFilter, PivotContent pivotContent) {
                Map<DimensionType, List<SearchResultEntity>> newFilter = new HashMap<DimensionType, List<SearchResultEntity>>();
                if (effectiveFilter != null) {
                    for (DimensionType type : effectiveFilter.getRestrictedDimensions()) {
                        List<SearchResultEntity> entities = new ArrayList<SearchResultEntity>();
                        for (Integer entityId : effectiveFilter.getRestrictions(type)) {
                            String name = getName(entityId, type, pivotContent);
                            String link = GWT.getHostPageBaseURL() + "#search/" + type.toString() + ":" + name;
                            SearchResultEntity entity = new SearchResultEntity(entityId, name, link, type);
                            entities.add(entity);
                        }
                        newFilter.put(type, entities);
                    }
                }
                return newFilter;
            }

            private String getName(Integer entityId, DimensionType type, PivotContent pivotTable) {
                for (FilterDescription fd : pivotTable.getFilterDescriptions()) {
                    if (fd.getDimensionType() == type) {
                        return fd.getLabels().get(entityId);
                    }
                }
                return "noName";
            }
        });
    }
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) SearchResult(org.activityinfo.shared.command.result.SearchResult) Filter(org.activityinfo.shared.command.Filter) Search(org.activityinfo.shared.command.Search) PivotContent(org.activityinfo.shared.report.content.PivotContent) SitePointList(org.activityinfo.shared.command.result.SitePointList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SearchResult (org.activityinfo.shared.command.result.SearchResult)3 PivotContent (org.activityinfo.shared.report.content.PivotContent)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Filter (org.activityinfo.shared.command.Filter)1 GenerateElement (org.activityinfo.shared.command.GenerateElement)1 GetSites (org.activityinfo.shared.command.GetSites)1 Search (org.activityinfo.shared.command.Search)1 AllSearcher (org.activityinfo.shared.command.handler.search.AllSearcher)1 Searcher (org.activityinfo.shared.command.handler.search.Searcher)1 SitePointList (org.activityinfo.shared.command.result.SitePointList)1 SiteResult (org.activityinfo.shared.command.result.SiteResult)1 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)1 DimensionType (org.activityinfo.shared.report.model.DimensionType)1 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1