Search in sources :

Example 11 with AdminLevelDTO

use of org.activityinfo.shared.dto.AdminLevelDTO 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 12 with AdminLevelDTO

use of org.activityinfo.shared.dto.AdminLevelDTO in project activityinfo by bedatadriven.

the class AdminFieldSetPresenterTest method expectEnabledEvents.

private void expectEnabledEvents(AdminLevelDTO... levels) {
    resetToDefault(levelStateChangeListener);
    for (AdminLevelDTO level : levels) {
        levelStateChangeListener.handleEvent(eq(new LevelStateChangeEvent(level.getId(), true)));
    }
    replay(levelStateChangeListener);
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO)

Example 13 with AdminLevelDTO

use of org.activityinfo.shared.dto.AdminLevelDTO in project activityinfo by bedatadriven.

the class GetSchemaTest method testDatabaseVisibilityForOwners.

@Test
public void testDatabaseVisibilityForOwners() throws CommandException {
    // owners should be able to see their databases
    // Alex
    setUser(1);
    SchemaDTO schema = execute(new GetSchema());
    assertThat("database count", schema.getDatabases().size(), equalTo(3));
    assertThat("database list is sorted", schema.getDatabases().get(0).getName(), equalTo("Alpha"));
    // PEAR
    assertTrue("ALEX(owner) in PEAR", schema.getDatabaseById(1) != null);
    assertTrue("ALEX can design", schema.getDatabaseById(1).isDesignAllowed());
    assertTrue("Alex can edit all", schema.getDatabaseById(1).isEditAllowed());
    assertTrue("object graph is preserved", schema.getDatabaseById(1).getCountry() == schema.getDatabaseById(2).getCountry());
    assertTrue("object graph is preserved (database-activity)", schema.getDatabaseById(1) == schema.getDatabaseById(1).getActivities().get(0).getDatabase());
    AdminLevelDTO adminLevel = schema.getCountries().get(0).getAdminLevels().get(0);
    assertThat("CountryId is not null", adminLevel.getCountryId(), not(equalTo(0)));
    assertThat("CountryId is not null", adminLevel.getId(), not(equalTo(0)));
    assertTrue("CountryId is not null", schema.getCountries().get(0).getAdminLevels().get(0).getCountryId() != 0);
    assertThat("deleted attribute is not present", schema.getActivityById(1).getAttributeGroups().size(), equalTo(3));
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)13 AdminEntityDTO (org.activityinfo.shared.dto.AdminEntityDTO)3 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)2 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)2 CountryDTO (org.activityinfo.shared.dto.CountryDTO)2 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)2 LocationDTO (org.activityinfo.shared.dto.LocationDTO)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 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 Radio (com.extjs.gxt.ui.client.widget.form.Radio)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 AdminLevelResult (org.activityinfo.shared.command.result.AdminLevelResult)1