use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SitePersisterTest method test.
@Test
public void test() {
FormClass formClass = assertResolves(locator.getFormClass(PEAR_Activity));
FormInstance siteFormInstance = new FormInstance(CuidAdapter.generateSiteCuid(), formClass.getId());
siteFormInstance.set(CONTENU_DI_KIT_FIELD, new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
// built-in values
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.partnerFormId(DATABASE_ID), CuidAdapter.partnerRecordId(1))));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.locationFormClass(1), CuidAdapter.locationInstanceId(1))));
assertResolves(locator.persist(siteFormInstance));
// query by id
FormInstance fromServer = assertResolves(locator.getFormInstance(siteFormInstance.getFormId(), siteFormInstance.getId()));
Assert.assertNotNull(fromServer);
Assert.assertEquals(fromServer.get(CONTENU_DI_KIT_FIELD), new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
FormTree formTree = assertResolves(locator.getFormTree(formClass.getId()));
final List<FieldPath> paths = Lists.newArrayList(formTree.getRootPaths());
Assert.assertTrue(paths.contains(new FieldPath(CONTENU_DI_KIT_FIELD)));
// query projection
FormInstance instance = assertResolves(locator.getFormInstance(formClass.getId(), siteFormInstance.getId()));
EnumValue fieldValue = (EnumValue) instance.get(CONTENU_DI_KIT_FIELD);
assertThat(fieldValue.getValueId(), equalTo(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class ActivityFormClassBuilderTest method partnersFieldIsAlwaysVisible.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void partnersFieldIsAlwaysVisible() {
setUser(BAVON_USER_ID);
FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1)));
int databaseId = 1;
ResourceId partnerFieldId = CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD);
FormField partnerField = formClass.getField(partnerFieldId);
// according to ai-1009 : partner field is always visible
assertThat(partnerField, hasProperty("visible", equalTo(true)));
// Make sure we can update if partner is not specified
FormInstance instance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClass.getId()), formClass.getId());
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.locationFormClass(1), CuidAdapter.locationInstanceId(1))));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
assertResolves(locator.persist(instance));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class UpdaterTest method invalidQuantity.
@Test(expected = InvalidUpdateException.class)
public void invalidQuantity() 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", "Hello World");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
Updater.parseChange(formClass, change, userId);
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class UpdaterTest method serialNumber.
@Test
public void serialNumber() throws JsonMappingException {
FormClass formClass = new FormClass(ResourceId.valueOf("FORM1"));
formClass.addField(ResourceId.valueOf("FIELD0")).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField serialNumberField = formClass.addField(ResourceId.valueOf("FIELD1")).setType(new SerialNumberType("PROVINCE", 5)).setRequired(true).setLabel("File Number").setCode("SN");
JsonValue fields = Json.createObject();
fields.put("PROVINCE", "KUNDUZ");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "FORM1");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
FormInstance effectiveRecord = updater.computeEffectiveRecord(formClass, Optional.<FormRecord>absent(), update);
updater.generateSerialNumber(formClass, serialNumberField, effectiveRecord, update);
FieldValue serialValue = update.getChangedFieldValues().get(serialNumberField.getId());
assertThat(serialValue, equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class UpdaterTest method validQuantity.
@Test
public void validQuantity() 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", 41.3);
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
Aggregations