Search in sources :

Example 1 with VideoGson

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

the class VideosRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpServletRequest request) {
    logger.info("handleGetRequest");
    JSONArray videosJsonArray = new JSONArray();
    for (Video video : videoDao.readAllOrdered()) {
        VideoGson videoGson = JpaToGsonConverter.getVideoGson(video);
        String json = new Gson().toJson(videoGson);
        videosJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = videosJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : JSONObject(org.json.JSONObject) Video(ai.elimu.model.content.multimedia.Video) JSONArray(org.json.JSONArray) VideoGson(ai.elimu.model.v2.gson.content.VideoGson) VideoGson(ai.elimu.model.v2.gson.content.VideoGson) Gson(com.google.gson.Gson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with VideoGson

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

the class JpaToGsonConverter method getVideoGson.

public static VideoGson getVideoGson(Video video) {
    if (video == null) {
        return null;
    } else {
        VideoGson videoGson = new VideoGson();
        // BaseEntity
        videoGson.setId(video.getId());
        // Content
        videoGson.setRevisionNumber(video.getRevisionNumber());
        videoGson.setUsageCount(video.getUsageCount());
        // Video
        videoGson.setTitle(video.getTitle());
        videoGson.setVideoFormat(video.getVideoFormat());
        videoGson.setBytesUrl("/video/" + video.getId() + "_r" + video.getRevisionNumber() + "." + video.getVideoFormat().toString().toLowerCase());
        videoGson.setBytesSize(video.getBytes().length / 1024);
        Set<WordGson> wordGsons = new HashSet<>();
        for (Word word : video.getWords()) {
            WordGson wordGson = new WordGson();
            wordGson.setId(word.getId());
            wordGsons.add(wordGson);
        }
        videoGson.setWords(wordGsons);
        return videoGson;
    }
}
Also used : WordGson(ai.elimu.model.v2.gson.content.WordGson) Word(ai.elimu.model.content.Word) VideoGson(ai.elimu.model.v2.gson.content.VideoGson) HashSet(java.util.HashSet)

Aggregations

VideoGson (ai.elimu.model.v2.gson.content.VideoGson)2 Word (ai.elimu.model.content.Word)1 Video (ai.elimu.model.content.multimedia.Video)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