use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class FormRecordEntity method setFieldValues.
public void setFieldValues(FormClass formClass, Map<ResourceId, FieldValue> values) {
if (fieldValues == null) {
fieldValues = new EmbeddedEntity();
}
for (FormField field : formClass.getFields()) {
if (values.containsKey(field.getId())) {
FieldValue value = values.get(field.getId());
if (value == null) {
fieldValues.removeProperty(field.getName());
} else {
FieldConverter converter = FieldConverters.forType(field.getType());
fieldValues.setUnindexedProperty(field.getName(), converter.toHrdProperty(value));
}
}
}
}
use of org.activityinfo.model.type.FieldValue 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.type.FieldValue in project activityinfo by bedatadriven.
the class TestingFormQueryBuilder method execute.
@Override
public void execute() {
for (FormInstance record : records) {
for (CursorObserver<ResourceId> idObserver : idObservers) {
idObserver.onNext(record.getId());
}
for (CursorObserver<FieldValue> parentObserver : parentObservers) {
parentObserver.onNext(new ReferenceValue(new RecordRef(formClass.getParentFormId().get(), record.getParentRecordId())));
}
for (Map.Entry<ResourceId, CursorObserver<FieldValue>> field : fieldObservers.entries()) {
ResourceId fieldId = field.getKey();
FieldValue fieldValue = record.get(fieldId);
CursorObserver<FieldValue> observer = field.getValue();
observer.onNext(fieldValue);
}
}
for (CursorObserver<ResourceId> observer : idObservers) {
observer.done();
}
for (CursorObserver<FieldValue> parentObserver : parentObservers) {
parentObserver.done();
}
for (CursorObserver<FieldValue> observer : fieldObservers.values()) {
observer.done();
}
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class TestingStorageProvider method addNew.
public RecordUpdate addNew(ResourceId formId) {
TestingFormStorage form = formMap.get(formId);
if (form == null) {
throw new RuntimeException("No such form: " + formId);
}
FormInstance newRecord = form.getGenerator().get();
RecordUpdate update = new RecordUpdate();
update.setFormId(formId);
update.setRecordId(newRecord.getRef().getRecordId());
for (Map.Entry<ResourceId, FieldValue> entry : newRecord.getFieldValueMap().entrySet()) {
update.setFieldValue(entry.getKey(), entry.getValue());
}
return update;
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class UnaryFunctionBase method apply.
@Override
public FieldValue apply(List<FieldValue> arguments) {
checkArity(arguments, MAXARGS);
FieldValue unaryArg = arguments.get(0);
return apply(unaryArg);
}
Aggregations