Search in sources :

Example 1 with KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator 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 KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator 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 KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator 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 KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator 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)

Example 5 with KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator 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)

Aggregations

KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)12 LocationDTO (org.activityinfo.shared.dto.LocationDTO)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)6 CreateSite (org.activityinfo.shared.command.CreateSite)4 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)3 CreateResult (org.activityinfo.shared.command.result.CreateResult)3 GregorianCalendar (java.util.GregorianCalendar)2 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 Location (org.activityinfo.server.database.hibernate.entity.Location)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 Command (org.activityinfo.shared.command.Command)2 CreateLocation (org.activityinfo.shared.command.CreateLocation)2 MatchLocation (org.activityinfo.shared.command.MatchLocation)2 BatchResult (org.activityinfo.shared.command.result.BatchResult)2 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)2 RpcMap (com.extjs.gxt.ui.client.data.RpcMap)1 Date (java.util.Date)1 List (java.util.List)1