Search in sources :

Example 1 with WordPeerReviewEvent

use of ai.elimu.model.contributor.WordPeerReviewEvent in project webapp by elimu-ai.

the class WordPeerReviewsController method handleGetRequest.

/**
 * Get {@link WordContributionEvent}s pending a {@link WordPeerReviewEvent} 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 WordContributionEvent for each Word, including those made by the current Contributor
    List<WordContributionEvent> mostRecentWordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
    logger.info("mostRecentWordContributionEvents.size(): " + mostRecentWordContributionEvents.size());
    // For each WordContributionEvent, check if the Contributor has already performed a peer-review.
    // If not, add it to the list of pending peer reviews.
    List<WordContributionEvent> wordContributionEventsPendingPeerReview = new ArrayList<>();
    for (WordContributionEvent mostRecentWordContributionEvent : mostRecentWordContributionEvents) {
        // Ignore WordContributionEvents made by the current Contributor
        if (mostRecentWordContributionEvent.getContributor().getId().equals(contributor.getId())) {
            continue;
        }
        // Check if the current Contributor has already peer-reviewed this Word contribution
        List<WordPeerReviewEvent> wordPeerReviewEvents = wordPeerReviewEventDao.readAll(mostRecentWordContributionEvent, contributor);
        if (wordPeerReviewEvents.isEmpty()) {
            wordContributionEventsPendingPeerReview.add(mostRecentWordContributionEvent);
        }
    }
    logger.info("wordContributionEventsPendingPeerReview.size(): " + wordContributionEventsPendingPeerReview.size());
    model.addAttribute("wordContributionEventsPendingPeerReview", wordContributionEventsPendingPeerReview);
    model.addAttribute("emojisByWordId", getEmojisByWordId());
    return "content/word/peer-reviews/pending";
}
Also used : WordPeerReviewEvent(ai.elimu.model.contributor.WordPeerReviewEvent) ArrayList(java.util.ArrayList) Contributor(ai.elimu.model.contributor.Contributor) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with WordPeerReviewEvent

use of ai.elimu.model.contributor.WordPeerReviewEvent in project webapp by elimu-ai.

the class WordPeerReviewEventCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@RequestParam Long wordContributionEventId, @RequestParam Boolean approved, @RequestParam(required = false) String comment, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("wordContributionEventId: " + wordContributionEventId);
    WordContributionEvent wordContributionEvent = wordContributionEventDao.read(wordContributionEventId);
    logger.info("wordContributionEvent: " + wordContributionEvent);
    // Store the peer review event
    WordPeerReviewEvent wordPeerReviewEvent = new WordPeerReviewEvent();
    wordPeerReviewEvent.setContributor(contributor);
    wordPeerReviewEvent.setWordContributionEvent(wordContributionEvent);
    wordPeerReviewEvent.setApproved(approved);
    wordPeerReviewEvent.setComment(StringUtils.abbreviate(comment, 1000));
    wordPeerReviewEvent.setTime(Calendar.getInstance());
    wordPeerReviewEvent.setPlatform(Platform.WEBAPP);
    wordPeerReviewEventDao.create(wordPeerReviewEvent);
    String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/word/edit/" + wordContributionEvent.getWord().getId();
    DiscordHelper.sendChannelMessage("Word peer-reviewed: " + contentUrl, "\"" + wordContributionEvent.getWord().getText() + "\"", "Comment: \"" + wordPeerReviewEvent.getComment() + "\"", wordPeerReviewEvent.isApproved(), null);
    // Update the word's peer review status
    int approvedCount = 0;
    int notApprovedCount = 0;
    for (WordPeerReviewEvent peerReviewEvent : wordPeerReviewEventDao.readAll(wordContributionEvent)) {
        if (peerReviewEvent.isApproved()) {
            approvedCount++;
        } else {
            notApprovedCount++;
        }
    }
    logger.info("approvedCount: " + approvedCount);
    logger.info("notApprovedCount: " + notApprovedCount);
    Word word = wordContributionEvent.getWord();
    if (approvedCount >= notApprovedCount) {
        word.setPeerReviewStatus(PeerReviewStatus.APPROVED);
    } else {
        word.setPeerReviewStatus(PeerReviewStatus.NOT_APPROVED);
    }
    wordDao.update(word);
    return "redirect:/content/word/edit/" + wordContributionEvent.getWord().getId() + "#contribution-events";
}
Also used : Word(ai.elimu.model.content.Word) WordPeerReviewEvent(ai.elimu.model.contributor.WordPeerReviewEvent) Contributor(ai.elimu.model.contributor.Contributor) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.contributor.Contributor)2 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)2 WordPeerReviewEvent (ai.elimu.model.contributor.WordPeerReviewEvent)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Word (ai.elimu.model.content.Word)1 ArrayList (java.util.ArrayList)1