Search in sources :

Example 26 with Word

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

the class NumberEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
    logger.info("handleRequest");
    Number number = numberDao.read(id);
    model.addAttribute("number", number);
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("words", words);
    return "content/number/edit";
}
Also used : Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with Word

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

the class NumberListController method getNumberWords.

private List<Word> getNumberWords(Locale locale, String... words) {
    List<Word> numberWords = new ArrayList<>();
    for (String word : words) {
        Word numberWord = wordDao.readByText(locale, word);
        numberWords.add(numberWord);
    }
    return numberWords;
}
Also used : Word(ai.elimu.model.content.Word) ArrayList(java.util.ArrayList)

Example 28 with Word

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

the class WordEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Word word, BindingResult result, Model model, HttpServletRequest request) {
    logger.info("handleSubmit");
    Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
    if ((existingWord != null) && !existingWord.getId().equals(word.getId())) {
        result.rejectValue("text", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
    // Verify that only valid Allophones are used
    String allAllophonesCombined = "";
    for (Allophone allophone : allophones) {
        allAllophonesCombined += allophone.getValueIpa();
    }
    if (StringUtils.isNotBlank(word.getPhonetics())) {
        for (char allophoneCharacter : word.getPhonetics().toCharArray()) {
            String allophone = String.valueOf(allophoneCharacter);
            if (!allAllophonesCombined.contains(allophone)) {
                result.rejectValue("phonetics", "Invalid");
                break;
            }
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("word", word);
        model.addAttribute("allophones", allophones);
        model.addAttribute("wordTypes", WordType.values());
        model.addAttribute("spellingConsistencies", SpellingConsistency.values());
        model.addAttribute("wordRevisionEvents", wordRevisionEventDao.readAll(word));
        Audio audio = audioDao.read(word.getText(), contributor.getLocale());
        model.addAttribute("audio", audio);
        return "content/word/edit";
    } else {
        if (!"I".equals(word.getText())) {
            word.setText(word.getText().toLowerCase());
        }
        word.setTimeLastUpdate(Calendar.getInstance());
        word.setRevisionNumber(word.getRevisionNumber() + 1);
        wordDao.update(word);
        WordRevisionEvent wordRevisionEvent = new WordRevisionEvent();
        wordRevisionEvent.setContributor(contributor);
        wordRevisionEvent.setCalendar(Calendar.getInstance());
        wordRevisionEvent.setWord(word);
        wordRevisionEvent.setText(word.getText());
        wordRevisionEvent.setPhonetics(word.getPhonetics());
        if (StringUtils.isNotBlank(request.getParameter("comment"))) {
            wordRevisionEvent.setComment(request.getParameter("comment"));
        }
        wordRevisionEventDao.create(wordRevisionEvent);
        // Delete syllables that are actual words
        Syllable syllable = syllableDao.readByText(contributor.getLocale(), word.getText());
        if (syllable != null) {
            syllableDao.delete(syllable);
        }
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated a Word:\n" + "• Language: \"" + word.getLocale().getLanguage() + "\"\n" + "• Text: \"" + word.getText() + "\"\n" + "• Phonetics (IPA): /" + word.getPhonetics() + "/\n" + "• Word type: " + word.getWordType() + "\n" + "• Spelling consistency: " + word.getSpellingConsistency() + "\n" + "• Comment: \"" + wordRevisionEvent.getComment() + "\"\n" + "See ") + "http://elimu.ai/content/word/edit/" + word.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/word/list#" + word.getId();
    }
}
Also used : Word(ai.elimu.model.content.Word) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) WordRevisionEvent(ai.elimu.model.contributor.WordRevisionEvent) Audio(ai.elimu.model.content.multimedia.Audio) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Word

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

the class WordListController 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 Words
    List<Word> wordsGenerated = generateWords(contributor.getLocale());
    for (Word word : wordsGenerated) {
        Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
        if (existingWord == null) {
            wordDao.create(word);
        }
    }
    List<Word> words = wordDao.readAllOrderedByUsage(contributor.getLocale());
    model.addAttribute("words", words);
    int maxUsageCount = 0;
    for (Word word : words) {
        if (word.getUsageCount() > maxUsageCount) {
            maxUsageCount = word.getUsageCount();
        }
    }
    model.addAttribute("maxUsageCount", maxUsageCount);
    return "content/word/list";
}
Also used : Word(ai.elimu.model.content.Word) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with Word

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

the class StringToWordConverter method convert.

/**
 * Convert Word id to Word entity
 */
public Word convert(String id) {
    if (StringUtils.isBlank(id)) {
        return null;
    } else {
        Long wordId = Long.parseLong(id);
        Word word = wordDao.read(wordId);
        return word;
    }
}
Also used : Word(ai.elimu.model.content.Word)

Aggregations

Word (ai.elimu.model.content.Word)35 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 Number (ai.elimu.model.content.Number)14 Contributor (ai.elimu.model.Contributor)10 Letter (ai.elimu.model.content.Letter)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Image (ai.elimu.model.content.multimedia.Image)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Allophone (ai.elimu.model.content.Allophone)5 WordGson (ai.elimu.model.gson.content.WordGson)5 Audio (ai.elimu.model.content.multimedia.Audio)4 NumberGson (ai.elimu.model.gson.content.NumberGson)4 HashMap (java.util.HashMap)4 Syllable (ai.elimu.model.content.Syllable)3 Locale (ai.elimu.model.enums.Locale)3 LetterGson (ai.elimu.model.gson.content.LetterGson)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)3 StoryBook (ai.elimu.model.content.StoryBook)2 Video (ai.elimu.model.content.multimedia.Video)2