Search in sources :

Example 1 with LetterGson

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

the class JavaToGsonConverter method getLetterGson.

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

Example 2 with LetterGson

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

the class JavaToGsonConverter method getImageGson.

public static ImageGson getImageGson(Image image) {
    if (image == null) {
        return null;
    } else {
        ImageGson imageGson = new ImageGson();
        imageGson.setId(image.getId());
        imageGson.setLocale(image.getLocale());
        imageGson.setTimeLastUpdate(image.getTimeLastUpdate());
        imageGson.setRevisionNumber(image.getRevisionNumber());
        imageGson.setContentStatus(image.getContentStatus());
        imageGson.setDownloadUrl("/image/" + image.getId() + "." + image.getImageFormat().toString().toLowerCase());
        imageGson.setDownloadSize(image.getBytes().length / 1024);
        imageGson.setContentType(image.getContentType());
        imageGson.setLiteracySkills(image.getLiteracySkills());
        imageGson.setNumeracySkills(image.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : image.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        imageGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : image.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        imageGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : image.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        imageGson.setWords(words);
        imageGson.setTitle(image.getTitle());
        imageGson.setImageFormat(image.getImageFormat());
        imageGson.setDominantColor(image.getDominantColor());
        return imageGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 3 with LetterGson

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

the class JavaToGsonConverter method getVideoGson.

public static VideoGson getVideoGson(Video video) {
    if (video == null) {
        return null;
    } else {
        VideoGson videoGson = new VideoGson();
        videoGson.setId(video.getId());
        videoGson.setLocale(video.getLocale());
        videoGson.setTimeLastUpdate(video.getTimeLastUpdate());
        videoGson.setRevisionNumber(video.getRevisionNumber());
        videoGson.setContentStatus(video.getContentStatus());
        videoGson.setDownloadUrl("/video/" + video.getId() + "." + video.getVideoFormat().toString().toLowerCase());
        videoGson.setDownloadSize(video.getBytes().length / 1024);
        videoGson.setContentType(video.getContentType());
        videoGson.setLiteracySkills(video.getLiteracySkills());
        videoGson.setNumeracySkills(video.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : video.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        videoGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : video.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        videoGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : video.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        videoGson.setWords(words);
        videoGson.setTitle(video.getTitle());
        videoGson.setVideoFormat(video.getVideoFormat());
        videoGson.setThumbnailDownloadUrl("/video/" + video.getId() + "/thumbnail.png");
        return videoGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) VideoGson(ai.elimu.model.gson.content.multimedia.VideoGson) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 4 with LetterGson

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

the class JavaToGsonConverter method getAudioGson.

public static AudioGson getAudioGson(Audio audio) {
    if (audio == null) {
        return null;
    } else {
        AudioGson audioGson = new AudioGson();
        audioGson.setId(audio.getId());
        audioGson.setLocale(audio.getLocale());
        audioGson.setTimeLastUpdate(audio.getTimeLastUpdate());
        audioGson.setRevisionNumber(audio.getRevisionNumber());
        audioGson.setContentStatus(audio.getContentStatus());
        audioGson.setDownloadUrl("/audio/" + audio.getId() + "." + audio.getAudioFormat().toString().toLowerCase());
        audioGson.setDownloadSize(audio.getBytes().length / 1024);
        audioGson.setContentType(audio.getContentType());
        audioGson.setLiteracySkills(audio.getLiteracySkills());
        audioGson.setNumeracySkills(audio.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : audio.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        audioGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : audio.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        audioGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : audio.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        audioGson.setWords(words);
        audioGson.setTranscription(audio.getTranscription());
        audioGson.setAudioType(audio.getAudioFormat());
        return audioGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) AudioGson(ai.elimu.model.gson.content.multimedia.AudioGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 5 with LetterGson

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

the class LetterRestController 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 numbers = new JSONArray();
    for (Letter letter : letterDao.readAllOrdered(locale)) {
        LetterGson letterGson = JavaToGsonConverter.getLetterGson(letter);
        String json = new Gson().toJson(letterGson);
        numbers.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("letters", numbers);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
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.gson.content.LetterGson) LetterGson(ai.elimu.model.gson.content.LetterGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LetterGson (ai.elimu.model.gson.content.LetterGson)5 Letter (ai.elimu.model.content.Letter)4 ArrayList (java.util.ArrayList)4 Number (ai.elimu.model.content.Number)3 Word (ai.elimu.model.content.Word)3 NumberGson (ai.elimu.model.gson.content.NumberGson)3 WordGson (ai.elimu.model.gson.content.WordGson)3 Allophone (ai.elimu.model.content.Allophone)1 AllophoneGson (ai.elimu.model.gson.content.AllophoneGson)1 AudioGson (ai.elimu.model.gson.content.multimedia.AudioGson)1 ImageGson (ai.elimu.model.gson.content.multimedia.ImageGson)1 VideoGson (ai.elimu.model.gson.content.multimedia.VideoGson)1 Gson (com.google.gson.Gson)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1