Search in sources :

Example 1 with ParameterizedDatatype

use of com.haulmont.chile.core.datatypes.ParameterizedDatatype in project cuba by cuba-platform.

the class DatatypesControllerManager method getDatatypesJson.

public String getDatatypesJson() {
    JsonArray jsonArray = new JsonArray();
    try {
        for (String id : datatypes.getIds()) {
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("id", id);
            // for backward compatibility
            jsonObject.addProperty("name", id);
            Datatype datatype = datatypes.get(id);
            if (datatype instanceof ParameterizedDatatype) {
                Map<String, Object> parameters = ((ParameterizedDatatype) datatype).getParameters();
                for (Map.Entry<String, Object> entry : parameters.entrySet()) {
                    jsonObject.addProperty(entry.getKey(), entry.getValue().toString());
                }
            }
            jsonArray.add(jsonObject);
        }
    } catch (Exception e) {
        log.error("Fail to get datatype settings", e);
        throw new RestAPIException("Fail to get datatype settings", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return jsonArray.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) ParameterizedDatatype(com.haulmont.chile.core.datatypes.ParameterizedDatatype) JsonObject(com.google.gson.JsonObject) RestAPIException(com.haulmont.restapi.exception.RestAPIException) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) RestAPIException(com.haulmont.restapi.exception.RestAPIException) Datatype(com.haulmont.chile.core.datatypes.Datatype) ParameterizedDatatype(com.haulmont.chile.core.datatypes.ParameterizedDatatype)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 ParameterizedDatatype (com.haulmont.chile.core.datatypes.ParameterizedDatatype)1 RestAPIException (com.haulmont.restapi.exception.RestAPIException)1 Map (java.util.Map)1