Search in sources :

Example 26 with FormInstance

use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.

the class RepeatingSubFormPanel method render.

private void render() {
    List<FormInstance> instances = Lists.newArrayList(getInstances());
    Collections.sort(instances, new Comparator<FormInstance>() {

        @Override
        public int compare(FormInstance o1, FormInstance o2) {
            return getCreationTime(o1).compareTo(getCreationTime(o2));
        }
    });
    for (FormInstance instance : instances) {
        addForm(instance);
    }
    panel.add(addButton);
}
Also used : FormInstance(org.activityinfo.model.form.FormInstance)

Example 27 with FormInstance

use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.

the class RelevanceExpressionTest method text.

@Test
public void text() {
    FormInstance instance = new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId());
    instance.set(TEXT_FIELD_ID, "1");
    eval(String.format("{%s}==\"1\"", TEXT_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}!=\"1\"", TEXT_FIELD_ID.asString()), false, instance);
}
Also used : FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 28 with FormInstance

use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.

the class RelevanceExpressionTest 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);
    instance.set(GENDER_FIELD_ID, new EnumValue());
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), 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 29 with FormInstance

use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.

the class SkipExpressionTest method quantity.

@Test
public void quantity() {
    FormInstance instance = new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId());
    instance.set(QUANTITY_FIELD_ID, 3);
    eval(String.format("{%s}==3", QUANTITY_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}==3.0", QUANTITY_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}!=3", QUANTITY_FIELD_ID.asString()), false, instance);
}
Also used : FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 30 with FormInstance

use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.

the class SkipExpressionTest method text.

@Test
public void text() {
    FormInstance instance = new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId());
    instance.set(TEXT_FIELD_ID, "1");
    eval(String.format("{%s}==\"1\"", TEXT_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}!=\"1\"", TEXT_FIELD_ID.asString()), false, instance);
}
Also used : FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Aggregations

FormInstance (org.activityinfo.model.form.FormInstance)46 Test (org.junit.Test)26 ResourceId (org.activityinfo.model.resource.ResourceId)15 FormClass (org.activityinfo.model.form.FormClass)14 FieldValue (org.activityinfo.model.type.FieldValue)10 FormField (org.activityinfo.model.form.FormField)9 RecordRef (org.activityinfo.model.type.RecordRef)8 ReferenceValue (org.activityinfo.model.type.ReferenceValue)7 LocalDate (org.activityinfo.model.type.time.LocalDate)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 SerialNumberType (org.activityinfo.model.type.SerialNumberType)5 FormRecord (org.activityinfo.model.form.FormRecord)4 SerialNumber (org.activityinfo.model.type.SerialNumber)4 Map (java.util.Map)3 FormTree (org.activityinfo.model.formTree.FormTree)3 Maybe (org.activityinfo.promise.Maybe)3 ArrayList (java.util.ArrayList)2