Search in sources :

Example 11 with LocationDTO

use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.

the class SiteDialog method showExisting.

public void showExisting(SiteDTO site, SiteDialogCallback callback) {
    this.newSite = false;
    this.site = site;
    this.callback = callback;
    LocationDTO location = site.getLocation();
    location.setLocationTypeId(activity.getLocationTypeId());
    locationForm.updateForm(location, false);
    updateForms(site);
    show();
}
Also used : LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 12 with LocationDTO

use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.

the class SiteDialogLauncher method chooseLocationThenAddSite.

private void chooseLocationThenAddSite(final ActivityDTO activity, final SiteDialogCallback callback) {
    LocationDialog dialog = new LocationDialog(dispatcher, activity.getDatabase().getCountry(), activity.getLocationType());
    dialog.show(new LocationDialog.Callback() {

        @Override
        public void onSelected(LocationDTO location, boolean isNew) {
            SiteDTO newSite = new SiteDTO();
            newSite.setActivityId(activity.getId());
            newSite.setLocation(location);
            SiteDialog dialog = new SiteDialog(dispatcher, activity);
            dialog.showNew(newSite, location, isNew, callback);
        }
    });
}
Also used : LocationDialog(org.activityinfo.client.page.entry.location.LocationDialog) SiteDTO(org.activityinfo.shared.dto.SiteDTO) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 13 with LocationDTO

use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.

the class FormSubmissionResource method createCreateLocationCommand.

private CreateLocation createCreateLocationCommand(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
    // create the dto
    LocationDTO loc = new LocationDTO();
    loc.setId(new KeyGenerator().generateInt());
    loc.setLocationTypeId(activity.getLocationTypeId());
    loc.setName(data.getLocationname());
    loc.setLatitude(data.getLatitude());
    loc.setLongitude(data.getLongitude());
    CreateLocation cmd = new CreateLocation(loc);
    // get adminentities that contain the specified coordinates
    List<AdminEntity> adminentities = geocoder.geocode(data.getLatitude(), data.getLongitude());
    if (adminentities.isEmpty()) {
        AdminEntity adminEntity = createDebugAdminEntity();
        if (adminEntity != null) {
            adminentities.add(adminEntity);
        }
    }
    if (!adminentities.isEmpty()) {
        RpcMap map = cmd.getProperties();
        for (AdminEntity entity : adminentities) {
            map.put(AdminLevelDTO.getPropertyName(entity.getLevel().getId()), entity.getId());
        }
    }
    return cmd;
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) RpcMap(com.extjs.gxt.ui.client.data.RpcMap) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 14 with LocationDTO

use of org.activityinfo.shared.dto.LocationDTO 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 15 with LocationDTO

use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.

the class GetLocationsTest method testGetLocation.

@Test
public void testGetLocation() {
    setUser(1);
    LocationDTO location = execute(new GetLocations(1)).getLocation();
    assertThat(location, notNullValue());
    assertThat(location.getName(), equalTo("Penekusu Kivu"));
    assertThat(location.getAxe(), nullValue());
    assertThat(location.getAdminEntity(1).getName(), equalTo("Sud Kivu"));
    assertThat(location.getAdminEntity(2).getName(), equalTo("Shabunda"));
}
Also used : GetLocations(org.activityinfo.shared.command.GetLocations) LocationDTO(org.activityinfo.shared.dto.LocationDTO) Test(org.junit.Test)

Aggregations

LocationDTO (org.activityinfo.shared.dto.LocationDTO)17 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)5 CreateLocation (org.activityinfo.shared.command.CreateLocation)4 Test (org.junit.Test)4 CreateSite (org.activityinfo.shared.command.CreateSite)3 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 ArrayList (java.util.ArrayList)2 LocationDialog (org.activityinfo.client.page.entry.location.LocationDialog)2 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 LocationResult (org.activityinfo.shared.command.result.LocationResult)2 AdminEntityDTO (org.activityinfo.shared.dto.AdminEntityDTO)2 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)2 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 RpcMap (com.extjs.gxt.ui.client.data.RpcMap)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1