use of ai.elimu.model.Contributor 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();
}
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class NumberListController 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 Numbers
List<Number> numbersGenerated = generateNumbers(contributor.getLocale());
for (Number number : numbersGenerated) {
Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
if (existingNumber == null) {
numberDao.create(number);
}
}
List<Number> numbers = numberDao.readAllOrdered(contributor.getLocale());
model.addAttribute("numbers", numbers);
return "content/number/list";
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class StoryBookCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook storyBook = new StoryBook();
model.addAttribute("storyBook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
return "content/storybook/create";
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class StoryBookCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid StoryBook storyBook, BindingResult result, Model model) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook existingStoryBook = storybookDao.readByTitle(storyBook.getLocale(), storyBook.getTitle());
if (existingStoryBook != null) {
result.rejectValue("title", "NonUnique");
}
List<String> paragraphs = storyBook.getParagraphs();
logger.info("paragraphs: " + paragraphs);
if (result.hasErrors()) {
model.addAttribute("storybook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
return "content/storybook/create";
} else {
storyBook.setTimeLastUpdate(Calendar.getInstance());
storybookDao.create(storyBook);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new StoryBook:\n" + "• Language: \"" + storyBook.getLocale().getLanguage() + "\"\n" + "• Title: \"" + storyBook.getTitle() + "\"\n" + "• Grade level: " + storyBook.getGradeLevel() + "\n" + "• Paragraphs: " + storyBook.getParagraphs() + "\n" + "See ") + "http://elimu.ai/content/storybook/edit/" + storyBook.getId();
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
}
return "redirect:/content/storybook/list#" + storyBook.getId();
}
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class SyllableListController 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 Syllables
List<Syllable> syllablesGenerated = generateSyllables(contributor.getLocale());
for (Syllable syllable : syllablesGenerated) {
logger.info("syllable.getText(): " + syllable.getText());
Syllable existingSyllable = syllableDao.readByText(syllable.getLocale(), syllable.getText());
if (existingSyllable == null) {
syllableDao.create(syllable);
}
}
List<Syllable> syllables = syllableDao.readAllOrdered(contributor.getLocale());
logger.info("syllables.size(): " + syllables.size());
model.addAttribute("syllables", syllables);
return "content/syllable/list";
}
Aggregations