Search in sources :

Example 6 with FormInstance

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

the class ActivityInfoClient method getTypedRecord.

public FormInstance getTypedRecord(FormClass formClass, ResourceId recordId) {
    FormRecord record = getRecord(formClass.getId(), recordId);
    FormInstance instance = FormInstance.toFormInstance(formClass, record);
    return instance;
}
Also used : FormRecord(org.activityinfo.model.form.FormRecord) FormInstance(org.activityinfo.model.form.FormInstance)

Example 7 with FormInstance

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

the class RecordTree method buildSubTrees.

public List<RecordTree> buildSubTrees(RecordRef parentRef, FormTree subTree) {
    List<RecordTree> recordTrees = new ArrayList<>();
    Iterable<FormInstance> subRecords = getSubRecords(parentRef, subTree.getRootFormId());
    for (FormInstance subRecord : subRecords) {
        recordTrees.add(new RecordTree(subTree, subRecord.getRef(), this.relatedRecords, this.subRecords));
    }
    return recordTrees;
}
Also used : ArrayList(java.util.ArrayList) FormInstance(org.activityinfo.model.form.FormInstance)

Example 8 with FormInstance

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

the class RelevanceExpressionTest 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);
    eval(String.format("{%s}>2", QUANTITY_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}>3", QUANTITY_FIELD_ID.asString()), false, instance);
    eval(String.format("{%s}>=3", QUANTITY_FIELD_ID.asString()), true, instance);
    eval(String.format("{%s}<3", QUANTITY_FIELD_ID.asString()), false, instance);
    eval(String.format("{%s}<=3", QUANTITY_FIELD_ID.asString()), true, instance);
}
Also used : FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 9 with FormInstance

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

the class FormEvalContextTest method circularRefs.

@Test
public void circularRefs() {
    FormField a = new FormField(ResourceId.generateId());
    a.setCode("A");
    a.setType(new CalculatedFieldType("B+1"));
    a.setLabel("A");
    FormField b = new FormField(ResourceId.generateId());
    b.setCode("B");
    b.setType(new CalculatedFieldType("A/50"));
    b.setLabel("B");
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.addElement(a);
    formClass.addElement(b);
    FormEvalContext context = new FormEvalContext(formClass);
    context.setInstance(new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId()));
    assertThat(context.getFieldValue(a.getId()), instanceOf(ErrorValue.class));
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FormClass(org.activityinfo.model.form.FormClass) ErrorValue(org.activityinfo.model.type.ErrorValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) FormEvalContext(org.activityinfo.model.form.FormEvalContext) Test(org.junit.Test)

Example 10 with FormInstance

use of org.activityinfo.model.form.FormInstance 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)

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