use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class AsyncClientStub method queryTableColumns.
@Override
public Promise<ColumnSet> queryTableColumns(QueryModel query) {
if (!connected) {
return offlineResult();
}
ColumnSetBuilder columnSetBuilder = new ColumnSetBuilder(storageProvider, new NullFormScanCache(), new NullFormSupervisor());
ColumnSet columnSet = columnSetBuilder.build(query);
return Promise.resolved(columnSet);
}
use of org.activityinfo.model.query.ColumnSet 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()));
}
use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class FormStoreTest method offlineColumnQuery.
@Test
public void offlineColumnQuery() {
TestSetup setup = new TestSetup();
Survey survey = setup.getSurveyForm();
setup.getFormStore().setFormOffline(survey.getFormId(), true);
setup.runScheduled();
setup.setConnected(false);
Connection<SnapshotStatus> snapshot = setup.connect(setup.getOfflineStore().getCurrentSnapshot());
assertTrue(snapshot.assertLoaded().isFormCached(survey.getFormId()));
QueryModel queryModel = new QueryModel(survey.getFormId());
queryModel.selectResourceId().as("id");
queryModel.selectField(survey.getNameFieldId()).as("name");
queryModel.selectField(survey.getAgeFieldId()).as("age");
ColumnSet columnSet = setup.connect(setup.getFormStore().query(queryModel)).assertLoaded();
assertThat(columnSet.getNumRows(), equalTo(survey.getRowCount()));
assertThat(columnSet.getColumnView("name").get(0), equalTo("Melanie"));
assertThat(columnSet.getColumnView("name").get(1), equalTo("Joe"));
assertThat(columnSet.getColumnView("name").get(2), equalTo("Matilda"));
}
use of org.activityinfo.model.query.ColumnSet 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));
}
use of org.activityinfo.model.query.ColumnSet in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormPane.
@Test
public void testSubFormPane() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> subTableView = setup.connect(viewModel.getEffectiveSubTable(ReferralSubForm.FORM_ID));
Connection<ColumnSet> subTable = setup.connect(subTableView.assertLoaded().getColumnSet());
// The sub table should not include parent forms
for (EffectiveTableColumn subColumn : subTableView.assertLoaded().getColumns()) {
if (subColumn.getLabel().equals(incidentForm.getUrgencyField().getLabel())) {
throw new AssertionError("Sub table should not include parent fields");
}
}
// Initially there should be no rows because there is no selection
assertThat(subTable.assertLoaded().getNumRows(), equalTo(0));
// Once we make a selection, then the column set should update to show the sub records of the selected
// parent record
subTable.resetChangeCounter();
viewModel.select(incidentForm.getRecordRef(0));
setup.runScheduled();
subTable.assertChanged();
assertThat(subTable.assertLoaded().getNumRows(), equalTo(4));
}
Aggregations