Search in sources :

Example 6 with LocationDTO

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;
        }
    }
}
Also used : LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 7 with LocationDTO

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;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO) MatchLocation(org.activityinfo.shared.command.MatchLocation) Location(org.activityinfo.server.database.hibernate.entity.Location)

Example 8 with LocationDTO

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());
    }
}
Also used : HashMap(java.util.HashMap) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) GetLocationsResult(org.activityinfo.shared.command.GetLocations.GetLocationsResult) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 9 with LocationDTO

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);
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) LocationDTO(org.activityinfo.shared.dto.LocationDTO) CreateSite(org.activityinfo.shared.command.CreateSite) Test(org.junit.Test)

Example 10 with LocationDTO

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);
        }
    });
}
Also used : Callback(org.activityinfo.client.page.entry.location.LocationDialog.Callback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) LocationDialog(org.activityinfo.client.page.entry.location.LocationDialog) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

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