Search in sources :

Example 1 with NumberContributionEvent

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";
}
Also used : HashMap(java.util.HashMap) Contributor(ai.elimu.model.contributor.Contributor) StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) NumberContributionEvent(ai.elimu.model.contributor.NumberContributionEvent) AudioContributionEvent(ai.elimu.model.contributor.AudioContributionEvent) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NumberContributionEvent

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";
}
Also used : NumberContributionEvent(ai.elimu.model.contributor.NumberContributionEvent) ArrayList(java.util.ArrayList) Contributor(ai.elimu.model.contributor.Contributor) NumberPeerReviewEvent(ai.elimu.model.contributor.NumberPeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with NumberContributionEvent

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();
    }
}
Also used : Number(ai.elimu.model.content.Number) NumberContributionEvent(ai.elimu.model.contributor.NumberContributionEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with NumberContributionEvent

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";
}
Also used : Number(ai.elimu.model.content.Number) NumberContributionEvent(ai.elimu.model.contributor.NumberContributionEvent) Contributor(ai.elimu.model.contributor.Contributor) NumberPeerReviewEvent(ai.elimu.model.contributor.NumberPeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NumberContributionEvent

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();
    }
}
Also used : Number(ai.elimu.model.content.Number) NumberContributionEvent(ai.elimu.model.contributor.NumberContributionEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NumberContributionEvent (ai.elimu.model.contributor.NumberContributionEvent)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Contributor (ai.elimu.model.contributor.Contributor)5 Number (ai.elimu.model.content.Number)4 StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)3 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)3 NumberPeerReviewEvent (ai.elimu.model.contributor.NumberPeerReviewEvent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 StoryBookLearningEvent (ai.elimu.model.analytics.StoryBookLearningEvent)1 Emoji (ai.elimu.model.content.Emoji)1 Letter (ai.elimu.model.content.Letter)1 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)1 Sound (ai.elimu.model.content.Sound)1 StoryBook (ai.elimu.model.content.StoryBook)1 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)1 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)1 Word (ai.elimu.model.content.Word)1 AudioContributionEvent (ai.elimu.model.contributor.AudioContributionEvent)1 LetterContributionEvent (ai.elimu.model.contributor.LetterContributionEvent)1