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;
}
}
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();
}
Aggregations