use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class LocationSearchPresenter method numberLocations.
private void numberLocations(List<LocationDTO> locations) {
int number = 0;
for (LocationDTO location : locations) {
if (location.hasCoordinates()) {
location.setMarker(String.valueOf((char) ('A' + number)));
number++;
}
if (number >= 26) {
break;
}
}
}
use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class MatchLocationHandler method execute.
@Override
public CommandResult execute(MatchLocation cmd, User user) throws CommandException {
Map<Integer, AdminEntity> matched = Maps.newHashMap();
// now try and match against the text
for (Integer levelId : cmd.getAdminLevels().keySet()) {
matchEntity(matched, cmd.getAdminLevels(), em.find(AdminLevel.class, levelId));
}
Location matchedLocation = matchLocation(cmd.getLocationType(), cmd.getName(), matched.values());
LocationDTO location = new LocationDTO();
if (matchedLocation == null) {
// create a new location object
location.setId(new KeyGenerator().generateInt());
location.setName(cmd.getName());
location.setLatitude(cmd.getLatitude());
location.setLongitude(cmd.getLongitude());
location.setNew(true);
location.setLocationTypeId(cmd.getLocationType());
for (AdminEntity entity : matched.values()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
} else {
location.setNew(false);
location.setId(matchedLocation.getId());
location.setName(matchedLocation.getName());
location.setLatitude(matchedLocation.getY());
location.setLongitude(matchedLocation.getX());
location.setLocationTypeId(matchedLocation.getLocationType().getId());
for (AdminEntity entity : matchedLocation.getAdminEntities()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
}
return location;
}
use of org.activityinfo.shared.dto.LocationDTO 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.dto.LocationDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SiteDTO newSite = SiteDTOs.newSite();
newSite.setLocation(location);
CreateSite cmd = new CreateSite(newSite);
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
assertThat(result.getNewId(), not(equalTo(0)));
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
SiteDTOs.validateNewSite(secondRead);
}
use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class LocationSection method changeLocation.
private void changeLocation() {
LocationDialog dialog = new LocationDialog(dispatcher, activity.getDatabase().getCountry(), activity.getLocationType());
dialog.show(new Callback() {
@Override
public void onSelected(LocationDTO location, boolean isNew) {
updateForm(location, isNew);
}
});
}
Aggregations