Search in sources :

Example 91 with FormClass

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

the class UpdaterTest method parsedQuantity.

@Test
public void parsedQuantity() throws JsonMappingException {
    ResourceId fieldId = ResourceId.valueOf("Q1");
    FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
    formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
    JsonValue fields = Json.createObject();
    fields.put("Q1", "41.3");
    JsonValue change = createObject();
    change.put("recordId", "A");
    change.put("formId", "XYZ123");
    change.put("fields", fields);
    TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
    assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 92 with FormClass

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

the class UpdaterTest method invalidParsedQuantity.

@Test(expected = InvalidUpdateException.class)
public void invalidParsedQuantity() throws JsonMappingException {
    ResourceId fieldId = ResourceId.valueOf("Q1");
    FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
    formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
    JsonValue fields = createObject();
    fields.put("Q1", "4.1.3");
    JsonValue change = createObject();
    change.put("recordId", "A");
    change.put("formId", "XYZ123");
    change.put("fields", fields);
    Updater.parseChange(formClass, change, userId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 93 with FormClass

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

the class NodeMatcherTest method formClass.

private FormClass formClass(String id, FormField... fields) {
    FormClass formClass = new FormClass(ResourceId.valueOf(id));
    formClass.setLabel(id);
    for (FormField field : fields) {
        formClass.addElement(field);
    }
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 94 with FormClass

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

the class NodeMatcherTest method givenRootForm.

private void givenRootForm(String label, FormField... fields) {
    if (rootFormClass != null) {
        throw new IllegalStateException("Root Form Class already set");
    }
    rootFormClass = new FormClass(ResourceId.valueOf(label));
    rootFormClass.setLabel(label);
    rootFormClass.getElements().addAll(Arrays.asList(fields));
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Example 95 with FormClass

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

the class QueryEvaluatorTest method circularReference.

@Test
public void circularReference() throws Exception {
    final FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
    formClass.addField(ResourceId.valueOf("FA")).setCode("A").setLabel("Field A").setType(new CalculatedFieldType("B"));
    formClass.addField(ResourceId.valueOf("FB")).setCode("B").setLabel("Field B").setType(new CalculatedFieldType("A"));
    FormStorageProviderStub catalog = new FormStorageProviderStub();
    catalog.addForm(formClass).withRowCount(10);
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    FormScanBatch batch = builder.createNewBatch();
    QueryEvaluator evaluator = new QueryEvaluator(FilterLevel.BASE, catalog.getTree(formClass.getId()), batch);
    Slot<ColumnView> a = evaluator.evaluateExpression(new SymbolNode("A"));
    Slot<ColumnView> aPlusOne = evaluator.evaluateExpression(FormulaParser.parse("A+1"));
    builder.execute(batch);
    assertThat(a.get().numRows(), equalTo(10));
    assertThat(a.get().getString(0), nullValue());
    assertThat(aPlusOne.get().getString(0), nullValue());
    assertThat(aPlusOne.get().getDouble(0), equalTo(1d));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) SymbolNode(org.activityinfo.model.formula.SymbolNode) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FormClass(org.activityinfo.model.form.FormClass) ColumnView(org.activityinfo.model.query.ColumnView) Test(org.junit.Test)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5