use of ai.elimu.model.contributor.SoundContributionEvent 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.contributor.SoundContributionEvent 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