Search in sources :

Example 66 with FormField

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

the class AdminEntityTable method getMapping.

@Override
public TableMapping getMapping(QueryExecutor executor, ResourceId formId) throws SQLException {
    int levelId = CuidAdapter.getLegacyIdFromCuid(formId);
    AdminLevel level = LEVEL_CACHE.getIfPresent(levelId);
    if (level == null) {
        level = AdminLevel.fetch(executor, levelId);
        LEVEL_CACHE.put(levelId, level);
    }
    FormField label = new FormField(CuidAdapter.field(formId, CuidAdapter.NAME_FIELD));
    label.setLabel(I18N.CONSTANTS.name());
    label.setCode("name");
    label.setKey(true);
    label.setRequired(true);
    label.addSuperProperty(ResourceId.valueOf("label"));
    label.setType(TextType.SIMPLE);
    FormField code = new FormField(CuidAdapter.field(formId, CuidAdapter.CODE_FIELD));
    code.setCode("code");
    code.setLabel(I18N.CONSTANTS.codeFieldLabel());
    code.setRequired(false);
    code.setType(TextType.SIMPLE);
    FormField bounds = new FormField(CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD));
    bounds.setCode("boundary");
    bounds.setLabel(I18N.CONSTANTS.geography());
    bounds.setType(GeoAreaType.INSTANCE);
    FormField parent = null;
    if (level.hasParent()) {
        parent = new FormField(CuidAdapter.field(formId, CuidAdapter.ADMIN_PARENT_FIELD));
        parent.setCode("parent");
        parent.setLabel(level.getParentName());
        parent.setRequired(true);
        parent.setKey(true);
        parent.setType(ReferenceType.single(CuidAdapter.adminLevelFormClass(level.getParentId())));
        parent.addSuperProperty(ApplicationProperties.PARENT_PROPERTY);
    }
    // TODO: geometry
    TableMappingBuilder mapping = TableMappingBuilder.newMapping(formId, ADMIN_ENTITY_TABLE);
    mapping.setDatabaseId(GeodbFolder.GEODB_ID);
    mapping.setPrimaryKeyMapping(CuidAdapter.ADMIN_ENTITY_DOMAIN, "adminEntityId");
    mapping.setBaseFilter("base.AdminLevelId=" + levelId + " AND base.deleted=0");
    mapping.defaultValueOnInsert("AdminLevelId", levelId);
    mapping.setFormLabel(level.getName());
    mapping.addTextField(label, "name");
    mapping.addTextField(code, "code");
    mapping.addGeoAreaField(bounds);
    mapping.setDeleteMethod(DeleteMethod.SOFT_BY_BOOLEAN);
    mapping.setVersion(level.getVersion());
    if (parent != null) {
        mapping.add(new FieldMapping(parent, "adminEntityParentId", new ReferenceConverter(CuidAdapter.adminLevelFormClass(level.getParentId()), ADMIN_ENTITY_DOMAIN)));
    }
    return mapping.build();
}
Also used : AdminLevel(org.activityinfo.store.mysql.metadata.AdminLevel) FormField(org.activityinfo.model.form.FormField)

Example 67 with FormField

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

the class CountryTable method getMapping.

@Override
public TableMapping getMapping(QueryExecutor executor, ResourceId formId) throws SQLException {
    FormField nameField = new FormField(NAME_FIELD_ID);
    nameField.setCode("label");
    nameField.setLabel(I18N.CONSTANTS.name());
    nameField.setType(TextType.SIMPLE);
    FormField isoField = new FormField(CODE_FIELD_ID);
    isoField.setCode("code");
    isoField.setLabel(I18N.CONSTANTS.codeFieldLabel());
    isoField.setType(TextType.SIMPLE);
    FormField boundaryField = new FormField(BOUNDARY_FIELD_ID);
    boundaryField.setCode("boundary");
    boundaryField.setLabel(I18N.CONSTANTS.boundaries());
    boundaryField.setType(GeoAreaType.INSTANCE);
    // TODO: polygons
    TableMappingBuilder mapping = TableMappingBuilder.newMapping(FORM_CLASS_ID, TABLE_NAME);
    mapping.setFormLabel("Country");
    mapping.setPrimaryKeyMapping(CuidAdapter.COUNTRY_DOMAIN, "countryId");
    mapping.setDatabaseId(GeodbFolder.GEODB_ID);
    mapping.addTextField(nameField, "name");
    mapping.addTextField(isoField, "iso2");
    mapping.addGeoAreaField(boundaryField);
    return mapping.build();
}
Also used : TableMappingBuilder(org.activityinfo.store.mysql.mapping.TableMappingBuilder) FormField(org.activityinfo.model.form.FormField)

Example 68 with FormField

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

the class SerialNumberTest method simpleTest.

@Test
public void simpleTest() {
    TestDatabase database = harness.createDatabase();
    ActivityInfoClient client = harness.client();
    FormClass formClass = new FormClass(harness.newFormId());
    formClass.setLabel("Test Form");
    formClass.setDatabaseId(database.getId());
    FormField partnerField = CuidAdapter.partnerField(formClass);
    formClass.addElement(partnerField);
    FormField fileNumberField = formClass.addField(harness.newFieldId()).setType(new SerialNumberType()).setLabel("Record Number");
    FormField nameField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Name");
    client.createForm(formClass);
    FormInstance record1 = new FormInstance(harness.newRecordId(), formClass.getId());
    record1.set(nameField.getId(), "Sue");
    record1.set(partnerField.getId(), database.getDefaultPartner());
    FormInstance record2 = new FormInstance(harness.newRecordId(), formClass.getId());
    record2.set(nameField.getId(), "Bob");
    record2.set(partnerField.getId(), database.getDefaultPartner());
    client.createRecord(record1);
    client.createRecord(record2);
    record1 = client.getTypedRecord(formClass, record1.getId());
    record2 = client.getTypedRecord(formClass, record2.getId());
    assertThat(record1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber(1)));
    assertThat(record2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber(2)));
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) ActivityInfoClient(org.activityinfo.client.ActivityInfoClient) FormClass(org.activityinfo.model.form.FormClass) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) SerialNumberType(org.activityinfo.model.type.SerialNumberType) Test(org.junit.Test)

Example 69 with FormField

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

the class SiteIds method builtinFields.

@Override
public List<FormField> builtinFields() {
    FormField partnerField = new FormField(CuidAdapter.partnerField(activityId));
    partnerField.setRequired(true);
    partnerField.setLabel("Partner");
    partnerField.setType(new ReferenceType(Cardinality.SINGLE, CuidAdapter.partnerFormId(database.getId())));
    return Collections.singletonList(partnerField);
}
Also used : FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 70 with FormField

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

the class RelevanceRow method init.

private void init(SimpleCondition simpleCondition) {
    int fieldIndex = indexOfField(simpleCondition.getFieldId());
    fieldListBox.setSelectedIndex(fieldIndex);
    FormField field = fields.get(fieldIndex);
    updateOperators(field, simpleCondition.getOperator());
    updateOperandChoices(field, simpleCondition.getValue());
}
Also used : 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