Search in sources :

Example 6 with BatchCommand

use of org.activityinfo.shared.command.BatchCommand in project activityinfo by bedatadriven.

the class ActivityTest method updateSortOrderTest.

@Test
public void updateSortOrderTest() throws Throwable {
    /* Update Sort Order */
    Map<String, Object> changes1 = new HashMap<String, Object>();
    changes1.put("sortOrder", 2);
    Map<String, Object> changes2 = new HashMap<String, Object>();
    changes2.put("sortOrder", 1);
    execute(new BatchCommand(new UpdateEntity("Activity", 1, changes1), new UpdateEntity("Activity", 2, changes2)));
    /* Confirm the order is changed */
    SchemaDTO schema = execute(new GetSchema());
    Assert.assertEquals(2, schema.getDatabaseById(1).getActivities().get(0).getId());
    Assert.assertEquals(1, schema.getDatabaseById(1).getActivities().get(1).getId());
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) BatchCommand(org.activityinfo.shared.command.BatchCommand) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 7 with BatchCommand

use of org.activityinfo.shared.command.BatchCommand 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)

Example 8 with BatchCommand

use of org.activityinfo.shared.command.BatchCommand in project activityinfo by bedatadriven.

the class DbUserEditor method save.

private void save() {
    BatchCommand batch = new BatchCommand();
    for (Record record : store.getModifiedRecords()) {
        batch.add(new UpdateUserPermissions(db.getId(), (UserPermissionDTO) record.getModel()));
    }
    dispatcher.execute(batch, new MaskingAsyncMonitor(this, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // handled by monitor
        }

        @Override
        public void onSuccess(BatchResult result) {
            store.commitChanges();
        }
    });
}
Also used : UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.shared.command.BatchCommand) Record(com.extjs.gxt.ui.client.store.Record) BatchResult(org.activityinfo.shared.command.result.BatchResult) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO)

Example 9 with BatchCommand

use of org.activityinfo.shared.command.BatchCommand in project activityinfo by bedatadriven.

the class TargetTest method updateTargetNameTest.

@Test
public void updateTargetNameTest() throws Throwable {
    Map<String, Object> changes1 = new HashMap<String, Object>();
    changes1.put("name", "newNameOfTarget");
    execute(new BatchCommand(new UpdateEntity("Target", 1, changes1)));
    List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
    TargetDTO dto = getTargetById(targets, 1);
    Assert.assertEquals("newNameOfTarget", dto.getName());
}
Also used : GetTargets(org.activityinfo.shared.command.GetTargets) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) BatchCommand(org.activityinfo.shared.command.BatchCommand) TargetDTO(org.activityinfo.shared.dto.TargetDTO) Test(org.junit.Test)

Aggregations

BatchCommand (org.activityinfo.shared.command.BatchCommand)9 BatchResult (org.activityinfo.shared.command.result.BatchResult)7 Command (org.activityinfo.shared.command.Command)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)3 GetSchema (org.activityinfo.shared.command.GetSchema)3 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 GetReportVisibility (org.activityinfo.shared.command.GetReportVisibility)2 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)2 CommandResult (org.activityinfo.shared.command.result.CommandResult)2 ReportVisibilityResult (org.activityinfo.shared.command.result.ReportVisibilityResult)2 Test (org.junit.Test)2 Record (com.extjs.gxt.ui.client.store.Record)1 List (java.util.List)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 GetReportModel (org.activityinfo.shared.command.GetReportModel)1