Search in sources :

Example 1 with LocationDTO

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

the class ImporterWizard method submitSites.

private void submitSites(List<LocationDTO> results, final AsyncCallback<Void> callback) {
    int numColums = model.getData().getNumColumns();
    ColumnBinding[] bindings = bindingsArray();
    KeyGenerator keyGenerator = new KeyGenerator();
    // do a first pass to match the location
    List<Command> siteBatch = Lists.newArrayList();
    int rowIndex = 0;
    for (ImportRowModel row : model.getData().getRowStore().getModels()) {
        LocationDTO location = results.get(rowIndex);
        if (location.isNew()) {
            siteBatch.add(new CreateLocation(location));
        }
        SiteDTO site = new SiteDTO();
        site.setId(keyGenerator.generateInt());
        site.setReportingPeriodId(keyGenerator.generateInt());
        site.setActivityId(model.getActivity().getId());
        site.setLocationId(location.getId());
        site.setPartner(model.getActivity().getDatabase().getPartners().get(0));
        for (int i = 0; i != numColums; ++i) {
            bindings[i].bindSite(row.get(i), site);
        }
        siteBatch.add(new CreateSite(site));
        rowIndex++;
    }
    dispatcher.execute(new BatchCommand(siteBatch), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert("Import failed", "Exception: " + caught.getMessage(), null);
            callback.onFailure(null);
        }

        @Override
        public void onSuccess(BatchResult result) {
            MessageBox.alert("Import succeeded!", "Refresh the data grid to see your new sites", null);
            callback.onSuccess(null);
        }
    });
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) ColumnBinding(org.activityinfo.client.importer.column.ColumnBinding) BatchResult(org.activityinfo.shared.command.result.BatchResult) CreateSite(org.activityinfo.shared.command.CreateSite) Command(org.activityinfo.shared.command.Command) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchCommand(org.activityinfo.shared.command.BatchCommand) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 2 with LocationDTO

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

the class BoundLocationSection method newLocation.

private void newLocation() {
    location = new LocationDTO(location);
    location.setId(new KeyGenerator().generateInt());
    location.setName(leafComboBox.getValue().getName());
    for (AdminLevelDTO level : adminFieldSet.getAdminLevels()) {
        location.setAdminEntity(level.getId(), adminFieldSet.getAdminEntity(level));
    }
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 3 with LocationDTO

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

the class SiteDialogLauncher method addNewSiteWithBoundLocation.

private void addNewSiteWithBoundLocation(ActivityDTO activity, SiteDialogCallback callback) {
    SiteDTO newSite = new SiteDTO();
    newSite.setActivityId(activity.getId());
    LocationDTO location = new LocationDTO();
    location.setId(new KeyGenerator().generateInt());
    location.setLocationTypeId(activity.getLocationTypeId());
    SiteDialog dialog = new SiteDialog(dispatcher, activity);
    dialog.showNew(newSite, location, true, callback);
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 4 with LocationDTO

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

the class LocationMap method updateSearchMarkers.

private void updateSearchMarkers() {
    markerLayer.clearLayers();
    List<LocationDTO> locations = Lists.reverse(searchPresenter.getStore().getModels());
    LatLngBounds bounds = new LatLngBounds();
    boolean empty = true;
    for (LocationDTO location : locations) {
        if (location.hasCoordinates()) {
            LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
            Marker marker = createMarker(latLng, location.getMarker());
            markerLayer.addLayer(marker);
            bounds.extend(latLng);
            bindClickEvent(location, marker);
            empty = false;
        }
    }
    if (empty) {
        if (searchPresenter.getBounds() != null) {
            bounds = LeafletUtil.newLatLngBounds(searchPresenter.getBounds());
        } else {
            bounds = LeafletUtil.newLatLngBounds(searchPresenter.getCountry().getBounds());
        }
    }
    int effectiveZoom = Math.min(8, map.getBoundsZoom(bounds, false));
    map.setView(bounds.getCenter(), effectiveZoom, false);
    map.fitBounds(bounds);
}
Also used : LatLngBounds(org.discotools.gwt.leaflet.client.types.LatLngBounds) LatLng(org.discotools.gwt.leaflet.client.types.LatLng) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Marker(org.discotools.gwt.leaflet.client.marker.Marker) LocationDTO(org.activityinfo.shared.dto.LocationDTO) Point(org.discotools.gwt.leaflet.client.types.Point)

Example 5 with LocationDTO

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

the class LocationForm method saveNewLocation.

private void saveNewLocation() {
    if (coordinateFields.validate() && nameField.validate()) {
        LocationDTO newLocation = new LocationDTO();
        newLocation.setId(new KeyGenerator().generateInt());
        newLocation.setLocationTypeId(locationType.getId());
        newLocation.setName(nameField.getValue());
        newLocation.setAxe(axeField.getValue());
        newLocation.setLatitude(coordinateFields.getLatitudeField().getValue());
        newLocation.setLongitude(coordinateFields.getLongitudeField().getValue());
        for (AdminLevelDTO level : adminPresenter.getAdminLevels()) {
            newLocation.setAdminEntity(level.getId(), adminPresenter.getAdminEntity(level));
        }
        newLocationPresenter.accept(newLocation);
    }
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) 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