Search in sources :

Example 6 with Video

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

the class VideoCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, /*@Valid*/
Video video, @RequestParam("bytes") MultipartFile multipartFile, @RequestParam("thumbnail") MultipartFile multipartFileThumbnail, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isBlank(video.getTitle())) {
        result.rejectValue("title", "NotNull");
    } else {
        Video existingVideo = videoDao.read(video.getTitle(), video.getLocale());
        if (existingVideo != null) {
            result.rejectValue("title", "NonUnique");
        }
    }
    try {
        byte[] bytes = multipartFile.getBytes();
        if (multipartFile.isEmpty() || (bytes == null) || (bytes.length == 0)) {
            result.rejectValue("bytes", "NotNull");
        } else {
            String originalFileName = multipartFile.getOriginalFilename();
            logger.info("originalFileName: " + originalFileName);
            if (originalFileName.toLowerCase().endsWith(".m4v")) {
                video.setVideoFormat(VideoFormat.M4V);
            } else if (originalFileName.toLowerCase().endsWith(".mp4")) {
                video.setVideoFormat(VideoFormat.MP4);
            } else {
                result.rejectValue("bytes", "typeMismatch");
            }
            if (video.getVideoFormat() != null) {
                String contentType = multipartFile.getContentType();
                logger.info("contentType: " + contentType);
                video.setContentType(contentType);
                video.setBytes(bytes);
            // TODO: convert to a default video format?
            }
        }
        byte[] bytesThumbnail = multipartFileThumbnail.getBytes();
        if (multipartFileThumbnail.isEmpty() || (bytesThumbnail == null) || (bytesThumbnail.length == 0)) {
            result.rejectValue("thumbnail", "NotNull");
        } else {
            String originalFileName = multipartFileThumbnail.getOriginalFilename();
            logger.info("originalFileName: " + originalFileName);
            if (!originalFileName.toLowerCase().endsWith(".png")) {
                result.rejectValue("thumbnail", "typeMismatch");
            } else {
                video.setThumbnail(bytesThumbnail);
                int width = ImageHelper.getWidth(bytesThumbnail);
                logger.info("width: " + width + "px");
                if (width < ImageHelper.MINIMUM_WIDTH) {
                    result.rejectValue("thumbnail", "image.too.small");
                    video.setBytes(null);
                } else {
                    if (width > ImageHelper.MINIMUM_WIDTH) {
                        bytesThumbnail = ImageHelper.scaleImage(bytesThumbnail, ImageHelper.MINIMUM_WIDTH);
                        video.setBytes(bytesThumbnail);
                    }
                }
            }
        }
    } catch (IOException e) {
        logger.error(e);
    }
    if (result.hasErrors()) {
        model.addAttribute("contentLicenses", ContentLicense.values());
        model.addAttribute("literacySkills", LiteracySkill.values());
        model.addAttribute("numeracySkills", NumeracySkill.values());
        return "content/multimedia/video/create";
    } else {
        video.setTitle(video.getTitle().toLowerCase());
        video.setTimeLastUpdate(Calendar.getInstance());
        videoDao.create(video);
        VideoRevisionEvent videoRevisionEvent = new VideoRevisionEvent();
        videoRevisionEvent.setContributor(contributor);
        videoRevisionEvent.setCalendar(Calendar.getInstance());
        videoRevisionEvent.setVideo(video);
        videoRevisionEvent.setTitle(video.getTitle());
        videoRevisionEventDao.create(videoRevisionEvent);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new Video:\n" + "• Language: \"" + video.getLocale().getLanguage() + "\"\n" + "• Title: \"" + video.getTitle() + "\"\n" + "See ") + "http://elimu.ai/content/multimedia/video/edit/" + video.getId();
            String iconUrl = contributor.getImageUrl();
            String imageUrl = "http://elimu.ai/video/" + video.getId() + "/thumbnail.png";
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, imageUrl);
        }
        return "redirect:/content/multimedia/video/list#" + video.getId();
    }
}
Also used : VideoRevisionEvent(ai.elimu.model.contributor.VideoRevisionEvent) Video(ai.elimu.model.content.multimedia.Video) Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Video

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

the class VideoCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
    logger.info("handleRequest");
    Video video = new Video();
    model.addAttribute("video", video);
    model.addAttribute("contentLicenses", ContentLicense.values());
    model.addAttribute("literacySkills", LiteracySkill.values());
    model.addAttribute("numeracySkills", NumeracySkill.values());
    return "content/multimedia/video/create";
}
Also used : Video(ai.elimu.model.content.multimedia.Video) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Video

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

the class VideoEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, Video video, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isBlank(video.getTitle())) {
        result.rejectValue("title", "NotNull");
    } else {
        Video existingVideo = videoDao.read(video.getTitle(), video.getLocale());
        if ((existingVideo != null) && !existingVideo.getId().equals(video.getId())) {
            result.rejectValue("title", "NonUnique");
        }
    }
    try {
        byte[] bytes = multipartFile.getBytes();
        if (multipartFile.isEmpty() || (bytes == null) || (bytes.length == 0)) {
            result.rejectValue("bytes", "NotNull");
        } else {
            String originalFileName = multipartFile.getOriginalFilename();
            logger.info("originalFileName: " + originalFileName);
            if (originalFileName.toLowerCase().endsWith(".m4v")) {
                video.setVideoFormat(VideoFormat.M4V);
            } else if (originalFileName.toLowerCase().endsWith(".mp4")) {
                video.setVideoFormat(VideoFormat.MP4);
            } else {
                result.rejectValue("bytes", "typeMismatch");
            }
            if (video.getVideoFormat() != null) {
                String contentType = multipartFile.getContentType();
                logger.info("contentType: " + contentType);
                video.setContentType(contentType);
                video.setBytes(bytes);
            // TODO: convert to a default video format?
            }
        }
    } catch (IOException e) {
        logger.error(e);
    }
    if (result.hasErrors()) {
        model.addAttribute("video", video);
        model.addAttribute("contentLicenses", ContentLicense.values());
        model.addAttribute("literacySkills", LiteracySkill.values());
        model.addAttribute("numeracySkills", NumeracySkill.values());
        model.addAttribute("videoRevisionEvents", videoRevisionEventDao.readAll(video));
        model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
        model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
        model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
        return "content/multimedia/video/edit";
    } else {
        video.setTitle(video.getTitle().toLowerCase());
        video.setTimeLastUpdate(Calendar.getInstance());
        video.setRevisionNumber(video.getRevisionNumber() + 1);
        videoDao.update(video);
        VideoRevisionEvent videoRevisionEvent = new VideoRevisionEvent();
        videoRevisionEvent.setContributor(contributor);
        videoRevisionEvent.setCalendar(Calendar.getInstance());
        videoRevisionEvent.setVideo(video);
        videoRevisionEvent.setTitle(video.getTitle());
        videoRevisionEventDao.create(videoRevisionEvent);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated a Video:\n" + "• Language: \"" + video.getLocale().getLanguage() + "\"\n" + "• Title: \"" + video.getTitle() + "\"\n" + "• Revision number: #" + video.getRevisionNumber() + "\n" + "See ") + "http://elimu.ai/content/multimedia/video/edit/" + video.getId();
            String iconUrl = contributor.getImageUrl();
            String imageUrl = "http://elimu.ai/video/" + video.getId() + "/thumbnail.png";
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, imageUrl);
        }
        return "redirect:/content/multimedia/video/list#" + video.getId();
    }
}
Also used : VideoRevisionEvent(ai.elimu.model.contributor.VideoRevisionEvent) Video(ai.elimu.model.content.multimedia.Video) Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Video

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

the class VideoListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Video> videos = videoDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("videos", videos);
    return "content/multimedia/video/list";
}
Also used : Video(ai.elimu.model.content.multimedia.Video) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Video

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

the class VideoRestController 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 (Video video : videoDao.readAllOrdered(locale)) {
        VideoGson videoGson = JavaToGsonConverter.getVideoGson(video);
        String json = new Gson().toJson(videoGson);
        jsonArray.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("videos", jsonArray);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) Video(ai.elimu.model.content.multimedia.Video) JSONArray(org.json.JSONArray) VideoGson(ai.elimu.model.gson.content.multimedia.VideoGson) Gson(com.google.gson.Gson) VideoGson(ai.elimu.model.gson.content.multimedia.VideoGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Video (ai.elimu.model.content.multimedia.Video)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 Contributor (ai.elimu.model.Contributor)4 IOException (java.io.IOException)4 Letter (ai.elimu.model.content.Letter)2 Number (ai.elimu.model.content.Number)2 Word (ai.elimu.model.content.Word)2 VideoRevisionEvent (ai.elimu.model.contributor.VideoRevisionEvent)2 EOFException (java.io.EOFException)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 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