Search in sources :

Example 91 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class FormRecordSet method toJson.

@Override
public JsonValue toJson() {
    JsonValue array = Json.createArray();
    for (FormRecord record : records) {
        array.add(record.toJson());
    }
    JsonValue object = Json.createObject();
    object.put("formId", formId);
    object.put("records", array);
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 92 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class FormSection method toJsonObject.

@Override
public JsonValue toJsonObject() {
    JsonValue object = createObject();
    object.put("id", id.asString());
    object.put("label", label);
    object.put("type", "section");
    object.put("elements", FormClass.toJsonArray(elements));
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 93 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class ActivityInfoClientAsyncStub method getRecords.

@Override
public Promise<FormRecordSet> getRecords(String formId, String parentId) {
    FormStorageProvider catalog = newCatalog();
    Optional<FormStorage> collection = catalog.getForm(ResourceId.valueOf(formId));
    JsonValue recordArray = Json.createArray();
    if (collection.isPresent()) {
        if (collection.get() instanceof HrdFormStorage) {
            HrdFormStorage hrdForm = (HrdFormStorage) collection.get();
            Iterable<FormRecord> records = hrdForm.getSubRecords(ResourceId.valueOf(parentId));
            for (FormRecord record : records) {
                recordArray.add(record.toJson());
            }
        }
    }
    JsonValue object = createObject();
    object.put("formId", formId);
    object.put("records", recordArray);
    return Promise.resolved(FormRecordSet.fromJson(object));
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) FormStorage(org.activityinfo.store.spi.FormStorage) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage) JsonValue(org.activityinfo.json.JsonValue) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage)

Example 94 with JsonValue

use of org.activityinfo.json.JsonValue 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);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 95 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class UpdaterTest method invalidChangesProperty.

@Test(expected = InvalidUpdateException.class)
public void invalidChangesProperty() {
    JsonValue updateObject = createObject();
    updateObject.put("changes", 42);
    updater.execute(updateObject);
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Test(org.junit.Test)

Aggregations

JsonValue (org.activityinfo.json.JsonValue)117 Test (org.junit.Test)24 ResourceId (org.activityinfo.model.resource.ResourceId)19 FormClass (org.activityinfo.model.form.FormClass)13 FormField (org.activityinfo.model.form.FormField)9 FieldValue (org.activityinfo.model.type.FieldValue)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3 JaxRsJsonReader (org.activityinfo.server.endpoint.rest.JaxRsJsonReader)3 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)3 EmbeddedEntity (com.google.appengine.api.datastore.EmbeddedEntity)2 URL (java.net.URL)2 JsonException (org.activityinfo.json.JsonException)2 JsonMappingException (org.activityinfo.json.JsonMappingException)2