Search in sources :

Example 6 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 7 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)

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