Search in sources :

Example 26 with FieldValue

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));
            }
        }
    }
}
Also used : FieldConverter(org.activityinfo.store.hrd.FieldConverter) FieldValue(org.activityinfo.model.type.FieldValue) EmbeddedEntity(com.google.appengine.api.datastore.EmbeddedEntity) FormField(org.activityinfo.model.form.FormField)

Example 27 with FieldValue

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)));
}
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 28 with FieldValue

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();
    }
}
Also used : CursorObserver(org.activityinfo.store.spi.CursorObserver) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) Map(java.util.Map)

Example 29 with FieldValue

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;
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) ResourceId(org.activityinfo.model.resource.ResourceId) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with FieldValue

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);
}
Also used : FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

FieldValue (org.activityinfo.model.type.FieldValue)49 ResourceId (org.activityinfo.model.resource.ResourceId)16 FormField (org.activityinfo.model.form.FormField)13 Test (org.junit.Test)12 FormInstance (org.activityinfo.model.form.FormInstance)10 Quantity (org.activityinfo.model.type.number.Quantity)9 JsonValue (org.activityinfo.json.JsonValue)8 FormClass (org.activityinfo.model.form.FormClass)8 ReferenceValue (org.activityinfo.model.type.ReferenceValue)7 RecordRef (org.activityinfo.model.type.RecordRef)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 SerialNumberType (org.activityinfo.model.type.SerialNumberType)5 BooleanFieldValue (org.activityinfo.model.type.primitive.BooleanFieldValue)5 SerialNumber (org.activityinfo.model.type.SerialNumber)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 JsonMappingException (org.activityinfo.json.JsonMappingException)3 FormulaNode (org.activityinfo.model.formula.FormulaNode)3