Search in sources :

Example 1 with SoundGson

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

the class SoundsRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest() {
    logger.info("handleGetRequest");
    JSONArray soundsJsonArray = new JSONArray();
    for (Sound sound : soundDao.readAllOrdered()) {
        SoundGson soundGson = JpaToGsonConverter.getSoundGson(sound);
        String json = new Gson().toJson(soundGson);
        soundsJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = soundsJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) SoundGson(ai.elimu.model.v2.gson.content.SoundGson) Gson(com.google.gson.Gson) SoundGson(ai.elimu.model.v2.gson.content.SoundGson) Sound(ai.elimu.model.content.Sound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SoundGson

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

the class JpaToGsonConverter method getLetterSoundCorrespondenceGson.

public static LetterSoundCorrespondenceGson getLetterSoundCorrespondenceGson(LetterSoundCorrespondence letterSoundCorrespondence) {
    if (letterSoundCorrespondence == null) {
        return null;
    } else {
        LetterSoundCorrespondenceGson letterSoundCorrespondenceGson = new LetterSoundCorrespondenceGson();
        // BaseEntity
        letterSoundCorrespondenceGson.setId(letterSoundCorrespondence.getId());
        // LetterSoundCorrespondence
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : letterSoundCorrespondence.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        letterSoundCorrespondenceGson.setLetters(letters);
        List<SoundGson> sounds = new ArrayList<>();
        for (Sound sound : letterSoundCorrespondence.getSounds()) {
            SoundGson soundGson = getSoundGson(sound);
            sounds.add(soundGson);
        }
        letterSoundCorrespondenceGson.setSounds(sounds);
        letterSoundCorrespondenceGson.setUsageCount(letterSoundCorrespondence.getUsageCount());
        return letterSoundCorrespondenceGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) ArrayList(java.util.ArrayList) SoundGson(ai.elimu.model.v2.gson.content.SoundGson) Sound(ai.elimu.model.content.Sound) LetterGson(ai.elimu.model.v2.gson.content.LetterGson) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson)

Example 3 with SoundGson

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

the class JpaToGsonConverter method getSoundGson.

public static SoundGson getSoundGson(Sound sound) {
    if (sound == null) {
        return null;
    } else {
        SoundGson soundGson = new SoundGson();
        // BaseEntity
        soundGson.setId(sound.getId());
        // Content
        soundGson.setRevisionNumber(sound.getRevisionNumber());
        soundGson.setUsageCount(sound.getUsageCount());
        // Sound
        soundGson.setValueIpa(sound.getValueIpa());
        soundGson.setDiacritic(sound.isDiacritic());
        soundGson.setSoundType(sound.getSoundType());
        return soundGson;
    }
}
Also used : SoundGson(ai.elimu.model.v2.gson.content.SoundGson)

Aggregations

SoundGson (ai.elimu.model.v2.gson.content.SoundGson)3 Sound (ai.elimu.model.content.Sound)2 Letter (ai.elimu.model.content.Letter)1 LetterGson (ai.elimu.model.v2.gson.content.LetterGson)1 LetterSoundCorrespondenceGson (ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson)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