use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.
the class AdminFilterPanel method getSelection.
/**
* @return the list of AdminEntityDTOs that user has selected with which the
* filter should be restricted
*/
public List<AdminEntityDTO> getSelection() {
List<AdminEntityDTO> checked = tree.getCheckedSelection();
List<AdminEntityDTO> selected = new ArrayList<AdminEntityDTO>();
for (AdminEntityDTO entity : checked) {
selected.add(entity);
}
return selected;
}
use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.
the class GetLocationsHandler method execute.
@Override
public void execute(final GetLocations command, final ExecutionContext context, final AsyncCallback<LocationResult> callback) {
if (!command.hasLocationIds() && command.getLocationTypeId() == null) {
callback.onSuccess(new LocationResult());
return;
}
final Map<Integer, LocationDTO> dtos = new HashMap<>();
SqlQuery query = SqlQuery.select("locationID", "name", "axe", "x", "y", "workflowStatusId", "LocationTypeId").from(Tables.LOCATION, "Location");
if (!command.getLocationIds().isEmpty()) {
query.where("LocationId").in(command.getLocationIds());
}
if (command.getLocationTypeId() != null) {
query.where("locationTypeId").equalTo(command.getLocationTypeId());
}
query.where("workflowstatusid").equalTo("validated");
query.execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
for (SqlResultSetRow row : results.getRows()) {
final LocationDTO dto = new LocationDTO();
dto.setId(row.getInt("locationID"));
dto.setName(row.getString("name"));
dto.setAxe(row.getString("axe"));
dto.setWorkflowStatusId(row.getString("workflowStatusId"));
dto.setLocationTypeId(row.getInt("LocationTypeId"));
if (!row.isNull("x") && !row.isNull("y")) {
dto.setLatitude(row.getDouble("y"));
dto.setLongitude(row.getDouble("x"));
}
dtos.put(dto.getId(), dto);
}
SqlQuery query = SqlQuery.select().appendColumn("AdminEntity.AdminEntityId", "adminEntityId").appendColumn("AdminEntity.Name", "name").appendColumn("AdminEntity.AdminLevelId", "levelId").appendColumn("AdminEntity.AdminEntityParentId", "parentId").appendColumn("link.LocationID", "locationId").from(Tables.LOCATION_ADMIN_LINK, "link").leftJoin(Tables.ADMIN_ENTITY, "AdminEntity").on("link.AdminEntityId=AdminEntity.AdminEntityId").whereTrue("AdminEntity.AdminEntityId is not null");
if (!command.getLocationIds().isEmpty()) {
query.where("link.LocationId").in(command.getLocationIds());
}
if (command.getLocationTypeId() != null) {
query.leftJoin(Tables.LOCATION, "Location").on("link.LocationId=Location.LocationId");
query.where("Location.LocationTypeId").equalTo(command.getLocationTypeId());
}
query.execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
for (SqlResultSetRow row : results.getRows()) {
AdminEntityDTO entity = new AdminEntityDTO();
entity.setId(row.getInt("adminEntityId"));
entity.setName(row.getString("name"));
entity.setLevelId(row.getInt("levelId"));
if (!row.isNull("parentId")) {
entity.setParentId(row.getInt("parentId"));
}
LocationDTO dto = dtos.get(row.getInt("locationId"));
if (dto != null) {
dto.setAdminEntity(entity.getLevelId(), entity);
}
}
List<LocationDTO> list = new ArrayList<>(dtos.values());
callback.onSuccess(new LocationResult(list));
}
});
}
});
}
use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.
the class AdminLevelClusterer method cluster.
@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
// admin entity id -> cluster
Map<Integer, Cluster> adminClusters = new HashMap<Integer, Cluster>();
for (PointValue pv : points) {
AdminEntityDTO entity = getAdminEntityId(pv);
if (entity != null) {
Cluster cluster = adminClusters.get(entity.getId());
if (cluster == null) {
cluster = new Cluster(pv);
cluster.setPoint(adminCenter(map, entity));
cluster.setTitle(entity.getName());
adminClusters.put(entity.getId(), cluster);
} else {
cluster.addPointValue(pv);
}
}
}
ArrayList<Cluster> clusters = Lists.newArrayList();
// update centers of clusters based on points, if any
for (Cluster cluster : adminClusters.values()) {
updateCenter(cluster);
if (cluster.hasPoint()) {
clusters.add(cluster);
}
}
radiiCalculator.calculate(clusters);
return clusters;
}
use of org.activityinfo.legacy.shared.model.AdminEntityDTO 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.model.AdminEntityDTO in project activityinfo by bedatadriven.
the class AdminFieldSetPresenterTest method expectSelections.
private void expectSelections(Collection<AdminEntityDTO> values) {
resetToDefault(selectionListener);
for (AdminEntityDTO entity : values) {
selectionListener.handleEvent(eq(new AdminLevelSelectionEvent(entity.getLevelId(), entity)));
}
replay(selectionListener);
}
Aggregations