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();
}
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();
}
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)));
}
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);
}
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());
}
Aggregations