use of ai.elimu.model.Contributor 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.Contributor 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();
}
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class LetterListController 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 Letters
List<Letter> lettersGenerated = generateLetters(contributor.getLocale());
for (Letter letter : lettersGenerated) {
logger.info("letter.getText(): " + letter.getText());
Letter existingLetter = letterDao.readByText(letter.getLocale(), letter.getText());
if (existingLetter == null) {
letterDao.create(letter);
}
}
List<Letter> letters = letterDao.readAllOrdered(contributor.getLocale());
model.addAttribute("letters", letters);
int maxUsageCount = 0;
for (Letter letter : letters) {
if (letter.getUsageCount() > maxUsageCount) {
maxUsageCount = letter.getUsageCount();
}
}
model.addAttribute("maxUsageCount", maxUsageCount);
return "content/letter/list";
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class AudioCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, /*@Valid*/
Audio audio, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
if (StringUtils.isBlank(audio.getTranscription())) {
result.rejectValue("transcription", "NotNull");
} else {
Audio existingAudio = audioDao.read(audio.getTranscription(), audio.getLocale());
if (existingAudio != null) {
result.rejectValue("transcription", "NonUnique");
}
}
try {
byte[] bytes = multipartFile.getBytes();
if (multipartFile.isEmpty() || (bytes == null) || (bytes.length == 0)) {
result.rejectValue("bytes", "NotNull");
} else {
String originalFileName = multipartFile.getOriginalFilename();
logger.info("originalFileName: " + originalFileName);
if (originalFileName.toLowerCase().endsWith(".mp3")) {
audio.setAudioFormat(AudioFormat.MP3);
} else if (originalFileName.toLowerCase().endsWith(".ogg")) {
audio.setAudioFormat(AudioFormat.OGG);
} else if (originalFileName.toLowerCase().endsWith(".wav")) {
audio.setAudioFormat(AudioFormat.WAV);
} else {
result.rejectValue("bytes", "typeMismatch");
}
if (audio.getAudioFormat() != null) {
String contentType = multipartFile.getContentType();
logger.info("contentType: " + contentType);
audio.setContentType(contentType);
audio.setBytes(bytes);
// TODO: convert to a default audio format?
}
}
} catch (IOException e) {
logger.error(e);
}
if (result.hasErrors()) {
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
return "content/multimedia/audio/create";
} else {
audio.setTranscription(audio.getTranscription().toLowerCase());
audio.setTimeLastUpdate(Calendar.getInstance());
audioDao.create(audio);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new Audio:\n" + "• Language: \"" + audio.getLocale().getLanguage() + "\"\n" + "• Transcription: \"" + audio.getTranscription() + "\"\n" + "See ") + "http://elimu.ai/content/multimedia/audio/edit/" + audio.getId();
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
}
return "redirect:/content/multimedia/audio/list#" + audio.getId();
}
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class AudioEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, Audio audio, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
if (StringUtils.isBlank(audio.getTranscription())) {
result.rejectValue("transcription", "NotNull");
} else {
Audio existingAudio = audioDao.read(audio.getTranscription(), audio.getLocale());
if ((existingAudio != null) && !existingAudio.getId().equals(audio.getId())) {
result.rejectValue("transcription", "NonUnique");
}
}
try {
byte[] bytes = multipartFile.getBytes();
if (multipartFile.isEmpty() || (bytes == null) || (bytes.length == 0)) {
result.rejectValue("bytes", "NotNull");
} else {
String originalFileName = multipartFile.getOriginalFilename();
logger.info("originalFileName: " + originalFileName);
if (originalFileName.toLowerCase().endsWith(".mp3")) {
audio.setAudioFormat(AudioFormat.MP3);
} else if (originalFileName.toLowerCase().endsWith(".ogg")) {
audio.setAudioFormat(AudioFormat.OGG);
} else if (originalFileName.toLowerCase().endsWith(".wav")) {
audio.setAudioFormat(AudioFormat.WAV);
} else {
result.rejectValue("bytes", "typeMismatch");
}
if (audio.getAudioFormat() != null) {
String contentType = multipartFile.getContentType();
logger.info("contentType: " + contentType);
audio.setContentType(contentType);
audio.setBytes(bytes);
// TODO: convert to a default audio format?
}
}
} catch (IOException e) {
logger.error(e);
}
if (result.hasErrors()) {
model.addAttribute("audio", audio);
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
return "content/multimedia/audio/edit";
} else {
audio.setTranscription(audio.getTranscription().toLowerCase());
audio.setTimeLastUpdate(Calendar.getInstance());
audio.setRevisionNumber(audio.getRevisionNumber() + 1);
audioDao.update(audio);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just edited an Audio:\n" + "• Language: \"" + audio.getLocale().getLanguage() + "\"\n" + "• Transcription: \"" + audio.getTranscription() + "\"\n" + "• Revision number: #" + audio.getRevisionNumber() + "\n" + "See ") + "http://elimu.ai/content/multimedia/audio/edit/" + audio.getId();
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
}
return "redirect:/content/multimedia/audio/list#" + audio.getId();
}
}
Aggregations