Search in sources :

Example 86 with FormField

use of org.activityinfo.model.form.FormField 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 87 with FormField

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

the class NodeMatch method joinsTo.

private static List<JoinNode> joinsTo(List<List<FormTree.Node>> partitions, Optional<StatFunction> aggregation) {
    /*
         *  Given a parent: "Site.Location.Territoire.District"
         *  This is represented as a tree of nodes:
         *      District -> Territoire -> Location -> Site
         *      
         *  We want to turn into a list of joins: 
         *      (site field -> form site), 
         *      (location field -> form school),
         *      (field territoire -> form Territoire)
         *      (field district -> form District)
         */
    LinkedList<JoinNode> joins = new LinkedList<>();
    for (int i = 0; i < partitions.size() - 1; i++) {
        // Reference field that functions as a foreign key
        List<FormTree.Node> left = partitions.get(i);
        FormField leftField = left.get(0).getField();
        ResourceId leftFormId = left.get(0).getDefiningFormClass().getId();
        FormulaNode leftFieldExpr = toExpr(left);
        // "RIGHT" side
        // Joining fom left to right using resource ids (primary key)
        List<FormTree.Node> right = partitions.get(i + 1);
        ResourceId rightFormId = right.get(0).getDefiningFormClass().getId();
        if (leftField.getType() instanceof ReferenceType) {
            // Join based on the (left) foreign key ==> (right) primary key
            joins.add(new JoinNode(JoinType.REFERENCE, leftFormId, leftFieldExpr, rightFormId, Optional.<StatFunction>absent()));
        } else if (leftField.getType() instanceof SubFormReferenceType) {
            joins.add(new JoinNode(JoinType.SUBFORM, leftFormId, new SymbolNode(ColumnModel.ID_SYMBOL), rightFormId, aggregation));
        } else {
            throw new IllegalStateException("Invalid field for joining: " + leftField.getType());
        }
    }
    return joins;
}
Also used : JoinNode(org.activityinfo.store.query.shared.join.JoinNode) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) JoinNode(org.activityinfo.store.query.shared.join.JoinNode) LinkedList(java.util.LinkedList) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ResourceId(org.activityinfo.model.resource.ResourceId) StatFunction(org.activityinfo.model.formula.functions.StatFunction) FormField(org.activityinfo.model.form.FormField)

Example 88 with FormField

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

the class NodeMatcherTest method pointField.

private FormField pointField(String id, String label) {
    FormField field = new FormField(ResourceId.valueOf(id));
    field.setLabel(label);
    field.setType(GeoPointType.INSTANCE);
    return field;
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 89 with FormField

use of org.activityinfo.model.form.FormField 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 90 with FormField

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

the class NodeMatcherTest method referenceField.

private FormField referenceField(String id, String label, String... formClasses) {
    List<ResourceId> range = new ArrayList<>();
    for (String formClass : formClasses) {
        range.add(ResourceId.valueOf(formClass));
    }
    ReferenceType type = new ReferenceType();
    type.setCardinality(Cardinality.SINGLE);
    type.setRange(range);
    FormField field = new FormField(ResourceId.valueOf(id));
    field.setLabel(label);
    field.setType(type);
    return field;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Aggregations

FormField (org.activityinfo.model.form.FormField)119 FormClass (org.activityinfo.model.form.FormClass)48 ResourceId (org.activityinfo.model.resource.ResourceId)32 Test (org.junit.Test)30 QuantityType (org.activityinfo.model.type.number.QuantityType)18 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)17 ReferenceType (org.activityinfo.model.type.ReferenceType)16 EnumType (org.activityinfo.model.type.enumerated.EnumType)14 FieldValue (org.activityinfo.model.type.FieldValue)12 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)11 JsonValue (org.activityinfo.json.JsonValue)9 FormTree (org.activityinfo.model.formTree.FormTree)9 FormInstance (org.activityinfo.model.form.FormInstance)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 ColumnSet (org.activityinfo.model.query.ColumnSet)6 QueryModel (org.activityinfo.model.query.QueryModel)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 Quantity (org.activityinfo.model.type.number.Quantity)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 ArrayList (java.util.ArrayList)4