Search in sources :

Example 21 with Filter

use of org.activityinfo.shared.command.Filter 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 22 with Filter

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

the class QueryParser method createFilter.

private void createFilter() {
    Filter filter = new Filter();
    for (String dimensionString : preciseDimensions.keySet()) {
        DimensionType dimension;
        try {
            dimension = fromString(dimensionString);
        } catch (Exception e) {
            // Ruthlessly ignore nonparseable string
            continue;
        }
        List<Integer> ids = new ArrayList<Integer>();
        for (String idString : preciseDimensions.get(dimensionString)) {
            try {
                int id = Integer.parseInt(idString);
                ids.add(id);
            } catch (Exception ex) {
                // Ruthlessly ignore nonparseable string
                continue;
            }
        }
        if (ids.size() > 0 && isSupportedDimension(dimension)) {
            filter.addRestriction(dimension, ids);
        }
    }
    this.filter = filter;
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) Filter(org.activityinfo.shared.command.Filter) ArrayList(java.util.ArrayList)

Example 23 with Filter

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

the class DataEntryPlaceParserTest method activityFiltered.

@Test
public void activityFiltered() {
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Activity, 33);
    verifyCorrectSerde(new DataEntryPlace(filter));
}
Also used : Filter(org.activityinfo.shared.command.Filter) Test(org.junit.Test)

Example 24 with Filter

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

the class GetSitesTest method filterByIndicator.

@Test
public void filterByIndicator() throws CommandException {
    setUser(1);
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 5);
    SiteResult result = execute(new GetSites(filter));
    assertThat(result.getData().size(), equalTo(1));
    assertThat(result.getData().get(0).getId(), equalTo(9));
}
Also used : Filter(org.activityinfo.shared.command.Filter) SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) Test(org.junit.Test)

Example 25 with Filter

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

the class SiteExporterTest method sheetNameTest.

@Test
public void sheetNameTest() {
    LocaleProxy.initialize();
    CountryDTO somalia = new CountryDTO(1, "Somalia");
    somalia.getLocationTypes().add(new LocationTypeDTO(1, "Village"));
    UserDatabaseDTO syli = new UserDatabaseDTO();
    syli.setName("SYLI");
    syli.setCountry(somalia);
    ActivityDTO activity = new ActivityDTO();
    activity.setId(1);
    activity.setDatabase(syli);
    activity.setName("Construction/Rehabilitation of Sec. Schools");
    activity.setLocationTypeId(1);
    ActivityDTO activity2 = new ActivityDTO();
    activity2.setId(2);
    activity2.setDatabase(syli);
    activity2.setName("Construction/Rehabilitation of Primary Schools");
    activity2.setLocationTypeId(1);
    ActivityDTO activity3 = new ActivityDTO();
    activity3.setId(3);
    activity3.setDatabase(syli);
    activity3.setName("Construction Rehabil (2)");
    activity3.setLocationTypeId(1);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(new ArrayList<SiteDTO>())).anyTimes();
    replay(dispatcher);
    Filter filter = new Filter();
    SiteExporter exporter = new SiteExporter(dispatcher);
    exporter.export(activity, filter);
    exporter.export(activity2, filter);
    exporter.export(activity3, filter);
    HSSFWorkbook book = exporter.getBook();
    assertThat(book.getSheetAt(0).getSheetName(), equalTo("SYLI - Construction Rehabilitat"));
    assertThat(book.getSheetAt(1).getSheetName(), equalTo("SYLI - Construction Rehabil (2)"));
    assertThat(book.getSheetAt(2).getSheetName(), equalTo("SYLI - Construction Rehabil 2"));
}
Also used : CountryDTO(org.activityinfo.shared.dto.CountryDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SiteResult(org.activityinfo.shared.command.result.SiteResult) Filter(org.activityinfo.shared.command.Filter) LocationTypeDTO(org.activityinfo.shared.dto.LocationTypeDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

Filter (org.activityinfo.shared.command.Filter)59 GetSites (org.activityinfo.shared.command.GetSites)8 Test (org.junit.Test)8 GetSchema (org.activityinfo.shared.command.GetSchema)5 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 DimensionType (org.activityinfo.shared.report.model.DimensionType)5 ArrayList (java.util.ArrayList)4 SiteDTO (org.activityinfo.shared.dto.SiteDTO)4 DateRange (org.activityinfo.shared.report.model.DateRange)4 StringWriter (java.io.StringWriter)3 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 SiteResult (org.activityinfo.shared.command.result.SiteResult)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)3 Margins (com.extjs.gxt.ui.client.util.Margins)2 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)2 JsonElement (com.google.gson.JsonElement)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2