use of ai.elimu.model.contributor.NumberContributionEvent in project webapp by elimu-ai.
the class MostRecentContributionsController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
logger.info("handleRequest");
List<StoryBookContributionEvent> storyBookContributionEvents = storyBookContributionEventDao.readMostRecent(9);
logger.info("storyBookContributionEvents.size(): " + storyBookContributionEvents.size());
model.addAttribute("storyBookContributionEvents", storyBookContributionEvents);
List<AudioContributionEvent> audioContributionEvents = audioContributionEventDao.readMostRecent(10);
logger.info("audioContributionEvents.size(): " + audioContributionEvents.size());
model.addAttribute("audioContributionEvents", audioContributionEvents);
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecent(10);
logger.info("wordContributionEvents.size(): " + wordContributionEvents.size());
model.addAttribute("wordContributionEvents", wordContributionEvents);
List<NumberContributionEvent> numberContributionEvents = numberContributionEventDao.readMostRecent(10);
logger.info("numberContributionEvents.size(): " + numberContributionEvents.size());
model.addAttribute("numberContributionEvents", numberContributionEvents);
List<Contributor> contributorsWithStoryBookContributions = contributorDao.readAllWithStoryBookContributions();
logger.info("contributorsWithStoryBookContributions.size(): " + contributorsWithStoryBookContributions.size());
model.addAttribute("contributorsWithStoryBookContributions", contributorsWithStoryBookContributions);
Map<Long, Long> storyBookContributionsCountMap = new HashMap<>();
for (Contributor contributor : contributorsWithStoryBookContributions) {
storyBookContributionsCountMap.put(contributor.getId(), storyBookContributionEventDao.readCount(contributor));
}
model.addAttribute("storyBookContributionsCountMap", storyBookContributionsCountMap);
List<Contributor> contributorsWithAudioContributions = contributorDao.readAllWithAudioContributions();
logger.info("contributorsWithAudioContributions.size(): " + contributorsWithAudioContributions.size());
model.addAttribute("contributorsWithAudioContributions", contributorsWithAudioContributions);
Map<Long, Long> audioContributionsCountMap = new HashMap<>();
for (Contributor contributor : contributorsWithAudioContributions) {
audioContributionsCountMap.put(contributor.getId(), audioContributionEventDao.readCount(contributor));
}
model.addAttribute("audioContributionsCountMap", audioContributionsCountMap);
List<Contributor> contributorsWithWordContributions = contributorDao.readAllWithWordContributions();
logger.info("contributorsWithWordContributions.size(): " + contributorsWithWordContributions.size());
model.addAttribute("contributorsWithWordContributions", contributorsWithWordContributions);
Map<Long, Long> wordContributionsCountMap = new HashMap<>();
for (Contributor contributor : contributorsWithWordContributions) {
wordContributionsCountMap.put(contributor.getId(), wordContributionEventDao.readCount(contributor));
}
model.addAttribute("wordContributionsCountMap", wordContributionsCountMap);
List<Contributor> contributorsWithNumberContributions = contributorDao.readAllWithNumberContributions();
logger.info("contributorsWithNumberContributions.size(): " + contributorsWithNumberContributions.size());
model.addAttribute("contributorsWithNumberContributions", contributorsWithNumberContributions);
Map<Long, Long> numberContributionsCountMap = new HashMap<>();
for (Contributor contributor : contributorsWithNumberContributions) {
numberContributionsCountMap.put(contributor.getId(), numberContributionEventDao.readCount(contributor));
}
model.addAttribute("numberContributionsCountMap", numberContributionsCountMap);
return "contributions/most-recent";
}
use of ai.elimu.model.contributor.NumberContributionEvent in project webapp by elimu-ai.
the class NumberPeerReviewsController method handleGetRequest.
/**
* Get {@link NumberContributionEvent}s pending a {@link NumberPeerReviewEvent} for the current {@link Contributor}.
*/
@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpSession session, Model model) {
logger.info("handleGetRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
logger.info("contributor: " + contributor);
// Get the most recent NumberContributionEvent for each Number, including those made by the current Contributor
List<NumberContributionEvent> mostRecentNumberContributionEvents = numberContributionEventDao.readMostRecentPerNumber();
logger.info("mostRecentNumberContributionEvents.size(): " + mostRecentNumberContributionEvents.size());
// For each NumberContributionEvent, check if the Contributor has already performed a peer-review.
// If not, add it to the list of pending peer reviews.
List<NumberContributionEvent> numberContributionEventsPendingPeerReview = new ArrayList<>();
for (NumberContributionEvent mostRecentNumberContributionEvent : mostRecentNumberContributionEvents) {
// Ignore NumberContributionEvents made by the current Contributor
if (mostRecentNumberContributionEvent.getContributor().getId().equals(contributor.getId())) {
continue;
}
// Check if the current Contributor has already peer-reviewed this Number contribution
List<NumberPeerReviewEvent> numberPeerReviewEvents = numberPeerReviewEventDao.readAll(mostRecentNumberContributionEvent, contributor);
if (numberPeerReviewEvents.isEmpty()) {
numberContributionEventsPendingPeerReview.add(mostRecentNumberContributionEvent);
}
}
logger.info("numberContributionEventsPendingPeerReview.size(): " + numberContributionEventsPendingPeerReview.size());
model.addAttribute("numberContributionEventsPendingPeerReview", numberContributionEventsPendingPeerReview);
return "content/number/peer-reviews/pending";
}
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";
}
use of ai.elimu.model.contributor.NumberContributionEvent in project webapp by elimu-ai.
the class NumberEditController method handleSubmit.
@RequestMapping(value = "/{id}", 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) && !existingNumber.getId().equals(number.getId())) {
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());
model.addAttribute("numberContributionEvents", numberContributionEventDao.readAll(number));
model.addAttribute("numberPeerReviewEvents", numberPeerReviewEventDao.readAll(number));
return "content/number/edit";
} else {
number.setTimeLastUpdate(Calendar.getInstance());
number.setRevisionNumber(number.getRevisionNumber() + 1);
numberDao.update(number);
NumberContributionEvent numberContributionEvent = new NumberContributionEvent();
numberContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
numberContributionEvent.setTime(Calendar.getInstance());
numberContributionEvent.setNumber(number);
numberContributionEvent.setRevisionNumber(number.getRevisionNumber());
numberContributionEvent.setComment(request.getParameter("contributionComment"));
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 edited: " + contentUrl, String.valueOf(numberContributionEvent.getNumber().getValue()), "Comment: \"" + numberContributionEvent.getComment() + "\"", null, null);
return "redirect:/content/number/list#" + number.getId();
}
}
Aggregations