Search in sources :

Example 11 with FormClass

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

the class SchemaImporterV3 method getFormClass.

private FormClass getFormClass(SourceRow row) {
    String name = formName.get(row);
    FormClass formClass = formMap.get(name);
    if (formClass == null) {
        formClass = new FormClass(CuidAdapter.activityFormClass(keyGenerator.generateInt()));
        formClass.setDatabaseId(databaseId);
        formClass.setLabel(name);
        formMap.put(name, formClass);
    }
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Example 12 with FormClass

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

the class SchemaImporterV3 method persist.

@Override
public void persist(final AsyncCallback<Void> callback) {
    List<PromiseExecutionOperation> operations = new ArrayList<>();
    for (final FormClass formClass : toSave()) {
        operations.add(new PromiseExecutionOperation() {

            @Nullable
            @Override
            public Promise<Void> apply(@Nullable Void aVoid) {
                return locator.persist(formClass);
            }
        });
    }
    PromisesExecutionGuard.newInstance().executeSerially(operations).then(callback);
}
Also used : PromiseExecutionOperation(org.activityinfo.promise.PromiseExecutionOperation) Promise(org.activityinfo.promise.Promise) FormClass(org.activityinfo.model.form.FormClass) Nullable(javax.annotation.Nullable)

Example 13 with FormClass

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

the class SchemaImporterV3 method processRows.

@Override
public boolean processRows() {
    formMap.clear();
    subFormMap.clear();
    enumMap.clear();
    refMap.clear();
    fatalError = false;
    for (SourceRow row : source.getRows()) {
        try {
            FormClass parentFormClass = getFormClass(row);
            FormClass formClass = getSubFormClass(parentFormClass, row);
            String type = formFieldType.get(row);
            if (isEnum(type)) {
                addChoice(formClass, row);
            } else {
                FieldType fieldType = parseFieldType(row);
                FormField newField = addField(formClass, fieldType.getTypeClass(), row);
                newField.setType(fieldType);
                if (newField.getType() instanceof ReferenceType) {
                    refMap.put(formClass, newField);
                }
            }
        } catch (UnableToParseRowException e) {
            warnings.add(SafeHtmlUtils.fromString(e.getMessage()));
            fatalError = true;
        }
    }
    for (EnumBuilder enumBuilder : enumMap.values()) {
        enumBuilder.formField.setType(new EnumType(enumBuilder.cardinality, enumBuilder.items));
    }
    if (validationCallback != null) {
        validateReferences();
    }
    return !fatalError;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType)

Example 14 with FormClass

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

the class SchemaImporterV3 method getSubFormClass.

private FormClass getSubFormClass(FormClass masterForm, SourceRow row) {
    String subFormName = subForm.get(row);
    if (subFormName == null) {
        return masterForm;
    }
    FormClass subFormClass = subFormMap.get(subFormName);
    if (subFormClass == null) {
        subFormClass = new FormClass(ResourceId.generateId());
        subFormClass.setSubFormKind(parseSubFormKind(subFormType.get(row)));
        subFormClass.setParentFormId(masterForm.getId());
        subFormClass.setLabel(subFormName);
        subFormClass.setDatabaseId(databaseId);
        subFormMap.put(subFormName, subFormClass);
        FormField subFormField = new FormField(ResourceId.generateFieldId(SubFormReferenceType.TYPE_CLASS));
        subFormField.setLabel(subFormName);
        subFormField.setType(new SubFormReferenceType(subFormClass.getId()));
        subFormField.setVisible(true);
        masterForm.addElement(subFormField);
    }
    return subFormClass;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 15 with FormClass

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

the class FormulaValidator method findCalculatedFieldType.

private FieldType findCalculatedFieldType(FormTree.Node fieldNode) {
    CalculatedFieldType fieldType = (CalculatedFieldType) fieldNode.getType();
    FormulaNode rootNode;
    try {
        rootNode = FormulaParser.parse(fieldType.getExpression());
    } catch (FormulaException e) {
        throw new ValidationFailed();
    }
    FormClass formClass = fieldNode.getDefiningFormClass();
    FormTree subTree = formTree.subTree(formClass.getId());
    FormulaValidator validator = new FormulaValidator(subTree);
    if (!validator.validate(rootNode)) {
        throw new ValidationFailed();
    }
    return validator.getResultType();
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) FormulaException(org.activityinfo.model.formula.diagnostic.FormulaException)

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