Search in sources :

Example 11 with Word

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

the class VideoEditController method handleRemoveContentLabelRequest.

@RequestMapping(value = "/{id}/remove-content-label", method = RequestMethod.POST)
@ResponseBody
public String handleRemoveContentLabelRequest(HttpServletRequest request, @PathVariable Long id) {
    logger.info("handleRemoveContentLabelRequest");
    logger.info("id: " + id);
    Video video = videoDao.read(id);
    String letterIdParameter = request.getParameter("letterId");
    logger.info("letterIdParameter: " + letterIdParameter);
    if (StringUtils.isNotBlank(letterIdParameter)) {
        Long letterId = Long.valueOf(letterIdParameter);
        Letter letter = letterDao.read(letterId);
        Set<Letter> letters = video.getLetters();
        Iterator<Letter> iterator = letters.iterator();
        while (iterator.hasNext()) {
            Letter existingLetter = iterator.next();
            if (existingLetter.getId().equals(letter.getId())) {
                iterator.remove();
            }
        }
        video.setRevisionNumber(video.getRevisionNumber() + 1);
        videoDao.update(video);
    }
    String numberIdParameter = request.getParameter("numberId");
    logger.info("numberIdParameter: " + numberIdParameter);
    if (StringUtils.isNotBlank(numberIdParameter)) {
        Long numberId = Long.valueOf(numberIdParameter);
        Number number = numberDao.read(numberId);
        Set<Number> numbers = video.getNumbers();
        Iterator<Number> iterator = numbers.iterator();
        while (iterator.hasNext()) {
            Number existingNumber = iterator.next();
            if (existingNumber.getId().equals(number.getId())) {
                iterator.remove();
            }
        }
        video.setRevisionNumber(video.getRevisionNumber() + 1);
        videoDao.update(video);
    }
    String wordIdParameter = request.getParameter("wordId");
    logger.info("wordIdParameter: " + wordIdParameter);
    if (StringUtils.isNotBlank(wordIdParameter)) {
        Long wordId = Long.valueOf(wordIdParameter);
        Word word = wordDao.read(wordId);
        Set<Word> words = video.getWords();
        Iterator<Word> iterator = words.iterator();
        while (iterator.hasNext()) {
            Word existingWord = iterator.next();
            if (existingWord.getId().equals(word.getId())) {
                iterator.remove();
            }
        }
        video.setRevisionNumber(video.getRevisionNumber() + 1);
        videoDao.update(video);
    }
    return "success";
}
Also used : Letter(ai.elimu.model.content.Letter) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) Video(ai.elimu.model.content.multimedia.Video) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with Word

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

the class NumberCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Number number, BindingResult result, Model model) {
    logger.info("handleSubmit");
    if (number.getLocale() == Locale.AR) {
        if (StringUtils.isBlank(number.getSymbol())) {
            result.rejectValue("symbol", "NotNull");
        }
    }
    Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
    if (existingNumber != null) {
        result.rejectValue("value", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (result.hasErrors()) {
        model.addAttribute("number", number);
        List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
        model.addAttribute("words", words);
        return "content/number/create";
    } else {
        number.setTimeLastUpdate(Calendar.getInstance());
        numberDao.create(number);
        return "redirect:/content/number/list#" + number.getId();
    }
}
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 13 with Word

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

the class NumberEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Number number, BindingResult result, Model model) {
    logger.info("handleSubmit");
    if (number.getLocale() == Locale.AR) {
        if (StringUtils.isBlank(number.getSymbol())) {
            result.rejectValue("symbol", "NotNull");
        }
    }
    Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
    if ((existingNumber != null) && !existingNumber.getId().equals(number.getId())) {
        result.rejectValue("value", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (result.hasErrors()) {
        model.addAttribute("number", number);
        List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
        model.addAttribute("words", words);
        return "content/number/edit";
    } else {
        number.setTimeLastUpdate(Calendar.getInstance());
        number.setRevisionNumber(number.getRevisionNumber() + 1);
        numberDao.update(number);
        return "redirect:/content/number/list#" + number.getId();
    }
}
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 14 with Word

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

the class WordCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Word word, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
    if (existingWord != null) {
        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());
        return "content/word/create";
    } else {
        if (!"I".equals(word.getText())) {
            word.setText(word.getText().toLowerCase());
        }
        word.setTimeLastUpdate(Calendar.getInstance());
        wordDao.create(word);
        WordRevisionEvent wordRevisionEvent = new WordRevisionEvent();
        wordRevisionEvent.setContributor(contributor);
        wordRevisionEvent.setCalendar(Calendar.getInstance());
        wordRevisionEvent.setWord(word);
        wordRevisionEvent.setText(word.getText());
        wordRevisionEvent.setPhonetics(word.getPhonetics());
        wordRevisionEventDao.create(wordRevisionEvent);
        // Label Image with Word of matching title
        Image matchingImage = imageDao.read(word.getText(), word.getLocale());
        if (matchingImage != null) {
            Set<Word> labeledWords = matchingImage.getWords();
            if (!labeledWords.contains(word)) {
                labeledWords.add(word);
                matchingImage.setWords(labeledWords);
                imageDao.update(matchingImage);
            }
        }
        // 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 added a new 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" + "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) Image(ai.elimu.model.content.multimedia.Image) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Word

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

the class WordCreateController method handleRequest.

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

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