Search in sources :

Example 6 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class SimpleConditionParser method parseEnumCondition.

private static SimpleCondition parseEnumCondition(CompoundExpr node) {
    ResourceId fieldId = parseFieldId(node.getValue());
    ResourceId enumItem = node.getField().asResourceId();
    return new SimpleCondition(fieldId, SimpleOperator.INCLUDES, new EnumValue(enumItem));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue)

Example 7 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class SkipExpressionTest method enumType.

@Test
public void enumType() {
    FormInstance instance = new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId());
    instance.set(GENDER_FIELD_ID, enumFieldValue(GENDER_FIELD_ID, "Male"));
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("{%s}!={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("({%s}=={%s})&&({%s}!={%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    // contains all
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    // enum with 2 values
    instance.set(GENDER_FIELD_ID, new EnumValue(enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()));
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("notContainsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("notContainsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("notContainsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("notContainsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 8 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class ActivityFormClassBuilderTest method nullLocationTypeIsNotVisible.

@Test
@OnDataSet("/dbunit/chad-form.db.xml")
public void nullLocationTypeIsNotVisible() {
    setUser(9944);
    int databaseId = 1470;
    FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(11218)));
    ResourceId locationFieldId = CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD);
    assertThat(formClass.getFields(), not(hasItem(withId(locationFieldId))));
    // Make sure we can update if location is not specified
    FormInstance instance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClass.getId()), formClass.getId());
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1734));
    instance.set(ResourceId.valueOf("Q0000031845"), new EnumValue(CuidAdapter.attributeField(166617)));
    assertResolves(locator.persist(instance));
    // Make sure the null location object is visible to legacy code
    SiteDTO site = execute(GetSites.byId(CuidAdapter.getLegacyIdFromCuid(instance.getId()))).getData().get(0);
    assertThat(site.getLocationName(), equalTo("Chad"));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 9 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class CompactingEnumColumnBuilderTest method buildCompact.

@Test
public void buildCompact() {
    EnumItem a = new EnumItem(ResourceId.valueOf("a"), "Enumerated Item A");
    EnumItem b = new EnumItem(ResourceId.valueOf("b"), "Enumerated Item B");
    EnumItem c = new EnumItem(ResourceId.valueOf("c"), "Enumerated Item C");
    EnumType enumType = new EnumType(Cardinality.SINGLE, a, b, c);
    CompactingEnumColumnBuilder builder = new CompactingEnumColumnBuilder(new PendingSlot<ColumnView>(), enumType);
    for (int i = 0; i < 13; i++) {
        builder.onNext(new EnumValue(a.getId()));
        builder.onNext(new EnumValue(b.getId()));
        builder.onNext(new EnumValue(c.getId()));
        builder.onNext(null);
    }
    ColumnView column8 = builder.build8();
    ColumnView column32 = builder.build32();
    for (int i = 0; i < column32.numRows(); i++) {
        if (!Objects.equals(column8.getString(i), column32.getString(i))) {
            throw new AssertionError("Vectors not equal at index " + i);
        }
    }
    assertThat(builder.build(), instanceOf(DiscreteStringColumnView8.class));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) ColumnView(org.activityinfo.model.query.ColumnView) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 10 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class EnumGenerator method get.

@Override
public FieldValue get() {
    double missing = random.nextDouble();
    if (missing < probabilityMissing) {
        return null;
    }
    int itemIndex = random.nextInt(enumType.getValues().size());
    EnumItem item = enumType.getValues().get(itemIndex);
    return new EnumValue(item.getId());
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Aggregations

EnumValue (org.activityinfo.model.type.enumerated.EnumValue)28 Test (org.junit.Test)13 ResourceId (org.activityinfo.model.resource.ResourceId)11 FormInstance (org.activityinfo.model.form.FormInstance)6 RecordRef (org.activityinfo.model.type.RecordRef)6 LocalDate (org.activityinfo.model.type.time.LocalDate)6 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)5 FieldValue (org.activityinfo.model.type.FieldValue)4 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)4 FormClass (org.activityinfo.model.form.FormClass)3 Quantity (org.activityinfo.model.type.number.Quantity)3 CheckBox (com.sencha.gxt.widget.core.client.form.CheckBox)2 FormRecord (org.activityinfo.model.form.FormRecord)2 ReferenceValue (org.activityinfo.model.type.ReferenceValue)2 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1