use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class ApiTestHarness method createDatabase.
public TestDatabase createDatabase() {
String name = aliasTable.createAlias("db");
ActivityInfoClient client = client();
ResourceId databaseId = client.createDatabase(name);
int id = CuidAdapter.getLegacyIdFromCuid(databaseId);
// Query list of partners
QueryModel queryModel = new QueryModel(CuidAdapter.partnerFormId(id));
queryModel.selectResourceId().as("id");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView partnerIdView = columnSet.getColumnView("id");
ResourceId firstPartnerId = ResourceId.valueOf(partnerIdView.getString(0));
return new TestDatabase(databaseId, name, firstPartnerId);
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class DateFunctionQueryTest method testToday.
@Test
public void testToday() {
TestingStorageProvider catalog = new TestingStorageProvider();
IntakeForm intakeForm = catalog.getIntakeForm();
ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
QueryModel queryModel = new QueryModel(intakeForm.getFormId());
queryModel.selectExpr("TODAY()").as("today");
queryModel.selectExpr("YEARFRAC(TODAY(), DOB)").as("age");
queryModel.selectExpr("DOB").as("dob");
ColumnSet columnSet = builder.build(queryModel);
ColumnView today = columnSet.getColumnView("today");
ColumnView age = columnSet.getColumnView("age");
ColumnView dob = columnSet.getColumnView("dob");
for (int i = 0; i < columnSet.getNumRows(); i++) {
if (dob.getString(i) != null) {
double ageInYears = age.getDouble(i);
System.out.println(dob.get(i) + " " + ageInYears);
if (Double.isNaN(ageInYears)) {
throw new AssertionError();
}
}
}
System.out.println(age);
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class EnumerationQueryTest method enumRefTests.
@Test
public void enumRefTests() {
TestingStorageProvider catalog = new TestingStorageProvider();
ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
IntakeForm intakeForm = catalog.getIntakeForm();
QueryModel queryModel = new QueryModel(intakeForm.getFormId());
queryModel.selectField(intakeForm.getNationalityFieldId()).as("nationality");
queryModel.selectExpr(intakeForm.getNationalityFieldId() + "==" + "\"" + intakeForm.getPalestinianId() + "\"").as("palestinian");
queryModel.selectExpr("\"" + intakeForm.getPalestinianId() + "\"" + "==" + intakeForm.getNationalityFieldId()).as("palestinianInverse");
ColumnSet columnSet = builder.build(queryModel);
ColumnView nationality = columnSet.getColumnView("nationality");
ColumnView palestinian = columnSet.getColumnView("palestinian");
ColumnView palestinianInverse = columnSet.getColumnView("palestinianInverse");
// Correct Tests
assertThat(nationality.get(1).toString(), equalTo(NAT_PAL));
assertThat(Boolean.valueOf(palestinian.get(1).toString()), equalTo(true));
assertThat(Boolean.valueOf(palestinianInverse.get(1).toString()), equalTo(true));
// Incorrect Tests
// Multiple selected values should return null
assertThat(nationality.get(5), equalTo(null));
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class SubFormDeletionTest method deleteParent.
@Test
public void deleteParent() {
QueryModel queryModel = new QueryModel(ReferralSubForm.FORM_ID);
queryModel.selectResourceId().as("id");
queryModel.selectExpr(new CompoundExpr(IncidentForm.FORM_ID, ColumnModel.ID_SYMBOL)).as("parent");
queryModel.selectExpr(new ConstantNode(1)).as("count");
ColumnSet columnSet = query(queryModel);
assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT));
System.out.println(columnSet.getColumnView("parent"));
// Now delete a number of parent records
delete(IncidentForm.FORM_ID, "c528");
// The query results should reflect the change
columnSet = query(queryModel);
assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT - 2));
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class UnaryFunctionQueryTest method divideFunctionTest.
@Test
public void divideFunctionTest() {
QueryModel queryModel = new QueryModel(intakeForm.getFormId());
makeQueryExprAndExpectColumnModelException(queryModel, "/1", "divOne");
makeQueryExprAndExpectColumnModelException(queryModel, "/1.0", "divOneDouble");
makeQueryExprAndExpectColumnModelException(queryModel, "1/", "oneDiv");
makeQueryExprAndExpectColumnModelException(queryModel, "1.0/", "oneDivDouble");
}
Aggregations