Search in sources :

Example 1 with LetterSoundCorrespondencePeerReviewEvent

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

the class LetterSoundCorrespondencePeerReviewsController method handleGetRequest.

/**
 * Get {@link LetterSoundCorrespondenceContributionEvent}s pending a {@link LetterSoundCorrespondencePeerReviewEvent} 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 LetterSoundCorrespondenceContributionEvent for each LetterSoundCorrespondence, including those made by the current Contributor
    List<LetterSoundCorrespondenceContributionEvent> mostRecentLetterSoundCorrespondenceContributionEvents = letterSoundCorrespondenceContributionEventDao.readMostRecentPerLetterSoundCorrespondence();
    logger.info("mostRecentLetterSoundCorrespondenceContributionEvents.size(): " + mostRecentLetterSoundCorrespondenceContributionEvents.size());
    // For each LetterSoundCorrespondenceContributionEvent, check if the Contributor has already performed a peer-review.
    // If not, add it to the list of pending peer reviews.
    List<LetterSoundCorrespondenceContributionEvent> letterSoundCorrespondenceContributionEventsPendingPeerReview = new ArrayList<>();
    for (LetterSoundCorrespondenceContributionEvent mostRecentLetterSoundCorrespondenceContributionEvent : mostRecentLetterSoundCorrespondenceContributionEvents) {
        // Ignore LetterSoundCorrespondenceContributionEvents made by the current Contributor
        if (mostRecentLetterSoundCorrespondenceContributionEvent.getContributor().getId().equals(contributor.getId())) {
            continue;
        }
        // Check if the current Contributor has already peer-reviewed this LetterSoundCorrespondence contribution
        List<LetterSoundCorrespondencePeerReviewEvent> letterSoundCorrespondencePeerReviewEvents = letterSoundCorrespondencePeerReviewEventDao.readAll(mostRecentLetterSoundCorrespondenceContributionEvent, contributor);
        if (letterSoundCorrespondencePeerReviewEvents.isEmpty()) {
            letterSoundCorrespondenceContributionEventsPendingPeerReview.add(mostRecentLetterSoundCorrespondenceContributionEvent);
        }
    }
    logger.info("letterSoundCorrespondenceContributionEventsPendingPeerReview.size(): " + letterSoundCorrespondenceContributionEventsPendingPeerReview.size());
    model.addAttribute("letterSoundCorrespondenceContributionEventsPendingPeerReview", letterSoundCorrespondenceContributionEventsPendingPeerReview);
    return "content/letter-sound-correspondence/peer-reviews/pending";
}
Also used : LetterSoundCorrespondenceContributionEvent(ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent) ArrayList(java.util.ArrayList) Contributor(ai.elimu.model.contributor.Contributor) LetterSoundCorrespondencePeerReviewEvent(ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LetterSoundCorrespondencePeerReviewEvent

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

the class LetterSoundCorrespondencePeerReviewEventCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@RequestParam Long letterSoundCorrespondenceContributionEventId, @RequestParam Boolean approved, @RequestParam(required = false) String comment, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("letterSoundCorrespondenceContributionEventId: " + letterSoundCorrespondenceContributionEventId);
    LetterSoundCorrespondenceContributionEvent letterSoundCorrespondenceContributionEvent = letterSoundCorrespondenceContributionEventDao.read(letterSoundCorrespondenceContributionEventId);
    logger.info("letterSoundCorrespondenceContributionEvent: " + letterSoundCorrespondenceContributionEvent);
    // Store the peer review event
    LetterSoundCorrespondencePeerReviewEvent letterSoundCorrespondencePeerReviewEvent = new LetterSoundCorrespondencePeerReviewEvent();
    letterSoundCorrespondencePeerReviewEvent.setContributor(contributor);
    letterSoundCorrespondencePeerReviewEvent.setLetterSoundCorrespondenceContributionEvent(letterSoundCorrespondenceContributionEvent);
    letterSoundCorrespondencePeerReviewEvent.setApproved(approved);
    letterSoundCorrespondencePeerReviewEvent.setComment(StringUtils.abbreviate(comment, 1000));
    letterSoundCorrespondencePeerReviewEvent.setTime(Calendar.getInstance());
    letterSoundCorrespondencePeerReviewEvent.setPlatform(Platform.WEBAPP);
    letterSoundCorrespondencePeerReviewEventDao.create(letterSoundCorrespondencePeerReviewEvent);
    String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/letterSoundCorrespondence/edit/" + letterSoundCorrespondenceContributionEvent.getLetterSoundCorrespondence().getId();
    DiscordHelper.sendChannelMessage("LetterSoundCorrespondence peer-reviewed: " + contentUrl, "\"" + letterSoundCorrespondenceContributionEvent.getLetterSoundCorrespondence().getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"", "Comment: \"" + letterSoundCorrespondencePeerReviewEvent.getComment() + "\"", letterSoundCorrespondencePeerReviewEvent.isApproved(), null);
    // Update the letterSoundCorrespondence's peer review status
    int approvedCount = 0;
    int notApprovedCount = 0;
    for (LetterSoundCorrespondencePeerReviewEvent peerReviewEvent : letterSoundCorrespondencePeerReviewEventDao.readAll(letterSoundCorrespondenceContributionEvent)) {
        if (peerReviewEvent.isApproved()) {
            approvedCount++;
        } else {
            notApprovedCount++;
        }
    }
    logger.info("approvedCount: " + approvedCount);
    logger.info("notApprovedCount: " + notApprovedCount);
    LetterSoundCorrespondence letterSoundCorrespondence = letterSoundCorrespondenceContributionEvent.getLetterSoundCorrespondence();
    if (approvedCount >= notApprovedCount) {
        letterSoundCorrespondence.setPeerReviewStatus(PeerReviewStatus.APPROVED);
    } else {
        letterSoundCorrespondence.setPeerReviewStatus(PeerReviewStatus.NOT_APPROVED);
    }
    letterSoundCorrespondenceDao.update(letterSoundCorrespondence);
    return "redirect:/content/letter-sound-correspondence/edit/" + letterSoundCorrespondenceContributionEvent.getLetterSoundCorrespondence().getId() + "#contribution-events";
}
Also used : Letter(ai.elimu.model.content.Letter) LetterSoundCorrespondenceContributionEvent(ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent) Contributor(ai.elimu.model.contributor.Contributor) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) LetterSoundCorrespondencePeerReviewEvent(ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.contributor.Contributor)2 LetterSoundCorrespondenceContributionEvent (ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent)2 LetterSoundCorrespondencePeerReviewEvent (ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Letter (ai.elimu.model.content.Letter)1 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)1 ArrayList (java.util.ArrayList)1