Search in sources :

Example 11 with FormField

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

the class SchemaImporterV3 method determineReferencesToValidate.

private List<ResourceId> determineReferencesToValidate() {
    List<ResourceId> validationList = new ArrayList<>(refMap.size());
    for (FormField refField : refMap.values()) {
        ReferenceType refType = (ReferenceType) refField.getType();
        ResourceId reference = refType.getRange().iterator().next();
        if (!isImportedReference(reference)) {
            validationList.add(reference);
        }
    }
    return validationList;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType)

Example 12 with FormField

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

the class SchemaImporterV3 method addField.

private FormField addField(FormClass formClass, FieldTypeClass typeClass, SourceRow row) {
    FormField field = new FormField(ResourceId.generateFieldId(typeClass));
    field.setLabel(fieldName.getOrThrow(row));
    field.setCode(fieldCode.get(row));
    field.setDescription(fieldDescription.get(row));
    field.setRequired(isTruthy(fieldRequired.get(row)));
    field.setVisible(true);
    formClass.addElement(field);
    return field;
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 13 with FormField

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

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

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

the class FormMappingBuilder method build.

public Observable<List<FieldMapping>> build() {
    // the source to the target field
    for (FieldProfile targetField : target.getFields()) {
        if (targetField.getNode().isRoot())
            if (SimpleFieldMapping.isSimple(targetField)) {
                buildSimpleMapping(targetField);
            }
    }
    // Add mappings for ReferenceFields, for which we have to perform look ups
    for (FormTree.Node targetNode : target.getFormTree().getRootFields()) {
        if (targetNode.isReference()) {
            buildReferenceMapping(targetNode.getField());
        }
    }
    // Add mapping for geography, IIF source and target have exactly one GeoArea
    Set<FormField> targetGeoFields = findGeoFields(target.getFormTree());
    Set<FormField> sourceGeoFields = findGeoFields(source.getFormTree());
    if (targetGeoFields.size() == 1 && sourceGeoFields.size() == 1) {
        FormField sourceField = Iterables.getOnlyElement(sourceGeoFields);
        FormField targetField = Iterables.getOnlyElement(targetGeoFields);
        mappings.add(Observable.<FieldMapping>just(new GeoAreaFieldMapping(source.getField(sourceField.getId()), targetField)));
    }
    return Observable.flatten(SynchronousScheduler.INSTANCE, mappings);
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) 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