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();
}
}
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;
}
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();
}
}
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";
}
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();
}
}
Aggregations