Search in sources :

Example 11 with NullFormSupervisor

use of org.activityinfo.store.query.shared.NullFormSupervisor 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);
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 12 with NullFormSupervisor

use of org.activityinfo.store.query.shared.NullFormSupervisor 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));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 13 with NullFormSupervisor

use of org.activityinfo.store.query.shared.NullFormSupervisor in project activityinfo by bedatadriven.

the class UnaryFunctionQueryTest method setup.

@Before
public void setup() {
    catalog = new TestingStorageProvider();
    builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    intakeForm = catalog.getIntakeForm();
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) Before(org.junit.Before)

Example 14 with NullFormSupervisor

use of org.activityinfo.store.query.shared.NullFormSupervisor in project activityinfo by bedatadriven.

the class ActivityInfoClientAsyncStub method queryTableColumns.

@Override
public Promise<ColumnSet> queryTableColumns(QueryModel query) {
    try {
        FormStorageProvider catalog = newCatalog();
        ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormSupervisor());
        return Promise.resolved(builder.build(query));
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor)

Example 15 with NullFormSupervisor

use of org.activityinfo.store.query.shared.NullFormSupervisor in project activityinfo by bedatadriven.

the class GetSitesHandler method initialiseHandler.

private void initialiseHandler(GetSites command, User user) {
    catalog = catalogProvider.get();
    if (catalog != null) {
        this.command = command;
        builder = new ColumnSetBuilder(catalog, new AppEngineFormScanCache(), new FormSupervisorAdapter(catalog, user.getId()));
        linkedBuilder = new ColumnSetBuilder(catalog, new AppEngineFormScanCache(), new NullFormSupervisor());
        batchFormTreeBuilder = new BatchingFormTreeBuilder(catalog);
        batch = builder.createNewBatch();
        linkedBatch = linkedBuilder.createNewBatch();
        selfLinkedActivities = Maps.newHashMap();
        sortInfo = command.getSortInfo();
        offset = command.getOffset();
        limit = command.getLimit();
        totalResultLength = 0;
    } else {
        throw new CommandException("Could not retrieve form catalog");
    }
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) AppEngineFormScanCache(org.activityinfo.store.hrd.AppEngineFormScanCache) FormSupervisorAdapter(org.activityinfo.store.query.server.FormSupervisorAdapter) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) CommandException(org.activityinfo.legacy.shared.exception.CommandException) BatchingFormTreeBuilder(org.activityinfo.store.spi.BatchingFormTreeBuilder)

Aggregations

ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)16 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)16 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)11 Test (org.junit.Test)10 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)8 ColumnView (org.activityinfo.model.query.ColumnView)7 FormClass (org.activityinfo.model.form.FormClass)4 FormField (org.activityinfo.model.form.FormField)3 Quantity (org.activityinfo.model.type.number.Quantity)3 QuantityType (org.activityinfo.model.type.number.QuantityType)3 EnumColumnView (org.activityinfo.model.query.EnumColumnView)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 RecordRef (org.activityinfo.model.type.RecordRef)1 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)1 AppEngineFormScanCache (org.activityinfo.store.hrd.AppEngineFormScanCache)1 FormSupervisorAdapter (org.activityinfo.store.query.server.FormSupervisorAdapter)1 Updater (org.activityinfo.store.query.server.Updater)1