use of ai.elimu.model.content.multimedia.Image in project webapp by elimu-ai.
the class ImageController method handleRequest.
@RequestMapping(value = "/{imageId}.{imageFormat}", method = RequestMethod.GET)
public void handleRequest(Model model, @PathVariable Long imageId, @PathVariable String imageFormat, HttpServletResponse response, OutputStream outputStream) {
logger.info("handleRequest");
logger.info("imageId: " + imageId);
logger.info("imageFormat: " + imageFormat);
Image image = imageDao.read(imageId);
response.setContentType(image.getContentType());
byte[] bytes = image.getBytes();
response.setContentLength(bytes.length);
try {
outputStream.write(bytes);
} catch (EOFException ex) {
// org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
logger.warn(ex);
} catch (IOException ex) {
logger.error(null, ex);
} finally {
try {
try {
outputStream.flush();
outputStream.close();
} catch (EOFException ex) {
// org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
logger.warn(ex);
}
} catch (IOException ex) {
logger.error(null, ex);
}
}
}
use of ai.elimu.model.content.multimedia.Image in project webapp by elimu-ai.
the class ImageRestController 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 (Image image : imageDao.readAllOrdered(locale)) {
ImageGson imageGson = JavaToGsonConverter.getImageGson(image);
String json = new Gson().toJson(imageGson);
jsonArray.put(new JSONObject(json));
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("result", "success");
jsonObject.put("images", jsonArray);
logger.info("jsonObject: " + jsonObject);
return jsonObject.toString();
}
use of ai.elimu.model.content.multimedia.Image in project webapp by elimu-ai.
the class ImageEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
Image image = imageDao.read(id);
model.addAttribute("image", image);
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
// model.addAttribute("imageRevisionEvents", imageRevisionEventDao.readAll(image));
model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
Audio audio = audioDao.read(image.getTitle(), contributor.getLocale());
model.addAttribute("audio", audio);
return "content/multimedia/image/edit";
}
use of ai.elimu.model.content.multimedia.Image in project webapp by elimu-ai.
the class StoryBookCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook storyBook = new StoryBook();
model.addAttribute("storyBook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
return "content/storybook/create";
}
use of ai.elimu.model.content.multimedia.Image in project webapp by elimu-ai.
the class StoryBookCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid StoryBook storyBook, BindingResult result, Model model) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook existingStoryBook = storybookDao.readByTitle(storyBook.getLocale(), storyBook.getTitle());
if (existingStoryBook != null) {
result.rejectValue("title", "NonUnique");
}
List<String> paragraphs = storyBook.getParagraphs();
logger.info("paragraphs: " + paragraphs);
if (result.hasErrors()) {
model.addAttribute("storybook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
return "content/storybook/create";
} else {
storyBook.setTimeLastUpdate(Calendar.getInstance());
storybookDao.create(storyBook);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new StoryBook:\n" + "• Language: \"" + storyBook.getLocale().getLanguage() + "\"\n" + "• Title: \"" + storyBook.getTitle() + "\"\n" + "• Grade level: " + storyBook.getGradeLevel() + "\n" + "• Paragraphs: " + storyBook.getParagraphs() + "\n" + "See ") + "http://elimu.ai/content/storybook/edit/" + storyBook.getId();
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
}
return "redirect:/content/storybook/list#" + storyBook.getId();
}
}
Aggregations