Search in sources :

Example 21 with Image

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

the class ImageListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    // To ease development/testing, auto-generate Images
    List<Image> imagesGenerated = generateImages(contributor.getLocale());
    for (Image image : imagesGenerated) {
        Image existingImage = imageDao.read(image.getTitle(), image.getLocale());
        if (existingImage == null) {
            ImageFormat imageFormat = ImageFormat.PNG;
            image.setContentType("image/png");
            String fileName = image.getTitle() + "." + imageFormat.toString().toLowerCase();
            logger.info("Looking up file \"" + image.getTitle() + "." + imageFormat.toString().toLowerCase() + "\"...");
            URL url = getClass().getResource(fileName);
            logger.info("url.getPath(): " + url.getPath());
            try {
                byte[] imageBytes = IOUtils.toByteArray(url);
                image.setBytes(imageBytes);
                image.setImageFormat(imageFormat);
                int[] dominantColor = ImageColorHelper.getDominantColor(image.getBytes());
                image.setDominantColor("rgb(" + dominantColor[0] + "," + dominantColor[1] + "," + dominantColor[2] + ")");
                imageDao.create(image);
            } catch (IOException ex) {
                logger.error(null, ex);
            }
        }
    }
    List<Image> images = imageDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("images", images);
    return "content/multimedia/image/list";
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Image(ai.elimu.model.content.multimedia.Image) URL(java.net.URL) ImageFormat(ai.elimu.model.enums.content.ImageFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Image

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

the class ImageListController method generateImages.

private List<Image> generateImages(Locale locale) {
    List<Image> images = new ArrayList<>();
    Image coverImage175 = new Image();
    coverImage175.setLocale(locale);
    coverImage175.setTimeLastUpdate(Calendar.getInstance());
    coverImage175.setTitle("ASP_175_I_like_to_read_Page_01_Image_0001");
    images.add(coverImage175);
    Image coverImage55 = new Image();
    coverImage55.setLocale(locale);
    coverImage55.setTimeLastUpdate(Calendar.getInstance());
    coverImage55.setTitle("M_ASP_55_Too_small_Page_02_Image_0001");
    images.add(coverImage55);
    return images;
}
Also used : ArrayList(java.util.ArrayList) Image(ai.elimu.model.content.multimedia.Image)

Example 23 with Image

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

the class StoryBookEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(Model model, @PathVariable Long id, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    StoryBook storyBook = storyBookDao.read(id);
    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());
    Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(storyBook);
    model.addAttribute("wordFrequencyMap", wordFrequencyMap);
    Map<String, Integer> letterFrequencyMap = LetterFrequencyHelper.getLetterFrequency(storyBook);
    model.addAttribute("letterFrequencyMap", letterFrequencyMap);
    return "content/storybook/edit";
}
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 24 with Image

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

the class StoryBookListController method generateStoryBooks.

private List<StoryBook> generateStoryBooks(Locale locale) {
    List<StoryBook> storyBooks = new ArrayList<>();
    StoryBook storyBook = new StoryBook();
    storyBook.setLocale(locale.EN);
    storyBook.setTimeLastUpdate(Calendar.getInstance());
    storyBook.setTitle("Too Small");
    Image coverImage = imageDao.read("M_ASP_55_Too_small_Page_02_Image_0001", locale);
    storyBook.setCoverImage(coverImage);
    storyBook.setGradeLevel(GradeLevel.LEVEL3);
    List<String> paragraphs = new ArrayList<>();
    paragraphs.add("\"Mom,\" called Lebo. \"Come and look. These clothes are all too small for me!\"");
    paragraphs.add("\"Let me see,\" said Mom.");
    paragraphs.add("\"Look at my skirt. It's too small,\" said Lebo.");
    paragraphs.add("\"Yes, it is,\" said Mom. \"Nomsa can have your skirt.\"");
    paragraphs.add("\"Look at my jeans. They are too small,\" said Lebo.");
    paragraphs.add("\"Yes, they are,\" said Mom. \"Nomsa can have your jeans.");
    paragraphs.add("\"Look at my T-shirt. It's too small,\" said Lebo.");
    paragraphs.add("\"Yes, it is,\" said Mom. \"Nomsa can have your T-shirt.");
    paragraphs.add("\"Look at my jersey. It is too small,\" said Lebo.");
    paragraphs.add("\"Yes, it is,\" said Mom. \"We will give your jersey to Nomsa.\"");
    paragraphs.add("\"Look at my raincoat. It's too small,\" said Lebo.");
    paragraphs.add("\"Yes, it is. Nomsa can have your raincoat,\" said Mom.");
    paragraphs.add("\"Look at my socks. They are too small,\" said Lebo.");
    paragraphs.add("\"Yes, they certainly are,\" said Mom. \"Nomsa can have your socks.\"");
    paragraphs.add("\"Look at my shoes. They are too small,\" said Lebo.");
    paragraphs.add("\"Yes, they are,\" said Mom. \"Nomsa can have your shoes.\"");
    paragraphs.add("\"Now you have lots of clothes,\" said Lebo.");
    paragraphs.add("\"Oh, no, I don't,\" said Nomsa.");
    paragraphs.add("\"These clothes are all too BIG for me!\"");
    storyBook.setParagraphs(paragraphs);
    storyBooks.add(storyBook);
    return storyBooks;
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) ArrayList(java.util.ArrayList) Image(ai.elimu.model.content.multimedia.Image)

Example 25 with Image

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

the class ImagesRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpServletRequest request) {
    logger.info("handleGetRequest");
    JSONArray imagesJsonArray = new JSONArray();
    for (Image image : imageDao.readAllOrdered()) {
        ImageGson imageGson = JpaToGsonConverter.getImageGson(image);
        String json = new Gson().toJson(imageGson);
        imagesJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = imagesJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : ImageGson(ai.elimu.model.v2.gson.content.ImageGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ImageGson(ai.elimu.model.v2.gson.content.ImageGson) Gson(com.google.gson.Gson) 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