use of org.activityinfo.shared.command.GetLocations.GetLocationsResult in project activityinfo by bedatadriven.
the class GetLocationsHandler method execute.
@Override
public void execute(final GetLocations command, final ExecutionContext context, final AsyncCallback<GetLocationsResult> callback) {
if (command.hasLocationIds()) {
final Map<Integer, LocationDTO> dtos = new HashMap<Integer, LocationDTO>();
SqlQuery.select("locationID", "name", "axe", "x", "y").from(Tables.LOCATION).where("locationId").in(command.getLocationIds()).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"));
if (!row.isNull("x") && !row.isNull("y")) {
dto.setLatitude(row.getDouble("y"));
dto.setLongitude(row.getDouble("x"));
}
dtos.put(dto.getId(), dto);
}
SqlQuery.select().appendColumn("AdminEntity.AdminEntityId", "adminEntityId").appendColumn("AdminEntity.Name", "name").appendColumn("AdminEntity.AdminLevelId", "levelId").appendColumn("link.LocationID", "locationId").from(Tables.LOCATION_ADMIN_LINK, "link").leftJoin(Tables.ADMIN_ENTITY, "AdminEntity").on("link.AdminEntityId=AdminEntity.AdminEntityId").where("link.LocationId").in(command.getLocationIds()).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"));
LocationDTO dto = dtos.get(row.getInt("locationId"));
if (dto != null) {
dto.setAdminEntity(entity.getLevelId(), entity);
}
}
List<LocationDTO> list = new ArrayList<LocationDTO>(dtos.values());
callback.onSuccess(new GetLocationsResult(list));
}
});
}
});
} else {
callback.onSuccess(new GetLocationsResult());
}
}
use of org.activityinfo.shared.command.GetLocations.GetLocationsResult in project activityinfo by bedatadriven.
the class SiteHistoryTab method setSite.
// retrieve all needed data: sitehistoryresult, schema, and locations
public void setSite(final SiteDTO site) {
renderLoading();
dispatcher.execute(new GetSiteHistory(site.getId()), new AsyncCallback<GetSiteHistoryResult>() {
@Override
public void onFailure(Throwable caught) {
renderNotAvailable(site);
}
@Override
public void onSuccess(final GetSiteHistoryResult historyResult) {
if (historyResult.hasHistories()) {
dispatcher.execute(new GetLocations(historyResult.collectLocationIds()), new AsyncCallback<GetLocationsResult>() {
@Override
public void onFailure(Throwable caught) {
renderNotAvailable(site);
}
@Override
public void onSuccess(final GetLocationsResult locationsResult) {
dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
renderNotAvailable(site);
}
@Override
public void onSuccess(SchemaDTO schema) {
render(schema, locationsResult.getLocations(), site, historyResult.getSiteHistories());
}
});
}
});
} else {
renderNotAvailable(site);
}
}
});
}
Aggregations