use of org.activityinfo.legacy.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.
the class AdminEntityProxy method load.
@Override
protected void load(Object loadConfig, final AsyncCallback<ListResult<AdminEntityDTO>> callback) {
GetAdminEntities query = new GetAdminEntities(levelId);
query.setParentId(parentId);
dispatcher.execute(query, new AsyncCallback<AdminEntityResult>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(AdminEntityResult result) {
callback.onSuccess(result);
}
});
}
use of org.activityinfo.legacy.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.
the class GetAdminEntitiesHandlerTest method testChildQuery.
@Test
public void testChildQuery() throws Exception {
GetAdminEntities cmd = new GetAdminEntities(2, 2);
AdminEntityResult result = execute(cmd);
assertThat(result.getData().size(), equalTo(3));
AdminEntityDTO kalehe = result.getData().get(0);
assertThat(kalehe.getName(), equalTo("Kalehe"));
assertThat(kalehe.getBounds(), is(not(nullValue())));
assertThat(kalehe.getBounds().getMinLon(), equalTo(-44d));
assertThat(kalehe.getBounds().getMinLat(), equalTo(-22d));
assertThat(kalehe.getBounds().getMaxLon(), equalTo(33.5d));
assertThat(kalehe.getBounds().getMaxLat(), equalTo(40d));
}
use of org.activityinfo.legacy.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.
the class GetAdminEntitiesHandlerTest method testRootLevelQuery.
@Test
public void testRootLevelQuery() throws Exception {
GetAdminEntities cmd = new GetAdminEntities(PROVINCE);
AdminEntityResult result = execute(cmd);
assertThat(result.getData().size(), equalTo(4));
}
use of org.activityinfo.legacy.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.
the class GetAdminEntitiesHandlerTest method testSiteQuery.
@Test
public void testSiteQuery() throws Exception {
GetAdminEntities cmd = new GetAdminEntities();
cmd.setLevelId(1);
cmd.setFilter(Filter.filter().onActivity(2));
AdminEntityResult result = execute(cmd);
assertThat(result.getData().size(), equalTo(2));
}
use of org.activityinfo.legacy.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.
the class GetAdminEntitiesHandler method execute.
@Override
public void execute(GetAdminEntities cmd, ExecutionContext context, final AsyncCallback<AdminEntityResult> callback) {
SqlQuery query = SqlQuery.select("AdminEntity.adminEntityId", "AdminEntity.name", "AdminEntity.adminLevelId", "AdminEntity.adminEntityParentId", "x1", "y1", "x2", "y2").from(Tables.ADMIN_ENTITY, "AdminEntity").whereTrue("not AdminEntity.deleted");
query.orderBy("AdminEntity.name");
if (cmd.getLevelId() != null) {
query.where("AdminEntity.AdminLevelId").equalTo(cmd.getLevelId());
} else {
query.leftJoin(Tables.ADMIN_LEVEL, "level").on("AdminEntity.AdminLevelID=level.AdminLevelId");
query.appendColumn("level.name", "levelName");
}
if (cmd.getEntityIds() != null && !cmd.getEntityIds().isEmpty()) {
query.where("AdminEntity.AdminEntityId").in(cmd.getEntityIds());
}
if (cmd.getParentId() != null) {
if (cmd.getParentId() == GetAdminEntities.ROOT) {
query.where("AdminEntity.AdminEntityParentId IS NULL");
} else {
query.where("AdminEntity.AdminEntityParentId").equalTo(cmd.getParentId());
}
}
if (cmd.getFilter() != null) {
Filter filter = cmd.getFilter();
if (filter.isRestricted(DimensionType.Activity) || filter.isRestricted(DimensionType.Database) || filter.isRestricted(DimensionType.Indicator)) {
SqlQuery subQuery = SqlQuery.select("link.AdminEntityId").from(Tables.SITE, "site").leftJoin(Tables.LOCATION, "Location").on("Location.LocationId = site.LocationId").leftJoin(Tables.LOCATION_ADMIN_LINK, "link").on("link.LocationId = Location.LocationId");
if (filter.isRestricted(DimensionType.Activity)) {
subQuery.where("site.ActivityId").in(filter.getRestrictions(DimensionType.Activity));
}
if (filter.isRestricted(DimensionType.Database)) {
subQuery.leftJoin(Tables.ACTIVITY, "activity").on("site.ActivityId=activity.ActivityId").where("activity.DatabaseId").in(filter.getRestrictions(DimensionType.Database));
}
if (filter.isRestricted(DimensionType.Indicator)) {
subQuery.leftJoin(Tables.REPORTING_PERIOD, "rp").on("site.siteId=rp.SiteId").leftJoin(Tables.INDICATOR_VALUE, "iv").on("iv.reportingPeriodId=rp.reportingPeriodId").where("iv.indicatorId").in(filter.getRestrictions(DimensionType.Indicator));
}
query.where("AdminEntity.AdminEntityId").in(subQuery);
}
}
if (cmd.getFilter() != null && cmd.getFilter().isRestricted(DimensionType.AdminLevel)) {
if (cmd.getLevelId() == null) {
query.where("AdminEntityId").in(cmd.getFilter().getRestrictions(DimensionType.AdminLevel));
} else {
SqlQuery subQuery = SqlQuery.select("adminEntityId").from(Tables.ADMIN_ENTITY, "AdminEntity").where("AdminLevelId").equalTo(cmd.getLevelId()).where("AdminEntityId").in(cmd.getFilter().getRestrictions(DimensionType.AdminLevel));
query.where("AdminEntity.AdminEntityId").in(subQuery);
}
}
query.execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
final List<AdminEntityDTO> entities = new ArrayList<AdminEntityDTO>();
Set<String> names = Sets.newHashSet();
Set<String> duplicates = Sets.newHashSet();
for (SqlResultSetRow row : results.getRows()) {
AdminEntityDTO entity = toEntity(row);
if (!names.add(entity.getName())) {
duplicates.add(entity.getName());
}
entities.add(entity);
}
for (int i = 0; i != entities.size(); ++i) {
if (duplicates.contains(entities.get(i).getName())) {
String levelName = results.getRow(i).getString("levelName");
entities.get(i).setName(entities.get(i).getName() + " [" + levelName + "]");
}
}
callback.onSuccess(new AdminEntityResult(entities));
}
});
}
Aggregations