Search in sources :

Example 1 with GetSites

use of org.activityinfo.shared.command.GetSites 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 GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class KmlDataServlet method querySites.

private List<SiteDTO> querySites(User user, SchemaDTO schema, int activityId) {
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Activity, activityId);
    return dispatcher.execute(new GetSites(filter)).getData();
}
Also used : Filter(org.activityinfo.shared.command.Filter) GetSites(org.activityinfo.shared.command.GetSites)

Example 3 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class PointLayerGenerator method queryFor.

private GetSites queryFor(Filter effectiveFilter, PointMapLayer layer) {
    Filter layerFilter = new Filter(effectiveFilter, layer.getFilter());
    for (int id : layer.getIndicatorIds()) {
        Indicator indicator = indicators.get(id);
        if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SITE_COUNT) {
            layerFilter.addRestriction(DimensionType.Activity, indicator.getActivity().getId());
        } else {
            layerFilter.addRestriction(DimensionType.Indicator, indicator.getId());
        }
    }
    layerFilter.addRestriction(DimensionType.Indicator, physicalIndicators(layer));
    GetSites query = new GetSites();
    query.setFilter(layerFilter);
    query.setFetchAttributes(false);
    query.setFetchAdminEntities(layer.getClustering() instanceof AdministrativeLevelClustering);
    query.setFetchAllIndicators(false);
    query.setFetchIndicators(physicalIndicators(layer));
    return query;
}
Also used : AdministrativeLevelClustering(org.activityinfo.shared.report.model.clustering.AdministrativeLevelClustering) Filter(org.activityinfo.shared.command.Filter) GetSites(org.activityinfo.shared.command.GetSites) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator)

Example 4 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitePointsHandler method execute.

@Override
public void execute(GetSitePoints command, ExecutionContext context, final AsyncCallback<SitePointList> callback) {
    Filter filter = new Filter();
    if (command.getActivityId() != 0) {
        filter.addRestriction(DimensionType.Activity, command.getActivityId());
    }
    context.execute(new GetSites(filter), new AsyncCallback<SiteResult>() {

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

        @Override
        public void onSuccess(SiteResult result) {
            callback.onSuccess(toPointList(result.getData()));
        }
    });
}
Also used : Filter(org.activityinfo.shared.command.Filter) SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites)

Example 5 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method duplicated.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void duplicated() {
    // A given site can be appear multiple times in the list if it is the
    // source
    // of one or more indicators
    setUser(1);
    GetSites cmd = new GetSites();
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(3));
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

GetSites (org.activityinfo.shared.command.GetSites)28 Test (org.junit.Test)18 SiteDTO (org.activityinfo.shared.dto.SiteDTO)16 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)10 SiteResult (org.activityinfo.shared.command.result.SiteResult)10 Filter (org.activityinfo.shared.command.Filter)8 OnDataSet (org.activityinfo.server.database.OnDataSet)5 StringWriter (java.io.StringWriter)2 GET (javax.ws.rs.GET)2 JsonGenerator (org.codehaus.jackson.JsonGenerator)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 Delete (org.activityinfo.shared.command.Delete)1 GenerateElement (org.activityinfo.shared.command.GenerateElement)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 PivotSites (org.activityinfo.shared.command.PivotSites)1