Search in sources :

Example 36 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class LetterCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    Letter letter = new Letter();
    model.addAttribute("letter", letter);
    List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
    model.addAttribute("allophones", allophones);
    return "content/letter/create";
}
Also used : Letter(ai.elimu.model.content.Letter) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class LetterEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Letter letter, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    Letter existingLetter = letterDao.readByText(letter.getLocale(), letter.getText());
    if ((existingLetter != null) && !existingLetter.getId().equals(letter.getId())) {
        result.rejectValue("text", "NonUnique");
    }
    if (result.hasErrors()) {
        model.addAttribute("letter", letter);
        List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
        model.addAttribute("allophones", allophones);
        return "content/letter/edit";
    } else {
        letter.setTimeLastUpdate(Calendar.getInstance());
        letter.setRevisionNumber(letter.getRevisionNumber() + 1);
        letterDao.update(letter);
        return "redirect:/content/letter/list#" + letter.getId();
    }
}
Also used : Letter(ai.elimu.model.content.Letter) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class LetterListController 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 Letters
    List<Letter> lettersGenerated = generateLetters(contributor.getLocale());
    for (Letter letter : lettersGenerated) {
        logger.info("letter.getText(): " + letter.getText());
        Letter existingLetter = letterDao.readByText(letter.getLocale(), letter.getText());
        if (existingLetter == null) {
            letterDao.create(letter);
        }
    }
    List<Letter> letters = letterDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("letters", letters);
    int maxUsageCount = 0;
    for (Letter letter : letters) {
        if (letter.getUsageCount() > maxUsageCount) {
            maxUsageCount = letter.getUsageCount();
        }
    }
    model.addAttribute("maxUsageCount", maxUsageCount);
    return "content/letter/list";
}
Also used : Letter(ai.elimu.model.content.Letter) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class AudioCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, /*@Valid*/
Audio audio, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isBlank(audio.getTranscription())) {
        result.rejectValue("transcription", "NotNull");
    } else {
        Audio existingAudio = audioDao.read(audio.getTranscription(), audio.getLocale());
        if (existingAudio != null) {
            result.rejectValue("transcription", "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(".mp3")) {
                audio.setAudioFormat(AudioFormat.MP3);
            } else if (originalFileName.toLowerCase().endsWith(".ogg")) {
                audio.setAudioFormat(AudioFormat.OGG);
            } else if (originalFileName.toLowerCase().endsWith(".wav")) {
                audio.setAudioFormat(AudioFormat.WAV);
            } else {
                result.rejectValue("bytes", "typeMismatch");
            }
            if (audio.getAudioFormat() != null) {
                String contentType = multipartFile.getContentType();
                logger.info("contentType: " + contentType);
                audio.setContentType(contentType);
                audio.setBytes(bytes);
            // TODO: convert to a default audio format?
            }
        }
    } 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/audio/create";
    } else {
        audio.setTranscription(audio.getTranscription().toLowerCase());
        audio.setTimeLastUpdate(Calendar.getInstance());
        audioDao.create(audio);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new Audio:\n" + "• Language: \"" + audio.getLocale().getLanguage() + "\"\n" + "• Transcription: \"" + audio.getTranscription() + "\"\n" + "See ") + "http://elimu.ai/content/multimedia/audio/edit/" + audio.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/multimedia/audio/list#" + audio.getId();
    }
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class AudioEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, Audio audio, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isBlank(audio.getTranscription())) {
        result.rejectValue("transcription", "NotNull");
    } else {
        Audio existingAudio = audioDao.read(audio.getTranscription(), audio.getLocale());
        if ((existingAudio != null) && !existingAudio.getId().equals(audio.getId())) {
            result.rejectValue("transcription", "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(".mp3")) {
                audio.setAudioFormat(AudioFormat.MP3);
            } else if (originalFileName.toLowerCase().endsWith(".ogg")) {
                audio.setAudioFormat(AudioFormat.OGG);
            } else if (originalFileName.toLowerCase().endsWith(".wav")) {
                audio.setAudioFormat(AudioFormat.WAV);
            } else {
                result.rejectValue("bytes", "typeMismatch");
            }
            if (audio.getAudioFormat() != null) {
                String contentType = multipartFile.getContentType();
                logger.info("contentType: " + contentType);
                audio.setContentType(contentType);
                audio.setBytes(bytes);
            // TODO: convert to a default audio format?
            }
        }
    } catch (IOException e) {
        logger.error(e);
    }
    if (result.hasErrors()) {
        model.addAttribute("audio", audio);
        model.addAttribute("contentLicenses", ContentLicense.values());
        model.addAttribute("literacySkills", LiteracySkill.values());
        model.addAttribute("numeracySkills", NumeracySkill.values());
        model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
        model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
        model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
        return "content/multimedia/audio/edit";
    } else {
        audio.setTranscription(audio.getTranscription().toLowerCase());
        audio.setTimeLastUpdate(Calendar.getInstance());
        audio.setRevisionNumber(audio.getRevisionNumber() + 1);
        audioDao.update(audio);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just edited an Audio:\n" + "• Language: \"" + audio.getLocale().getLanguage() + "\"\n" + "• Transcription: \"" + audio.getTranscription() + "\"\n" + "• Revision number: #" + audio.getRevisionNumber() + "\n" + "See ") + "http://elimu.ai/content/multimedia/audio/edit/" + audio.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/multimedia/audio/list#" + audio.getId();
    }
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.Contributor)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 Project (ai.elimu.model.project.Project)12 IOException (java.io.IOException)10 Allophone (ai.elimu.model.content.Allophone)9 Word (ai.elimu.model.content.Word)8 Image (ai.elimu.model.content.multimedia.Image)8 Audio (ai.elimu.model.content.multimedia.Audio)6 Letter (ai.elimu.model.content.Letter)5 Number (ai.elimu.model.content.Number)5 AppCategory (ai.elimu.model.project.AppCategory)5 StoryBook (ai.elimu.model.content.StoryBook)4 Video (ai.elimu.model.content.multimedia.Video)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 AppCollection (ai.elimu.model.project.AppCollection)3 AppGroup (ai.elimu.model.project.AppGroup)3 Locale (java.util.Locale)3 Application (ai.elimu.model.admin.Application)2 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)2 Syllable (ai.elimu.model.content.Syllable)2