Search in sources :

Example 1 with AudioGson

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

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

the class AudioRestController 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 jsonArray = new JSONArray();
    for (Audio audio : audioDao.readAllOrdered(locale)) {
        AudioGson audioGson = JavaToGsonConverter.getAudioGson(audio);
        String json = new Gson().toJson(audioGson);
        jsonArray.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("audios", jsonArray);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : AudioGson(ai.elimu.model.gson.content.multimedia.AudioGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AudioGson(ai.elimu.model.gson.content.multimedia.AudioGson) Gson(com.google.gson.Gson) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AudioGson (ai.elimu.model.gson.content.multimedia.AudioGson)2 Letter (ai.elimu.model.content.Letter)1 Number (ai.elimu.model.content.Number)1 Word (ai.elimu.model.content.Word)1 Audio (ai.elimu.model.content.multimedia.Audio)1 LetterGson (ai.elimu.model.gson.content.LetterGson)1 NumberGson (ai.elimu.model.gson.content.NumberGson)1 WordGson (ai.elimu.model.gson.content.WordGson)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