use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class UpdaterTest method missingValue.
@Test
public void missingValue() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", Json.createNull());
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertTrue(update.getChangedFieldValues().containsKey(fieldId));
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class NodeMatcherTest method field.
private FormField field(String id, String label) {
FormField field = new FormField(ResourceId.valueOf(id));
field.setLabel(label);
field.setType(TextType.SIMPLE);
return field;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class NodeMatcherTest method multiEnum.
private FormField multiEnum(String id, String label, String... values) {
List<EnumItem> enumValues = Lists.newArrayList();
for (String value : values) {
enumValues.add(new EnumItem(ResourceId.valueOf(value), value));
}
EnumType type = new EnumType(Cardinality.MULTIPLE, enumValues);
FormField field = new FormField(ResourceId.valueOf(id));
field.setLabel(label);
field.setType(type);
return field;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class BatchingFormTreeBuilder method queryTrees.
public Map<ResourceId, FormTree> queryTrees(Collection<ResourceId> rootFormIds) {
// Fetch Required FormClasses in batches
Set<ResourceId> toFetch = Sets.newHashSet();
toFetch.addAll(rootFormIds);
while (!toFetch.isEmpty()) {
// First round: fetch root form classes
List<FormClass> fetched = fetchFormClasses(toFetch);
toFetch.clear();
// Find newly referenced forms
for (FormClass formClass : fetched) {
if (formClass.isSubForm()) {
if (!formCache.containsKey(formClass.getParentFormId().get())) {
toFetch.add(formClass.getParentFormId().get());
}
}
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof ReferenceType) {
ReferenceType refType = (ReferenceType) formField.getType();
for (ResourceId refFormId : refType.getRange()) {
if (!formCache.containsKey(refFormId)) {
toFetch.add(refFormId);
}
}
} else if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
if (!formCache.containsKey(subFormType.getClassId())) {
toFetch.add(subFormType.getClassId());
}
}
}
}
}
// Now assemble trees
Map<ResourceId, FormTree> treeMap = new HashMap<>();
FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
return formCache.get(formId);
}
});
for (ResourceId rootFormId : rootFormIds) {
treeMap.put(rootFormId, builder.queryTree(rootFormId));
}
return treeMap;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class SerialNumberTest method testWithPrefix.
@Test
public void testWithPrefix() {
TestDatabase database = harness.createDatabase();
ActivityInfoClient client = harness.client();
FormClass formClass = new FormClass(harness.newFormId());
formClass.setLabel("Test Prefix");
formClass.setDatabaseId(database.getId());
FormField partnerField = CuidAdapter.partnerField(formClass);
formClass.addElement(partnerField);
FormField provinceField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField fileNumberField = formClass.addField(harness.newFieldId()).setCode("SN").setType(new SerialNumberType("PROVINCE", 5)).setLabel("Record Number");
client.createForm(formClass);
FormInstance kunduz1 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz1.set(provinceField.getId(), "KUNDUZ");
kunduz1.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz1);
FormInstance kunduz2 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz2.set(provinceField.getId(), "KUNDUZ");
kunduz2.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz2);
FormInstance takhar = new FormInstance(harness.newRecordId(), formClass.getId());
takhar.set(provinceField.getId(), "TAKHAR");
takhar.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(takhar);
// Verify that the serial numbers have been assigned
kunduz1 = client.getTypedRecord(formClass, kunduz1.getId());
kunduz2 = client.getTypedRecord(formClass, kunduz2.getId());
takhar = client.getTypedRecord(formClass, takhar.getId());
assertThat(kunduz1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
assertThat(kunduz2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 2)));
assertThat(takhar.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("TAKHAR", 1)));
// Now verify that we can query a table with serial numbers
QueryModel queryModel = new QueryModel(formClass.getId());
queryModel.selectResourceId().as("id");
queryModel.selectField("SN");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView sn = columnSet.getColumnView("SN");
}
Aggregations