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;
}
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;
}
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));
}
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);
}
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);
}
Aggregations