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;
}
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;
}
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);
}
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));
}
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);
}
Aggregations