Search in sources :

Example 36 with FormField

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

the class FormFolder method getChildren.

public List<CatalogEntry> getChildren(ResourceId formId) {
    Optional<FormStorage> storage = catalog.getForm(formId);
    if (!storage.isPresent()) {
        return Collections.emptyList();
    }
    List<CatalogEntry> entries = new ArrayList<>();
    FormClass formClass = storage.get().getFormClass();
    for (FormField formField : formClass.getFields()) {
        if (formField.getType() instanceof SubFormReferenceType) {
            SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
            ResourceId subFormId = subFormType.getClassId();
            CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
            catalogEntry.setLeaf(true);
            entries.add(catalogEntry);
        }
    }
    return entries;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Example 37 with FormField

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

the class FormRecordEntity method toFieldValueMap.

public Map<ResourceId, FieldValue> toFieldValueMap(FormClass formClass) {
    Map<ResourceId, FieldValue> map = new HashMap<>();
    for (FormField formField : formClass.getFields()) {
        Object value = fieldValues.getProperty(formField.getName());
        if (value != null) {
            FieldConverter<?> converter = FieldConverters.forType(formField.getType());
            map.put(formField.getId(), converter.toFieldValue(value));
        }
    }
    return map;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 38 with FormField

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

the class FormRecordEntity method toFormRecord.

public FormRecord toFormRecord(FormClass formClass) {
    FormRecord.Builder record = FormRecord.builder();
    record.setFormId(formClass.getId());
    record.setRecordId(getRecordId());
    if (formClass.getParentField().isPresent()) {
        record.setParentRecordId(ResourceId.valueOf(getParentRecordId()));
    }
    for (FormField formField : formClass.getFields()) {
        Object value = fieldValues.getProperty(formField.getName());
        if (value != null) {
            FieldConverter<?> converter = FieldConverters.forType(formField.getType());
            record.setFieldValue(formField.getId(), converter.toFieldValue(value));
        }
    }
    return record.build();
}
Also used : FormRecord(org.activityinfo.model.form.FormRecord) FormField(org.activityinfo.model.form.FormField)

Example 39 with FormField

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

the class ExprQueryBuilder method computeFormClass.

private FormSymbolTable computeFormClass(FormSymbolTable parent, FormulaNode formulaNode) {
    if (formulaNode instanceof SymbolNode) {
        FormField field = parent.resolveSymbol((SymbolNode) formulaNode);
        if (field.getType() instanceof RecordFieldType) {
            RecordFieldType recordFieldType = (RecordFieldType) field.getType();
            FormClass recordFormClass = recordFieldType.getFormClass();
            return new FormSymbolTable(recordFormClass);
        } else {
            throw new IllegalStateException(field.getName() + " is not a record type field.");
        }
    } else if (formulaNode instanceof CompoundExpr) {
        CompoundExpr compoundExpr = (CompoundExpr) formulaNode;
        FormSymbolTable child = computeFormClass(parent, compoundExpr.getValue());
        return computeFormClass(child, compoundExpr.getValue());
    } else {
        throw new UnsupportedOperationException("exprNode: " + formulaNode);
    }
}
Also used : FormClass(org.activityinfo.model.form.FormClass) FormSymbolTable(org.activityinfo.model.formula.eval.FormSymbolTable) FormField(org.activityinfo.model.form.FormField)

Example 40 with FormField

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

the class ExprQueryBuilder method addExpr.

private void addExpr(FormulaNode expr, CursorObserver<FieldValue> target) {
    if (expr instanceof SymbolNode) {
        SymbolNode symbol = (SymbolNode) expr;
        FormField field = symbolTable.resolveSymbol(symbol);
        queryBuilder.addField(field.getId(), target);
    } else if (expr instanceof FunctionCallNode) {
        FunctionCallNode call = (FunctionCallNode) expr;
        if (call.getArguments().isEmpty()) {
        } else {
            List<CursorObserver<FieldValue>> argumentObservers = CursorObservers.collect(target, call.getArguments().size(), call.getFunction());
            for (int i = 0; i < call.getArgumentCount(); i++) {
                addExpr(call.getArgument(i), argumentObservers.get(i));
            }
        }
    } else if (expr instanceof CompoundExpr) {
        CompoundExpr compoundExpr = (CompoundExpr) expr;
        Function<FieldValue, FieldValue> reader;
        if (isEnumItemReference(compoundExpr)) {
            reader = new EnumItemReader(compoundExpr.getField().asResourceId());
        } else {
            reader = new ComponentReader(compoundExpr.getField().getName());
        }
        CursorObserver<FieldValue> valueObserver = CursorObservers.transform(reader, target);
        addExpr(compoundExpr.getValue(), valueObserver);
    } else if (expr instanceof ConstantNode) {
        ConstantNode constantNode = (ConstantNode) expr;
        Function<Object, FieldValue> constantFunction = Functions.constant(constantNode.getValue());
        CursorObserver<ResourceId> rowObserver = CursorObservers.transform(constantFunction, target);
        queryBuilder.addResourceId(rowObserver);
    } else if (expr instanceof GroupNode) {
        addExpr(((GroupNode) expr).getExpr(), target);
    } else {
        throw new UnsupportedOperationException("TODO: " + expr);
    }
}
Also used : Function(com.google.common.base.Function) CursorObserver(org.activityinfo.store.spi.CursorObserver) List(java.util.List) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue) FormField(org.activityinfo.model.form.FormField)

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