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