Search in sources :

Example 1 with ColumnBinding

use of org.activityinfo.client.importer.column.ColumnBinding 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 ColumnBinding

use of org.activityinfo.client.importer.column.ColumnBinding in project activityinfo by bedatadriven.

the class ImporterWizard method finish.

@Override
public void finish(final AsyncCallback<Void> callback) {
    final KeyGenerator keyGenerator = new KeyGenerator();
    int numColums = model.getData().getNumColumns();
    ColumnBinding[] bindings = bindingsArray();
    // do a first pass to match the location
    List<Command> matchBatch = Lists.newArrayList();
    for (ImportRowModel row : model.getData().getRowStore().getModels()) {
        MatchLocation location = new MatchLocation();
        location.setLocationType(model.getActivity().getLocationTypeId());
        for (int i = 0; i != numColums; ++i) {
            bindings[i].bindLocation(row.get(i), location);
        }
        matchBatch.add(location);
    }
    dispatcher.execute(new BatchCommand(matchBatch), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert("Match locations failed", "Exception", null);
        }

        @Override
        public void onSuccess(BatchResult result) {
            submitSites((List) result.getResults(), callback);
        }
    });
}
Also used : ColumnBinding(org.activityinfo.client.importer.column.ColumnBinding) BatchResult(org.activityinfo.shared.command.result.BatchResult) MatchLocation(org.activityinfo.shared.command.MatchLocation) Command(org.activityinfo.shared.command.Command) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchCommand(org.activityinfo.shared.command.BatchCommand) List(java.util.List) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator)

Aggregations

ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 Command (org.activityinfo.shared.command.Command)2 BatchResult (org.activityinfo.shared.command.result.BatchResult)2 List (java.util.List)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 MatchLocation (org.activityinfo.shared.command.MatchLocation)1 LocationDTO (org.activityinfo.shared.dto.LocationDTO)1 SiteDTO (org.activityinfo.shared.dto.SiteDTO)1