Search in sources :

Example 1 with EmojiGson

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

the class JpaToGsonConverter method getEmojiGson.

public static EmojiGson getEmojiGson(Emoji emoji) {
    if (emoji == null) {
        return null;
    } else {
        EmojiGson emojiGson = new EmojiGson();
        // BaseEntity
        emojiGson.setId(emoji.getId());
        // Content
        emojiGson.setRevisionNumber(emoji.getRevisionNumber());
        emojiGson.setUsageCount(emoji.getUsageCount());
        // Emoji
        emojiGson.setGlyph(emoji.getGlyph());
        emojiGson.setUnicodeVersion(emoji.getUnicodeVersion());
        emojiGson.setUnicodeEmojiVersion(emoji.getUnicodeEmojiVersion());
        Set<WordGson> wordGsons = new HashSet<>();
        for (Word word : emoji.getWords()) {
            WordGson wordGson = new WordGson();
            wordGson.setId(word.getId());
            wordGsons.add(wordGson);
        }
        emojiGson.setWords(wordGsons);
        return emojiGson;
    }
}
Also used : EmojiGson(ai.elimu.model.v2.gson.content.EmojiGson) WordGson(ai.elimu.model.v2.gson.content.WordGson) Word(ai.elimu.model.content.Word) HashSet(java.util.HashSet)

Example 2 with EmojiGson

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

the class EmojisRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpServletRequest request) {
    logger.info("handleGetRequest");
    JSONArray emojisJsonArray = new JSONArray();
    for (Emoji emoji : emojiDao.readAllOrdered()) {
        EmojiGson emojiGson = JpaToGsonConverter.getEmojiGson(emoji);
        String json = new Gson().toJson(emojiGson);
        emojisJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = emojisJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : EmojiGson(ai.elimu.model.v2.gson.content.EmojiGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Emoji(ai.elimu.model.content.Emoji) EmojiGson(ai.elimu.model.v2.gson.content.EmojiGson) Gson(com.google.gson.Gson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EmojiGson (ai.elimu.model.v2.gson.content.EmojiGson)2 Emoji (ai.elimu.model.content.Emoji)1 Word (ai.elimu.model.content.Word)1 WordGson (ai.elimu.model.v2.gson.content.WordGson)1 Gson (com.google.gson.Gson)1 HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1