Search in sources :

Example 1 with LetterGson

use of ai.elimu.model.v2.gson.content.LetterGson 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 2 with LetterGson

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

the class LettersRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest() {
    logger.info("handleGetRequest");
    JSONArray lettersJsonArray = new JSONArray();
    for (Letter letter : letterDao.readAllOrdered()) {
        LetterGson letterGson = JpaToGsonConverter.getLetterGson(letter);
        String json = new Gson().toJson(letterGson);
        lettersJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = lettersJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : Letter(ai.elimu.model.content.Letter) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) LetterGson(ai.elimu.model.v2.gson.content.LetterGson) LetterGson(ai.elimu.model.v2.gson.content.LetterGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with LetterGson

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

the class JpaToGsonConverter method getLetterGson.

public static LetterGson getLetterGson(Letter letter) {
    if (letter == null) {
        return null;
    } else {
        LetterGson letterGson = new LetterGson();
        // BaseEntity
        letterGson.setId(letter.getId());
        // Content
        letterGson.setRevisionNumber(letter.getRevisionNumber());
        letterGson.setUsageCount(letter.getUsageCount());
        // Letter
        letterGson.setText(letter.getText());
        letterGson.setDiacritic(letter.isDiacritic());
        return letterGson;
    }
}
Also used : LetterGson(ai.elimu.model.v2.gson.content.LetterGson)

Aggregations

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