Search in sources :

Example 16 with Allophone

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

the class AllophoneEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(@PathVariable Long id, @Valid Allophone allophone, BindingResult result, Model model, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isNotBlank(allophone.getValueIpa())) {
        Allophone existingAllophone = allophoneDao.readByValueIpa(allophone.getLocale(), allophone.getValueIpa());
        if ((existingAllophone != null) && !existingAllophone.getId().equals(allophone.getId())) {
            result.rejectValue("valueIpa", "NonUnique");
        }
    }
    if (StringUtils.isNotBlank(allophone.getValueSampa())) {
        Allophone existingAllophone = allophoneDao.readByValueSampa(allophone.getLocale(), allophone.getValueSampa());
        if ((existingAllophone != null) && !existingAllophone.getId().equals(allophone.getId())) {
            result.rejectValue("valueSampa", "NonUnique");
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("allophone", allophone);
        model.addAttribute("soundTypes", SoundType.values());
        return "content/allophone/edit";
    } else {
        allophone.setTimeLastUpdate(Calendar.getInstance());
        allophone.setRevisionNumber(allophone.getRevisionNumber() + 1);
        allophoneDao.update(allophone);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an Allophone:\n" + "• Language: \"" + allophone.getLocale().getLanguage() + "\"\n" + "• IPA: /" + allophone.getValueIpa() + "/\n" + "• X-SAMPA: \"" + allophone.getValueSampa() + "\"\n" + "• Sound type: \"" + allophone.getSoundType() + "\"\n" + "See ") + "http://elimu.ai/content/allophone/edit/" + allophone.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/allophone/list#" + allophone.getId();
    }
}
Also used : Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Allophone

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

the class AllophoneListController method generateAllophones.

// TODO: add SoundType to each Allophone
private List<Allophone> generateAllophones(Locale locale) {
    List<Allophone> allophones = new ArrayList<>();
    String[][] allophonesArray = null;
    if (locale == Locale.AR) {
        allophonesArray = allophonesArrayAR;
    } else if (locale == Locale.EN) {
        allophonesArray = allophonesArrayEN;
    } else if (locale == Locale.ES) {
        allophonesArray = allophonesArrayES;
    } else if (locale == Locale.SW) {
        allophonesArray = allophonesArraySW;
    }
    for (String[] allophoneRow : allophonesArray) {
        Allophone allophone = new Allophone();
        allophone.setLocale(locale);
        allophone.setTimeLastUpdate(Calendar.getInstance());
        allophone.setValueIpa(allophoneRow[0]);
        allophone.setValueSampa(allophoneRow[1]);
        allophone.setUsageCount(Integer.valueOf(allophoneRow[2]));
        allophones.add(allophone);
    }
    return allophones;
}
Also used : Allophone(ai.elimu.model.content.Allophone) ArrayList(java.util.ArrayList)

Example 18 with Allophone

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

the class LetterCreateController method handleSubmit.

@RequestMapping(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) {
        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/create";
    } else {
        letter.setTimeLastUpdate(Calendar.getInstance());
        letterDao.create(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 19 with Allophone

use of ai.elimu.model.content.Allophone 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 20 with Allophone

use of ai.elimu.model.content.Allophone 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)

Aggregations

Allophone (ai.elimu.model.content.Allophone)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 Contributor (ai.elimu.model.Contributor)11 Word (ai.elimu.model.content.Word)5 ArrayList (java.util.ArrayList)5 Letter (ai.elimu.model.content.Letter)4 AllophoneGson (ai.elimu.model.gson.content.AllophoneGson)4 Locale (ai.elimu.model.enums.Locale)3 Syllable (ai.elimu.model.content.Syllable)2 Audio (ai.elimu.model.content.multimedia.Audio)2 Image (ai.elimu.model.content.multimedia.Image)2 WordRevisionEvent (ai.elimu.model.contributor.WordRevisionEvent)2 Test (org.junit.Test)2 LetterGson (ai.elimu.model.gson.content.LetterGson)1 SyllableGson (ai.elimu.model.gson.content.SyllableGson)1 WordGson (ai.elimu.model.gson.content.WordGson)1 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1