Search in sources :

Example 1 with Image

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);
        }
    }
}
Also used : EOFException(java.io.EOFException) IOException(java.io.IOException) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Image

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();
}
Also used : ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) Gson(com.google.gson.Gson) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Image

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";
}
Also used : Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Image

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";
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Image

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();
    }
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Image (ai.elimu.model.content.multimedia.Image)38 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 StoryBook (ai.elimu.model.content.StoryBook)11 Word (ai.elimu.model.content.Word)11 Contributor (ai.elimu.model.Contributor)8 IOException (java.io.IOException)8 Audio (ai.elimu.model.content.multimedia.Audio)7 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)5 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)5 StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)5 ArrayList (java.util.ArrayList)5 Letter (ai.elimu.model.content.Letter)4 Language (ai.elimu.model.v2.enums.Language)4 Test (org.junit.Test)4 Syllable (ai.elimu.model.content.Syllable)3 ImageContributionEvent (ai.elimu.model.contributor.ImageContributionEvent)3 HashSet (java.util.HashSet)3 Emoji (ai.elimu.model.content.Emoji)2 Number (ai.elimu.model.content.Number)2 AudioContributionEvent (ai.elimu.model.contributor.AudioContributionEvent)2