Search in sources :

Example 1 with NullFormSupervisor

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

the class ResourceLocatorSyncImpl method getReferenceChoices.

@Override
public List<ReferenceChoice> getReferenceChoices(Collection<ResourceId> range) {
    ResourceId formId = Iterables.getOnlyElement(range);
    QueryModel queryModel = new QueryModel(formId);
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr("label").as("label");
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog.get(), new NullFormSupervisor());
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView id = columnSet.getColumnView("id");
    ColumnView label = columnSet.getColumnView("label");
    List<ReferenceChoice> choices = Lists.newArrayList();
    for (int i = 0; i < columnSet.getNumRows(); i++) {
        ResourceId choiceId = ResourceId.valueOf(id.getString(i));
        String choiceLabel = label.getString(i);
        choices.add(new ReferenceChoice(new RecordRef(formId, choiceId), choiceLabel));
    }
    return choices;
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel)

Example 2 with NullFormSupervisor

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

the class HrdCatalogTest method simpleFormTest.

@Test
public void simpleFormTest() {
    ResourceId collectionId = ResourceId.generateId();
    ResourceId villageField = ResourceId.valueOf("FV");
    ResourceId countField = ResourceId.valueOf("FC");
    FormClass formClass = new FormClass(collectionId);
    formClass.setParentFormId(ResourceId.valueOf("foo"));
    formClass.setLabel("NFI Distributions");
    formClass.addField(villageField).setLabel("Village name").setCode("VILLAGE").setType(TextType.SIMPLE);
    formClass.addField(countField).setLabel("Number of Beneficiaries").setCode("BENE").setType(new QuantityType("Beneficiaries"));
    HrdStorageProvider catalog = new HrdStorageProvider();
    catalog.create(formClass);
    Optional<FormStorage> storage = catalog.getForm(collectionId);
    assertTrue(storage.isPresent());
    TypedRecordUpdate village1 = new TypedRecordUpdate();
    village1.setUserId(userId);
    village1.setRecordId(ResourceId.generateSubmissionId(formClass));
    village1.set(villageField, TextValue.valueOf("Rutshuru"));
    village1.set(countField, new Quantity(1000));
    TypedRecordUpdate village2 = new TypedRecordUpdate();
    village2.setUserId(userId);
    village2.setRecordId(ResourceId.generateSubmissionId(formClass));
    village2.set(villageField, TextValue.valueOf("Beni"));
    village2.set(countField, new Quantity(230));
    storage.get().add(village1);
    storage.get().add(village2);
    QueryModel queryModel = new QueryModel(collectionId);
    queryModel.selectResourceId().as("id");
    queryModel.selectField("VILLAGE").as("village");
    queryModel.selectField("BENE").as("family_count");
    queryModel.selectExpr("BENE*5").as("individual_count");
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormSupervisor());
    ColumnSet columnSet = builder.build(queryModel);
    System.out.println(columnSet);
    assertThat(columnSet.getNumRows(), equalTo(2));
    List<RecordVersion> versions1 = ((VersionedFormStorage) storage.get()).getVersions(village1.getRecordId());
    assertThat(versions1, hasSize(1));
    RecordVersion version = versions1.get(0);
    assertThat(version.getRecordId(), equalTo(village1.getRecordId()));
    assertThat(version.getUserId(), equalTo((long) userId));
    assertThat(version.getType(), equalTo(RecordChangeType.CREATED));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) Test(org.junit.Test)

Example 3 with NullFormSupervisor

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

the class DateFunctionQueryTest method invalidArityTest.

@Test
public void invalidArityTest() {
    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("YEARFRAC(TODAY())").as("age");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView age = columnSet.getColumnView("age");
    assertThat(age.numRows(), equalTo(IntakeForm.ROW_COUNT));
    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 4 with NullFormSupervisor

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

the class DateFunctionQueryTest method testFloorToday.

@Test
public void testFloorToday() {
    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("FLOOR(YEARFRAC(\"2017-05-05\", DOB))").as("ageFloored");
    queryModel.selectExpr("FLOOR(1.5)").as("floor");
    queryModel.selectExpr("DOB").as("dob");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView floor = columnSet.getColumnView("floor");
    ColumnView ageFloored = columnSet.getColumnView("ageFloored");
    assertThat(floor.numRows(), equalTo(intakeForm.getRecords().size()));
    assertThat(floor.getDouble(0), equalTo(1.0));
    assertThat(ageFloored.getDouble(0), equalTo(45.0));
    assertThat(ageFloored.getDouble(3), equalTo(29.0));
    System.out.println(ageFloored);
}
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 5 with NullFormSupervisor

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

the class EnumerationQueryTest method enumIdTests.

@Test
public void enumIdTests() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(EmptyForm.FORM_ID);
    queryModel.selectField(EmptyForm.ENUM_FIELD_ID).as("emptyEnum");
    queryModel.selectField(EmptyForm.POP_ENUM_FIELD_ID).as("populatedEnum");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView emptyEnum = columnSet.getColumnView("emptyEnum");
    ColumnView populatedEnum = columnSet.getColumnView("populatedEnum");
    // // Standard Enum Id Checks
    // Null check on empty set first
    assertThat(emptyEnum.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptyEnum).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedEnum.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedEnum).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
    // // Selected Row Enum Id Checks
    ColumnView emptySelectedRow = emptyEnum.select(new int[] { 0 });
    ColumnView populatedSelectedRow = populatedEnum.select(new int[] { 0 });
    // Null check on empty set first
    assertThat(emptySelectedRow.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptySelectedRow).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedSelectedRow.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedSelectedRow).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
}
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)

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