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