Search in sources :

Example 1 with DataType

use of com.tvd12.dahlia.core.data.DataType in project dahlia by youngmonkeys.

the class LocalCollectionSettingReader method readFieldArraySetting.

protected FieldSetting readFieldArraySetting(JSONObject setting) {
    FieldArraySetting field = new FieldArraySetting();
    if (setting.has(SettingFields.MAX_SIZE))
        field.setMaxSize(setting.getInt(SettingFields.MAX_SIZE));
    if (setting.has(SettingFields.ITEM)) {
        JSONObject itemSetting = setting.getJSONObject(SettingFields.ITEM);
        DataType itemType = null;
        if (itemSetting.has(SettingFields.TYPE))
            itemType = DataType.valueOfName(itemSetting.getString(SettingFields.TYPE));
        else
            throw new IllegalArgumentException("item 'type' is required");
        FieldSetting item = readFieldSetting(itemType, itemSetting);
        field.setItem(item);
    } else {
        throw new IllegalArgumentException("'item' field is required");
    }
    return field;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting) JSONObject(org.json.JSONObject) DataType(com.tvd12.dahlia.core.data.DataType)

Example 2 with DataType

use of com.tvd12.dahlia.core.data.DataType in project dahlia by youngmonkeys.

the class SettingObjectToFields method toSetting.

public FieldSetting toSetting(EzyObject object) {
    DataType type = DataType.valueOf(object.get(SettingFields.TYPE));
    SettingObjectToField mapper = mappers.get(type);
    FieldSetting answer = mapper.toSetting(this, object);
    return answer;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) DataType(com.tvd12.dahlia.core.data.DataType)

Example 3 with DataType

use of com.tvd12.dahlia.core.data.DataType in project dahlia by youngmonkeys.

the class LocalCollectionSettingReader method readFieldSettings.

protected Map<String, FieldSetting> readFieldSettings(JSONObject settings) {
    Map<String, FieldSetting> answer = new HashMap<>();
    for (String fieldName : settings.keySet()) {
        JSONObject setting = settings.getJSONObject(fieldName);
        DataType type = null;
        if (setting.has(SettingFields.TYPE))
            type = DataType.valueOfName(setting.getString(SettingFields.TYPE));
        else
            throw new IllegalArgumentException("'type' is required at field: " + fieldName);
        answer.put(fieldName, readFieldSetting(type, setting));
    }
    return answer;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) DataType(com.tvd12.dahlia.core.data.DataType)

Aggregations

DataType (com.tvd12.dahlia.core.data.DataType)3 FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)3 JSONObject (org.json.JSONObject)2 FieldArraySetting (com.tvd12.dahlia.core.setting.FieldArraySetting)1 HashMap (java.util.HashMap)1