Search in sources :

Example 1 with SyllableGson

use of ai.elimu.model.gson.content.SyllableGson in project webapp by elimu-ai.

the class JavaToGsonConverter method getSyllableGson.

public static SyllableGson getSyllableGson(Syllable syllable) {
    if (syllable == null) {
        return null;
    } else {
        SyllableGson syllableGson = new SyllableGson();
        syllableGson.setId(syllable.getId());
        syllableGson.setLocale(syllable.getLocale());
        syllableGson.setTimeLastUpdate(syllable.getTimeLastUpdate());
        syllableGson.setRevisionNumber(syllable.getRevisionNumber());
        syllableGson.setContentStatus(syllable.getContentStatus());
        syllableGson.setText(syllable.getText());
        List<AllophoneGson> allophones = new ArrayList<>();
        for (Allophone allophone : syllable.getAllophones()) {
            AllophoneGson allophoneGson = getAllophoneGson(allophone);
            allophones.add(allophoneGson);
        }
        syllableGson.setAllophones(allophones);
        syllableGson.setUsageCount(syllable.getUsageCount());
        return syllableGson;
    }
}
Also used : AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) Allophone(ai.elimu.model.content.Allophone) SyllableGson(ai.elimu.model.gson.content.SyllableGson) ArrayList(java.util.ArrayList)

Example 2 with SyllableGson

use of ai.elimu.model.gson.content.SyllableGson in project webapp by elimu-ai.

the class SyllableRestController method list.

@RequestMapping("/list")
public String list(HttpServletRequest request, @RequestParam String deviceId, // TODO: checksum,
@RequestParam Locale locale) {
    logger.info("list");
    logger.info("request.getQueryString(): " + request.getQueryString());
    JSONArray syllables = new JSONArray();
    for (Syllable syllable : syllableDao.readAllOrdered(locale)) {
        SyllableGson syllableGson = JavaToGsonConverter.getSyllableGson(syllable);
        String json = new Gson().toJson(syllableGson);
        syllables.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("syllables", syllables);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) SyllableGson(ai.elimu.model.gson.content.SyllableGson) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SyllableGson(ai.elimu.model.gson.content.SyllableGson) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SyllableGson (ai.elimu.model.gson.content.SyllableGson)2 Allophone (ai.elimu.model.content.Allophone)1 Syllable (ai.elimu.model.content.Syllable)1 AllophoneGson (ai.elimu.model.gson.content.AllophoneGson)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1