Search in sources :

Example 1 with StoryBookPeerReviewEvent

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

the class StoryBookPeerReviewsController method handleGetRequest.

/**
 * Get {@link StoryBookContributionEvent}s pending a {@link StoryBookPeerReviewEvent} 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);
    List<StoryBookContributionEvent> allStoryBookContributionEvents = storyBookContributionEventDao.readAllOrderedByTimeDesc();
    logger.info("allStoryBookContributionEvents.size(): " + allStoryBookContributionEvents.size());
    // Get the most recent StoryBookContributionEvent for each StoryBook, including those made by the current Contributor
    List<StoryBookContributionEvent> mostRecentStoryBookContributionEvents = storyBookContributionEventDao.readMostRecentPerStoryBook();
    logger.info("mostRecentStoryBookContributionEvents.size(): " + mostRecentStoryBookContributionEvents.size());
    // For each StoryBookContributionEvent, check if the Contributor has already performed a peer-review.
    // If not, add it to the list of pending peer reviews.
    List<StoryBookContributionEvent> storyBookContributionEventsPendingPeerReview = new ArrayList<>();
    for (StoryBookContributionEvent mostRecentStoryBookContributionEvent : mostRecentStoryBookContributionEvents) {
        // Ignore StoryBookContributionEvents made by the current Contributor
        if (mostRecentStoryBookContributionEvent.getContributor().getId().equals(contributor.getId())) {
            continue;
        }
        // Check if the current Contributor has already peer-reviewed this StoryBook contribution
        List<StoryBookPeerReviewEvent> storyBookPeerReviewEvents = storyBookPeerReviewEventDao.readAll(mostRecentStoryBookContributionEvent, contributor);
        if (storyBookPeerReviewEvents.isEmpty()) {
            storyBookContributionEventsPendingPeerReview.add(mostRecentStoryBookContributionEvent);
        }
    }
    logger.info("storyBookContributionEventsPendingPeerReview.size(): " + storyBookContributionEventsPendingPeerReview.size());
    model.addAttribute("storyBookContributionEventsPendingPeerReview", storyBookContributionEventsPendingPeerReview);
    return "content/storybook/peer-reviews/pending";
}
Also used : StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) ArrayList(java.util.ArrayList) Contributor(ai.elimu.model.contributor.Contributor) StoryBookPeerReviewEvent(ai.elimu.model.contributor.StoryBookPeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StoryBookPeerReviewEvent

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

the class StoryBookPeerReviewEventCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@RequestParam Long storyBookContributionEventId, @RequestParam Boolean approved, @RequestParam(required = false) String comment, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("storyBookContributionEventId: " + storyBookContributionEventId);
    StoryBookContributionEvent storyBookContributionEvent = storyBookContributionEventDao.read(storyBookContributionEventId);
    logger.info("storyBookContributionEvent: " + storyBookContributionEvent);
    // Store the peer review event
    StoryBookPeerReviewEvent storyBookPeerReviewEvent = new StoryBookPeerReviewEvent();
    storyBookPeerReviewEvent.setContributor(contributor);
    storyBookPeerReviewEvent.setStoryBookContributionEvent(storyBookContributionEvent);
    storyBookPeerReviewEvent.setApproved(approved);
    storyBookPeerReviewEvent.setComment(StringUtils.abbreviate(comment, 1000));
    storyBookPeerReviewEvent.setTime(Calendar.getInstance());
    storyBookPeerReviewEvent.setPlatform(Platform.WEBAPP);
    storyBookPeerReviewEventDao.create(storyBookPeerReviewEvent);
    String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/storybook/edit/" + storyBookContributionEvent.getStoryBook().getId();
    String embedThumbnailUrl = null;
    if (storyBookContributionEvent.getStoryBook().getCoverImage() != null) {
        embedThumbnailUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/image/" + storyBookContributionEvent.getStoryBook().getCoverImage().getId() + "_r" + storyBookContributionEvent.getStoryBook().getCoverImage().getRevisionNumber() + "." + storyBookContributionEvent.getStoryBook().getCoverImage().getImageFormat().toString().toLowerCase();
    }
    DiscordHelper.sendChannelMessage("Storybook peer-reviewed: " + contentUrl, "\"" + storyBookContributionEvent.getStoryBook().getTitle() + "\"", "Comment: \"" + storyBookPeerReviewEvent.getComment() + "\"", storyBookPeerReviewEvent.isApproved(), embedThumbnailUrl);
    // Update the storybook's peer review status
    int approvedCount = 0;
    int notApprovedCount = 0;
    for (StoryBookPeerReviewEvent peerReviewEvent : storyBookPeerReviewEventDao.readAll(storyBookContributionEvent)) {
        if (peerReviewEvent.isApproved()) {
            approvedCount++;
        } else {
            notApprovedCount++;
        }
    }
    logger.info("approvedCount: " + approvedCount);
    logger.info("notApprovedCount: " + notApprovedCount);
    StoryBook storyBook = storyBookContributionEvent.getStoryBook();
    if (approvedCount >= notApprovedCount) {
        storyBook.setPeerReviewStatus(PeerReviewStatus.APPROVED);
    } else {
        storyBook.setPeerReviewStatus(PeerReviewStatus.NOT_APPROVED);
    }
    storyBookDao.update(storyBook);
    return "redirect:/content/storybook/edit/" + storyBookContributionEvent.getStoryBook().getId() + "#contribution-events";
}
Also used : StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.contributor.Contributor) StoryBookPeerReviewEvent(ai.elimu.model.contributor.StoryBookPeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.contributor.Contributor)2 StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)2 StoryBookPeerReviewEvent (ai.elimu.model.contributor.StoryBookPeerReviewEvent)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 StoryBook (ai.elimu.model.content.StoryBook)1 ArrayList (java.util.ArrayList)1