Search in sources :

Example 86 with JsonValue

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

the class SerialNumberType method getParametersAsJson.

@Override
public JsonValue getParametersAsJson() {
    JsonValue object = createObject();
    if (!Strings.isNullOrEmpty(prefixFormula)) {
        object.put("prefixFormula", prefixFormula);
    }
    object.put("digits", digits);
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 87 with JsonValue

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

the class GeoAreaType method parseJsonValue.

@Override
public FieldValue parseJsonValue(JsonValue value) {
    JsonValue object = value;
    JsonValue bbox = object.get("bbox");
    return new GeoArea(Extents.fromJsonObject(bbox));
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 88 with JsonValue

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

the class RootResource method update.

@POST
@Path("/update")
@Consumes(MediaType.APPLICATION_JSON)
public Response update(String json) {
    final JsonValue jsonElement = Json.parse(json);
    Updater updater = backend.newUpdater();
    try {
        updater.execute(jsonElement);
    } catch (InvalidUpdateException e) {
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
    }
    return Response.ok().build();
}
Also used : Updater(org.activityinfo.store.query.server.Updater) JsonValue(org.activityinfo.json.JsonValue) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException)

Example 89 with JsonValue

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

the class FormConverterTest method deserializationEnumTypeNoChoices.

@Test
public void deserializationEnumTypeNoChoices() {
    EnumType type = new EnumType(Cardinality.SINGLE, EnumType.Presentation.AUTOMATIC, Collections.<EnumItem>emptyList());
    JsonValue jsonObject = type.getParametersAsJson();
    EmbeddedEntity entity = FormConverter.toEmbeddedEntity(jsonObject);
    JsonValue fromEntity = FormConverter.fromEmbeddedEntity(entity);
    EnumType reType = EnumType.TYPE_CLASS.deserializeType(fromEntity);
    assertThat(reType.getCardinality(), equalTo(Cardinality.SINGLE));
    assertThat(reType.getPresentation(), equalTo(EnumType.Presentation.AUTOMATIC));
    assertThat(reType.getValues(), hasSize(0));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) JsonValue(org.activityinfo.json.JsonValue) EmbeddedEntity(com.google.appengine.api.datastore.EmbeddedEntity) Test(org.junit.Test)

Example 90 with JsonValue

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

the class ExportAuditLog method toJson.

@Override
public JsonValue toJson() {
    JsonValue object = createObject();
    object.put("databaseId", databaseId);
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

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