use of ai.elimu.model.contributor.NumberContributionEvent in project webapp by elimu-ai.
the class NumberCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpServletRequest request, HttpSession session, @Valid Number number, BindingResult result, Model model) {
logger.info("handleSubmit");
Number existingNumber = numberDao.readByValue(number.getValue());
if (existingNumber != null) {
result.rejectValue("value", "NonUnique");
}
if (result.hasErrors()) {
model.addAttribute("number", number);
model.addAttribute("timeStart", request.getParameter("timeStart"));
model.addAttribute("words", wordDao.readAllOrdered());
model.addAttribute("emojisByWordId", getEmojisByWordId());
return "content/number/create";
} else {
number.setTimeLastUpdate(Calendar.getInstance());
numberDao.create(number);
NumberContributionEvent numberContributionEvent = new NumberContributionEvent();
numberContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
numberContributionEvent.setTime(Calendar.getInstance());
numberContributionEvent.setNumber(number);
numberContributionEvent.setRevisionNumber(number.getRevisionNumber());
numberContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
numberContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
numberContributionEvent.setPlatform(Platform.WEBAPP);
numberContributionEventDao.create(numberContributionEvent);
String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/number/edit/" + number.getId();
DiscordHelper.sendChannelMessage("Number created: " + contentUrl, String.valueOf(numberContributionEvent.getNumber().getValue()), "Comment: \"" + numberContributionEvent.getComment() + "\"", null, null);
return "redirect:/content/number/list#" + number.getId();
}
}
use of ai.elimu.model.contributor.NumberContributionEvent in project webapp by elimu-ai.
the class NumberPeerReviewEventCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@RequestParam Long numberContributionEventId, @RequestParam Boolean approved, @RequestParam(required = false) String comment, HttpSession session) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
logger.info("numberContributionEventId: " + numberContributionEventId);
NumberContributionEvent numberContributionEvent = numberContributionEventDao.read(numberContributionEventId);
logger.info("numberContributionEvent: " + numberContributionEvent);
// Store the peer review event
NumberPeerReviewEvent numberPeerReviewEvent = new NumberPeerReviewEvent();
numberPeerReviewEvent.setContributor(contributor);
numberPeerReviewEvent.setNumberContributionEvent(numberContributionEvent);
numberPeerReviewEvent.setApproved(approved);
numberPeerReviewEvent.setComment(StringUtils.abbreviate(comment, 1000));
numberPeerReviewEvent.setTime(Calendar.getInstance());
numberPeerReviewEvent.setPlatform(Platform.WEBAPP);
numberPeerReviewEventDao.create(numberPeerReviewEvent);
String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/number/edit/" + numberContributionEvent.getNumber().getId();
DiscordHelper.sendChannelMessage("Number peer-reviewed: " + contentUrl, "\"" + numberContributionEvent.getNumber().getValue() + "\"", "Comment: \"" + numberPeerReviewEvent.getComment() + "\"", numberPeerReviewEvent.isApproved(), null);
// Update the number's peer review status
int approvedCount = 0;
int notApprovedCount = 0;
for (NumberPeerReviewEvent peerReviewEvent : numberPeerReviewEventDao.readAll(numberContributionEvent)) {
if (peerReviewEvent.isApproved()) {
approvedCount++;
} else {
notApprovedCount++;
}
}
logger.info("approvedCount: " + approvedCount);
logger.info("notApprovedCount: " + notApprovedCount);
Number number = numberContributionEvent.getNumber();
if (approvedCount >= notApprovedCount) {
number.setPeerReviewStatus(PeerReviewStatus.APPROVED);
} else {
number.setPeerReviewStatus(PeerReviewStatus.NOT_APPROVED);
}
numberDao.update(number);
return "redirect:/content/number/edit/" + numberContributionEvent.getNumber().getId() + "#contribution-events";
}
Aggregations