Search in sources :

Example 6 with JsonValue

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

the class DimensionModel method toJson.

@Value.Lazy
public JsonValue toJson() {
    JsonValue object = Json.createObject();
    object.put("id", getId());
    object.put("label", getLabel());
    object.put("axis", getAxis().name());
    object.put("totals", getTotals());
    object.put("percentage", getPercentage());
    object.put("missingIncluded", getMissingIncluded());
    if (getDateLevel().isPresent()) {
        object.put("dateLevel", getDateLevel().get().name());
    }
    if (getTotalLabel().isPresent()) {
        object.put("totalLabel", getTotalLabel().get());
    }
    JsonValue mappingArray = Json.createArray();
    for (DimensionMapping mapping : getMappings()) {
        mappingArray.add(mapping.toJson());
    }
    object.put("mappings", mappingArray);
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 7 with JsonValue

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

the class AnalysisViewModelTest method serializeAndDeserialize.

private PivotModel serializeAndDeserialize(PivotModel model) {
    JsonValue json = model.toJson();
    PivotModel deserialized = PivotModel.fromJson(json);
    assertThat(deserialized, equalTo(model));
    return deserialized;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 8 with JsonValue

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

the class KeyValueStore method getOfflineForms.

public final Promise<Set<ResourceId>> getOfflineForms() {
    return impl.get(OFFLINE_FORMS).then(json -> {
        if (json == null) {
            return Collections.emptySet();
        } else {
            Set<ResourceId> forms = new HashSet<>();
            JsonValue array = json;
            for (int i = 0; i < array.length(); i++) {
                forms.add(ResourceId.valueOf(array.getString(i)));
            }
            return forms;
        }
    });
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) JsonValue(org.activityinfo.json.JsonValue) HashSet(java.util.HashSet)

Example 9 with JsonValue

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

the class OfflineStore method applyLocalUpdate.

private RecordObject applyLocalUpdate(Optional<RecordObject> existingRecord, RecordUpdate update) {
    RecordObject updatedRecord = new RecordObject();
    // Combine old and new field values
    if (existingRecord.isPresent()) {
        updatedRecord.setParentRecordId(existingRecord.get().getParentRecordId());
        JsonValue existingFields = existingRecord.get().getFields();
        for (String fieldName : existingFields.keys()) {
            updatedRecord.setField(fieldName, existingFields.<JsonValue>get(fieldName));
        }
    }
    for (String fieldName : update.getFields().keys()) {
        updatedRecord.setField(fieldName, update.getFields().<JsonValue>get(fieldName));
    }
    // Only update parent record if this is a new record
    if (!existingRecord.isPresent()) {
        updatedRecord.setParentRecordId(update.getParentRecordId());
    }
    return updatedRecord;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 10 with JsonValue

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

the class GeoAdminClient method getFormTree.

public FormTree getFormTree(ResourceId resourceId) {
    if (localCatalog.isLocalResource(resourceId)) {
        FormTreeBuilder treeBuilder = new FormTreeBuilder(localCatalog);
        return treeBuilder.queryTree(resourceId);
    } else {
        String json = formResource(resourceId).path("tree").get(String.class);
        JsonValue object = new Gson().fromJson(json, JsonValue.class);
        return JsonFormTreeBuilder.fromJson(object);
    }
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Gson(com.google.gson.Gson) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

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