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));
}
});
}
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);
}
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));
}
Aggregations