use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class LetterSoundCorrespondenceEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpServletRequest request, HttpSession session, @Valid LetterSoundCorrespondence letterSoundCorrespondence, BindingResult result, Model model) {
logger.info("handleSubmit");
// Check if the LetterSoundCorrespondence already exists
LetterSoundCorrespondence existingLetterSoundCorrespondence = letterSoundCorrespondenceDao.read(letterSoundCorrespondence.getLetters(), letterSoundCorrespondence.getSounds());
if ((existingLetterSoundCorrespondence != null) && !existingLetterSoundCorrespondence.getId().equals(letterSoundCorrespondence.getId())) {
result.rejectValue("letters", "NonUnique");
}
if (result.hasErrors()) {
model.addAttribute("letterSoundCorrespondence", letterSoundCorrespondence);
model.addAttribute("timeStart", System.currentTimeMillis());
List<Letter> letters = letterDao.readAllOrdered();
model.addAttribute("letters", letters);
List<Sound> sounds = soundDao.readAllOrdered();
model.addAttribute("sounds", sounds);
model.addAttribute("letterSoundCorrespondenceContributionEvents", letterSoundCorrespondenceContributionEventDao.readAll(letterSoundCorrespondence));
model.addAttribute("letterSoundCorrespondencePeerReviewEvents", letterSoundCorrespondencePeerReviewEventDao.readAll(letterSoundCorrespondence));
return "content/letter-sound-correspondence/edit";
} else {
letterSoundCorrespondence.setTimeLastUpdate(Calendar.getInstance());
letterSoundCorrespondence.setRevisionNumber(letterSoundCorrespondence.getRevisionNumber() + 1);
letterSoundCorrespondenceDao.update(letterSoundCorrespondence);
LetterSoundCorrespondenceContributionEvent letterSoundCorrespondenceContributionEvent = new LetterSoundCorrespondenceContributionEvent();
letterSoundCorrespondenceContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
letterSoundCorrespondenceContributionEvent.setTime(Calendar.getInstance());
letterSoundCorrespondenceContributionEvent.setLetterSoundCorrespondence(letterSoundCorrespondence);
letterSoundCorrespondenceContributionEvent.setRevisionNumber(letterSoundCorrespondence.getRevisionNumber());
letterSoundCorrespondenceContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
letterSoundCorrespondenceContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
letterSoundCorrespondenceContributionEvent.setPlatform(Platform.WEBAPP);
letterSoundCorrespondenceContributionEventDao.create(letterSoundCorrespondenceContributionEvent);
String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/letter-sound-correspondence/edit/" + letterSoundCorrespondence.getId();
DiscordHelper.sendChannelMessage("Letter-sound correspondence edited: " + contentUrl, "\"" + letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"", "Comment: \"" + letterSoundCorrespondenceContributionEvent.getComment() + "\"", null, null);
return "redirect:/content/letter-sound-correspondence/list#" + letterSoundCorrespondence.getId();
}
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class LetterSoundCorrespondenceEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(Model model, @PathVariable Long id) {
logger.info("handleRequest");
LetterSoundCorrespondence letterSoundCorrespondence = letterSoundCorrespondenceDao.read(id);
model.addAttribute("letterSoundCorrespondence", letterSoundCorrespondence);
model.addAttribute("timeStart", System.currentTimeMillis());
List<Letter> letters = letterDao.readAllOrdered();
model.addAttribute("letters", letters);
List<Sound> sounds = soundDao.readAllOrdered();
model.addAttribute("sounds", sounds);
model.addAttribute("letterSoundCorrespondenceContributionEvents", letterSoundCorrespondenceContributionEventDao.readAll(letterSoundCorrespondence));
model.addAttribute("letterSoundCorrespondencePeerReviewEvents", letterSoundCorrespondencePeerReviewEventDao.readAll(letterSoundCorrespondence));
List<Word> words = wordDao.readAllOrderedByUsage();
model.addAttribute("words", words);
return "content/letter-sound-correspondence/edit";
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class SoundCsvExportController method handleRequest.
@RequestMapping(value = "/sounds.csv", method = RequestMethod.GET)
public void handleRequest(HttpServletResponse response, OutputStream outputStream) throws IOException {
logger.info("handleRequest");
List<Sound> sounds = soundDao.readAllOrderedByUsage();
logger.info("sounds.size(): " + sounds.size());
CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader("id", "value_ipa", "value_sampa", "audio_id", "diacritic", "sound_type", "usage_count");
StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
for (Sound sound : sounds) {
Long audioId = null;
if (sound.getAudio() != null) {
audioId = sound.getAudio().getId();
}
csvPrinter.printRecord(sound.getId(), sound.getValueIpa(), sound.getValueSampa(), audioId, sound.isDiacritic(), sound.getSoundType(), sound.getUsageCount());
csvPrinter.flush();
}
String csvFileContent = stringWriter.toString();
response.setContentType("text/csv");
byte[] bytes = csvFileContent.getBytes();
response.setContentLength(bytes.length);
try {
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
logger.error(ex);
}
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class SoundCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpServletRequest request, HttpSession session, @Valid Sound sound, BindingResult result, Model model) {
logger.info("handleSubmit");
if (StringUtils.isNotBlank(sound.getValueIpa())) {
Sound existingSound = soundDao.readByValueIpa(sound.getValueIpa());
if (existingSound != null) {
result.rejectValue("valueIpa", "NonUnique");
}
}
if (StringUtils.isNotBlank(sound.getValueSampa())) {
Sound existingSound = soundDao.readByValueSampa(sound.getValueSampa());
if (existingSound != null) {
result.rejectValue("valueSampa", "NonUnique");
}
}
if (result.hasErrors()) {
model.addAttribute("sound", sound);
model.addAttribute("timeStart", System.currentTimeMillis());
model.addAttribute("soundTypes", SoundType.values());
return "content/sound/create";
} else {
sound.setTimeLastUpdate(Calendar.getInstance());
soundDao.create(sound);
SoundContributionEvent soundContributionEvent = new SoundContributionEvent();
soundContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
soundContributionEvent.setTime(Calendar.getInstance());
soundContributionEvent.setSound(sound);
soundContributionEvent.setRevisionNumber(sound.getRevisionNumber());
soundContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
soundContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
soundContributionEvent.setPlatform(Platform.WEBAPP);
soundContributionEventDao.create(soundContributionEvent);
String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/sound/edit/" + sound.getId();
DiscordHelper.sendChannelMessage("Sound created: " + contentUrl, "/" + soundContributionEvent.getSound().getValueIpa() + "/", "Comment: \"" + soundContributionEvent.getComment() + "\"", null, null);
return "redirect:/content/sound/list#" + sound.getId();
}
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class SoundEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpServletRequest request, HttpSession session, @PathVariable Long id, @Valid Sound sound, BindingResult result, Model model) {
logger.info("handleSubmit");
if (StringUtils.isNotBlank(sound.getValueIpa())) {
Sound existingSound = soundDao.readByValueIpa(sound.getValueIpa());
if ((existingSound != null) && !existingSound.getId().equals(sound.getId())) {
result.rejectValue("valueIpa", "NonUnique");
}
}
if (StringUtils.isNotBlank(sound.getValueSampa())) {
Sound existingSound = soundDao.readByValueSampa(sound.getValueSampa());
if ((existingSound != null) && !existingSound.getId().equals(sound.getId())) {
result.rejectValue("valueSampa", "NonUnique");
}
}
if (result.hasErrors()) {
model.addAttribute("sound", sound);
model.addAttribute("timeStart", System.currentTimeMillis());
model.addAttribute("soundTypes", SoundType.values());
model.addAttribute("soundContributionEvents", soundContributionEventDao.readAll(sound));
return "content/sound/edit";
} else {
sound.setTimeLastUpdate(Calendar.getInstance());
sound.setRevisionNumber(sound.getRevisionNumber() + 1);
soundDao.update(sound);
SoundContributionEvent soundContributionEvent = new SoundContributionEvent();
soundContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
soundContributionEvent.setTime(Calendar.getInstance());
soundContributionEvent.setSound(sound);
soundContributionEvent.setRevisionNumber(sound.getRevisionNumber());
soundContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
soundContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
soundContributionEvent.setPlatform(Platform.WEBAPP);
soundContributionEventDao.create(soundContributionEvent);
String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/sound/edit/" + sound.getId();
DiscordHelper.sendChannelMessage("Sound edited: " + contentUrl, "/" + soundContributionEvent.getSound().getValueIpa() + "/", "Comment: \"" + soundContributionEvent.getComment() + "\"", null, null);
return "redirect:/content/sound/list#" + sound.getId();
}
}
Aggregations