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