Search in sources :

Example 1 with AdminLevelResult

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

the class AdminLevelPanel method setIndicators.

public void setIndicators(Collection<Integer> indicatorIds) {
    showLoading();
    GetAdminLevels query = new GetAdminLevels();
    query.setIndicatorIds(Sets.newHashSet(indicatorIds));
    dispatcher.execute(query, new AsyncCallback<AdminLevelResult>() {

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

        @Override
        public void onSuccess(AdminLevelResult result) {
            showOptions(result.getData());
        }
    });
}
Also used : AdminLevelResult(org.activityinfo.shared.command.result.AdminLevelResult) GetAdminLevels(org.activityinfo.shared.command.GetAdminLevels)

Example 2 with AdminLevelResult

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

the class GetAdminLevelsHandler method execute.

@Override
public void execute(GetAdminLevels command, ExecutionContext context, final AsyncCallback<AdminLevelResult> callback) {
    if (CollectionUtil.isEmpty(command.getIndicatorIds())) {
        callback.onSuccess(new AdminLevelResult(new ArrayList<AdminLevelDTO>()));
        return;
    }
    String hasPolygonsSubQuery = "exists (select e.adminentityid from adminentity e " + "where e.adminlevelid=level.adminlevelid and geometry is not null)";
    SqlQuery.select().appendColumn("level.adminlevelId", "id").appendColumn("level.name", "name").appendColumn(hasPolygonsSubQuery, "polygons").from(Tables.INDICATOR, "i").innerJoin(Tables.ACTIVITY, "a").on("i.activityId=a.activityId").innerJoin(Tables.USER_DATABASE, "db").on("a.databaseid=db.databaseid").innerJoin(Tables.COUNTRY, "c").on("db.countryid=c.countryid").innerJoin(Tables.ADMIN_LEVEL, "level").on("level.countryid=c.countryid").where("i.indicatorId").in(command.getIndicatorIds()).groupBy("level.adminlevelid").groupBy("level.name").execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            List<AdminLevelDTO> levels = Lists.newArrayList();
            for (SqlResultSetRow row : results.getRows()) {
                AdminLevelDTO level = new AdminLevelDTO();
                level.setId(row.getInt("id"));
                level.setName(row.getString("name"));
                level.setPolygons(row.getBoolean("polygons"));
                levels.add(level);
            }
            callback.onSuccess(new AdminLevelResult(levels));
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) AdminLevelResult(org.activityinfo.shared.command.result.AdminLevelResult) AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) ArrayList(java.util.ArrayList) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ArrayList(java.util.ArrayList) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow)

Example 3 with AdminLevelResult

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

the class GetAdminLevelsHandlerTest method test.

@Test
public void test() {
    GetAdminLevels query = new GetAdminLevels();
    query.setIndicatorIds(Sets.newHashSet(1));
    AdminLevelResult result = execute(query);
    System.out.println(result.getData());
}
Also used : AdminLevelResult(org.activityinfo.shared.command.result.AdminLevelResult) GetAdminLevels(org.activityinfo.shared.command.GetAdminLevels) Test(org.junit.Test)

Aggregations

AdminLevelResult (org.activityinfo.shared.command.result.AdminLevelResult)3 GetAdminLevels (org.activityinfo.shared.command.GetAdminLevels)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)1 Test (org.junit.Test)1