Search in sources :

Example 6 with RecordTransactionBuilder

use of org.activityinfo.model.resource.RecordTransactionBuilder in project activityinfo by bedatadriven.

the class FormInputViewModel method buildTransaction.

public RecordTransaction buildTransaction() {
    RecordTransactionBuilder tx = new RecordTransactionBuilder();
    tx.add(buildUpdate(Optional.absent()));
    for (SubFormViewModel subFormViewModel : subFormMap.values()) {
        tx.add(subFormViewModel.buildUpdates(inputModel.getRecordRef()));
    }
    return tx.build();
}
Also used : RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder)

Example 7 with RecordTransactionBuilder

use of org.activityinfo.model.resource.RecordTransactionBuilder in project activityinfo by bedatadriven.

the class FormStoreTest method serialNumberOffline.

@Test
public void serialNumberOffline() {
    TestSetup setup = new TestSetup();
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    // Synchronize the intake form
    setup.setConnected(true);
    setup.getFormStore().setFormOffline(intakeForm.getFormId(), true);
    setup.runScheduled();
    // Go offline
    setup.setConnected(false);
    // Create a new intake record
    FormInstance newRecord = intakeForm.getGenerator().get();
    newRecord.set(intakeForm.getProtectionCodeFieldId(), (FieldValue) null);
    Promise<Void> update = setup.getFormStore().updateRecords(new RecordTransactionBuilder().create(newRecord).build());
    assertThat(update.getState(), equalTo(Promise.State.FULFILLED));
    // Verify that we can read the new record offline
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectField(intakeForm.getProtectionCodeFieldId()).as("serial");
    queryModel.setFilter(Formulas.equals(new SymbolNode("_id"), new ConstantNode(newRecord.getId().asString())));
    Connection<ColumnSet> view = setup.connect(setup.getFormStore().query(queryModel));
    assertThat(view.assertLoaded().getNumRows(), equalTo(1));
    assertThat(view.assertLoaded().getColumnView("serial").getString(0), nullValue());
    // Now go online...
    setup.setConnected(true);
    setup.getOfflineStore().syncChanges();
    ;
    setup.runScheduled();
    // Check that the serial number has been updated with the value from the server
    assertThat(view.assertLoaded().getColumnView("serial").getString(0), not(nullValue()));
}
Also used : RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder) SymbolNode(org.activityinfo.model.formula.SymbolNode) ConstantNode(org.activityinfo.model.formula.ConstantNode) ColumnSet(org.activityinfo.model.query.ColumnSet) FormInstance(org.activityinfo.model.form.FormInstance) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 8 with RecordTransactionBuilder

use of org.activityinfo.model.resource.RecordTransactionBuilder in project activityinfo by bedatadriven.

the class FormStoreTest method newRecordHitsQuery.

@Test
public void newRecordHitsQuery() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    Survey survey = catalog.getSurvey();
    AsyncClientStub client = new AsyncClientStub(catalog);
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    // Open a query on a set of records
    QueryModel queryModel = new QueryModel(survey.getFormId());
    queryModel.selectResourceId().as("id");
    Connection<ColumnSet> tableView = connect(formStore.query(queryModel));
    tableView.assertLoaded();
    // Add an new record to Survey
    tableView.resetChangeCounter();
    formStore.updateRecords(new RecordTransactionBuilder().add(catalog.addNew(survey.getFormId())).build());
    // Verify that the table view has been updated
    tableView.assertLoaded();
    tableView.assertChanged();
    assertThat(tableView.assertLoaded().getNumRows(), equalTo(survey.getRowCount() + 1));
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)8 QueryModel (org.activityinfo.model.query.QueryModel)4 Test (org.junit.Test)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)2 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 FieldMapping (org.activityinfo.geoadmin.merge2.view.mapping.FieldMapping)1 IDBFactoryStub (org.activityinfo.indexedb.IDBFactoryStub)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 ConstantNode (org.activityinfo.model.formula.ConstantNode)1 SymbolNode (org.activityinfo.model.formula.SymbolNode)1 ColumnView (org.activityinfo.model.query.ColumnView)1 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)1 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1