Search in sources :

Example 6 with Contributor

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

the class AudioPeerReviewEventCreateController method handleSubmit.

/**
 * Note: The logic in this method is similar to the one used at {@link AudioPeerReviewsRestController#uploadAudioPeerReview}
 */
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@RequestParam Long audioContributionEventId, @RequestParam Boolean approved, @RequestParam(required = false) String comment, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("audioContributionEventId: " + audioContributionEventId);
    AudioContributionEvent audioContributionEvent = audioContributionEventDao.read(audioContributionEventId);
    logger.info("audioContributionEvent: " + audioContributionEvent);
    // Store the peer review event
    AudioPeerReviewEvent audioPeerReviewEvent = new AudioPeerReviewEvent();
    audioPeerReviewEvent.setContributor(contributor);
    audioPeerReviewEvent.setAudioContributionEvent(audioContributionEvent);
    audioPeerReviewEvent.setApproved(approved);
    audioPeerReviewEvent.setComment(StringUtils.abbreviate(comment, 1000));
    audioPeerReviewEvent.setTime(Calendar.getInstance());
    audioPeerReviewEvent.setPlatform(Platform.WEBAPP);
    audioPeerReviewEventDao.create(audioPeerReviewEvent);
    String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/multimedia/audio/edit/" + audioContributionEvent.getAudio().getId();
    DiscordHelper.sendChannelMessage("Audio peer-reviewed: " + contentUrl, "\"" + audioContributionEvent.getAudio().getTitle() + "\"", "Comment: \"" + audioPeerReviewEvent.getComment() + "\"", audioPeerReviewEvent.isApproved(), null);
    // Update the audio's peer review status
    int approvedCount = 0;
    int notApprovedCount = 0;
    for (AudioPeerReviewEvent peerReviewEvent : audioPeerReviewEventDao.readAll(audioContributionEvent)) {
        if (peerReviewEvent.isApproved()) {
            approvedCount++;
        } else {
            notApprovedCount++;
        }
    }
    logger.info("approvedCount: " + approvedCount);
    logger.info("notApprovedCount: " + notApprovedCount);
    Audio audio = audioContributionEvent.getAudio();
    if (approvedCount >= notApprovedCount) {
        audio.setPeerReviewStatus(PeerReviewStatus.APPROVED);
    } else {
        audio.setPeerReviewStatus(PeerReviewStatus.NOT_APPROVED);
    }
    audioDao.update(audio);
    return "redirect:/content/multimedia/audio/edit/" + audioContributionEvent.getAudio().getId() + "#contribution-events";
}
Also used : Contributor(ai.elimu.model.contributor.Contributor) AudioContributionEvent(ai.elimu.model.contributor.AudioContributionEvent) Audio(ai.elimu.model.content.multimedia.Audio) AudioPeerReviewEvent(ai.elimu.model.contributor.AudioPeerReviewEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Contributor

use of ai.elimu.model.contributor.Contributor 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)

Example 8 with Contributor

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

the class SignOnControllerSelenium method handleRequest.

@RequestMapping(value = "/sign-on/test/role-{role}", method = RequestMethod.GET)
public String handleRequest(@PathVariable Role role, HttpServletRequest request, Model model) {
    logger.info("handleRequest");
    if (EnvironmentContextLoaderListener.env == Environment.PROD) {
        return "redirect:/sign-on";
    }
    logger.info("role: " + role);
    Contributor contributor = new Contributor();
    contributor.setEmail("info+role-" + role + "@elimu.ai");
    contributor.setRoles(new HashSet<>(Arrays.asList(role)));
    contributor.setRegistrationTime(Calendar.getInstance());
    contributor.setFirstName("TestRole");
    contributor.setLastName(role.toString());
    contributor.setMotivation("Regression testing as " + role);
    Contributor existingContributor = contributorDao.read(contributor.getEmail());
    logger.info("existingContributor: " + existingContributor);
    if (existingContributor != null) {
        contributor = existingContributor;
    } else {
        contributorDao.create(contributor);
        logger.info("Contributor " + contributor.getEmail() + " was created at " + request.getServerName());
    }
    // Authenticate
    new CustomAuthenticationManager().authenticateUser(contributor);
    // Add Contributor object to session
    request.getSession().setAttribute("contributor", contributor);
    return "redirect:/content";
}
Also used : Contributor(ai.elimu.model.contributor.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Contributor

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

the class AddEmailController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @RequestParam String email, Model model) {
    logger.info("handleSubmit");
    if (!EmailValidator.getInstance().isValid(email)) {
        // TODO: display error message
        return "content/contributor/add-email";
    }
    // Look for existing Contributor with matching e-mail address
    Contributor existingContributor = contributorDao.read(email);
    if (existingContributor != null) {
        // TODO: display error message
        return "content/contributor/add-email";
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    contributor.setEmail(email);
    contributorDao.create(contributor);
    session.setAttribute("contributor", contributor);
    return "redirect:/content";
}
Also used : Contributor(ai.elimu.model.contributor.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Contributor

use of ai.elimu.model.contributor.Contributor 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)

Aggregations

Contributor (ai.elimu.model.contributor.Contributor)38 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)10 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)8 ArrayList (java.util.ArrayList)8 JSONObject (org.json.JSONObject)8 StoryBook (ai.elimu.model.content.StoryBook)7 Word (ai.elimu.model.content.Word)7 Audio (ai.elimu.model.content.multimedia.Audio)6 AudioContributionEvent (ai.elimu.model.contributor.AudioContributionEvent)6 NumberContributionEvent (ai.elimu.model.contributor.NumberContributionEvent)5 HashMap (java.util.HashMap)5 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)4 Gson (com.google.gson.Gson)4 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)3 AudioPeerReviewEvent (ai.elimu.model.contributor.AudioPeerReviewEvent)3 LetterSoundCorrespondenceContributionEvent (ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Letter (ai.elimu.model.content.Letter)2