Search in sources :

Example 1 with AdminLevelResult

use of org.activityinfo.legacy.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.legacy.shared.command.result.AdminLevelResult) AdminLevelDTO(org.activityinfo.legacy.shared.model.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 2 with AdminLevelResult

use of org.activityinfo.legacy.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.legacy.shared.command.result.AdminLevelResult) GetAdminLevels(org.activityinfo.legacy.shared.command.GetAdminLevels)

Example 3 with AdminLevelResult

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

the class ClusteringOptionsWidget method loadForm.

public void loadForm(final MapLayer layer) {
    // mask();
    destroyForm();
    GetAdminLevels query = new GetAdminLevels();
    query.setIndicatorIds(Sets.newHashSet(layer.getIndicatorIds()));
    service.execute(query, new AsyncCallback<AdminLevelResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

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

Example 4 with AdminLevelResult

use of org.activityinfo.legacy.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.legacy.shared.command.result.AdminLevelResult) GetAdminLevels(org.activityinfo.legacy.shared.command.GetAdminLevels) Test(org.junit.Test)

Aggregations

AdminLevelResult (org.activityinfo.legacy.shared.command.result.AdminLevelResult)4 GetAdminLevels (org.activityinfo.legacy.shared.command.GetAdminLevels)3 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.legacy.shared.model.AdminLevelDTO)1 Test (org.junit.Test)1