Search in sources :

Example 1 with LocationResult

use of org.activityinfo.shared.command.result.LocationResult in project activityinfo by bedatadriven.

the class SearchLocationsHandler method retrieveLocations.

private void retrieveLocations(final SearchLocations command, final ExecutionContext context, final AsyncCallback<LocationResult> callback) {
    SqlQuery query = baseQuery(command).appendColumns("LocationId", "Name", "Axe", "X", "Y").setLimitClause(dialect.limitClause(0, 26));
    query.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            // Create a list of locations from query result
            List<LocationDTO> locations = Lists.newArrayList();
            Map<Integer, LocationDTO> locationsById = Maps.newHashMap();
            for (SqlResultSetRow row : results.getRows()) {
                LocationDTO location = LocationDTO.fromSqlRow(row);
                locations.add(location);
                locationsById.put(location.getId(), location);
            }
            LocationResult result = new LocationResult(locations);
            result.setOffset(0);
            result.setTotalLength(results.getRows().size());
            callback.onSuccess(result);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ArrayList(java.util.ArrayList) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) Map(java.util.Map) LocationDTO(org.activityinfo.shared.dto.LocationDTO) LocationResult(org.activityinfo.shared.command.result.LocationResult)

Example 2 with LocationResult

use of org.activityinfo.shared.command.result.LocationResult in project activityinfo by bedatadriven.

the class CreateLocationTest method test.

@Test
public void test() throws CommandException {
    LocationDTO location = LocationDTOs.newLocation();
    execute(new CreateLocation(location));
    SearchLocations getLocations = new SearchLocations().setName(location.getName());
    LocationResult locations = execute(getLocations);
    LocationDTO newLocation = locations.getData().get(0);
    assertEquals(location.getName(), newLocation.getName());
    assertEquals(location.getAxe(), newLocation.getAxe());
    assertEquals(location.getLongitude(), newLocation.getLongitude());
    assertEquals(location.getLatitude(), newLocation.getLatitude());
}
Also used : LocationDTO(org.activityinfo.shared.dto.LocationDTO) LocationResult(org.activityinfo.shared.command.result.LocationResult) Test(org.junit.Test)

Example 3 with LocationResult

use of org.activityinfo.shared.command.result.LocationResult in project activityinfo by bedatadriven.

the class SearchLocationsHandlerTest method test.

@Test
public void test() throws CommandException {
    SearchLocations getLocations = new SearchLocations().setAdminEntityIds(Arrays.asList(3, 12)).setName("Sh");
    LocationResult result = execute(getLocations);
    assertTrue(result.getData().size() == 1);
}
Also used : LocationResult(org.activityinfo.shared.command.result.LocationResult) Test(org.junit.Test)

Aggregations

LocationResult (org.activityinfo.shared.command.result.LocationResult)3 LocationDTO (org.activityinfo.shared.dto.LocationDTO)2 Test (org.junit.Test)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1