Search in sources :

Example 1 with StoryBookContributionEvent

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

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

the class StoryBookParagraphDeleteController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, @PathVariable Long id) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("contributor.getRoles(): " + contributor.getRoles());
    if (!contributor.getRoles().contains(Role.EDITOR)) {
        // TODO: return HttpStatus.FORBIDDEN
        throw new IllegalAccessError("Missing role for access");
    }
    StoryBookParagraph storyBookParagraphToBeDeleted = storyBookParagraphDao.read(id);
    logger.info("storyBookParagraphToBeDeleted: " + storyBookParagraphToBeDeleted);
    logger.info("storyBookParagraphToBeDeleted.getSortOrder(): " + storyBookParagraphToBeDeleted.getSortOrder());
    String paragraphTextBeforeDeletion = storyBookParagraphToBeDeleted.getOriginalText();
    // Delete the paragraph's reference from corresponding audios (if any)
    List<Audio> paragraphAudios = audioDao.readAll(storyBookParagraphToBeDeleted);
    for (Audio paragraphAudio : paragraphAudios) {
        paragraphAudio.setStoryBookParagraph(null);
        audioDao.update(paragraphAudio);
    }
    // Delete the paragraph
    logger.info("Deleting StoryBookParagraph with ID " + storyBookParagraphToBeDeleted.getId());
    storyBookParagraphDao.delete(storyBookParagraphToBeDeleted);
    // Update the storybook's metadata
    StoryBook storyBook = storyBookParagraphToBeDeleted.getStoryBookChapter().getStoryBook();
    storyBook.setTimeLastUpdate(Calendar.getInstance());
    storyBook.setRevisionNumber(storyBook.getRevisionNumber() + 1);
    storyBook.setPeerReviewStatus(PeerReviewStatus.PENDING);
    storyBookDao.update(storyBook);
    // Store contribution event
    StoryBookContributionEvent storyBookContributionEvent = new StoryBookContributionEvent();
    storyBookContributionEvent.setContributor(contributor);
    storyBookContributionEvent.setTime(Calendar.getInstance());
    storyBookContributionEvent.setStoryBook(storyBook);
    storyBookContributionEvent.setRevisionNumber(storyBook.getRevisionNumber());
    storyBookContributionEvent.setComment("Deleted storybook paragraph in chapter " + (storyBookParagraphToBeDeleted.getStoryBookChapter().getSortOrder() + 1) + " (🤖 auto-generated comment)");
    storyBookContributionEvent.setParagraphTextBefore(paragraphTextBeforeDeletion);
    storyBookContributionEvent.setTimeSpentMs(0L);
    storyBookContributionEvent.setPlatform(Platform.WEBAPP);
    storyBookContributionEventDao.create(storyBookContributionEvent);
    String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/storybook/edit/" + storyBook.getId();
    String embedThumbnailUrl = null;
    if (storyBook.getCoverImage() != null) {
        embedThumbnailUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/image/" + storyBook.getCoverImage().getId() + "_r" + storyBook.getCoverImage().getRevisionNumber() + "." + storyBook.getCoverImage().getImageFormat().toString().toLowerCase();
    }
    DiscordHelper.sendChannelMessage("Storybook paragraph deleted: " + contentUrl, "\"" + storyBookContributionEvent.getStoryBook().getTitle() + "\"", "Comment: \"" + storyBookContributionEvent.getComment() + "\"", null, embedThumbnailUrl);
    // Update the sorting order of the remaining paragraphs
    List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookParagraphToBeDeleted.getStoryBookChapter());
    logger.info("storyBookParagraphs.size(): " + storyBookParagraphs.size());
    for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
        logger.info("storyBookParagraph.getId(): " + storyBookParagraph.getId() + ", storyBookParagraph.getSortOrder(): " + storyBookParagraph.getSortOrder());
        if (storyBookParagraph.getSortOrder() > storyBookParagraphToBeDeleted.getSortOrder()) {
            // Reduce sort order by 1
            storyBookParagraph.setSortOrder(storyBookParagraph.getSortOrder() - 1);
            storyBookParagraphDao.update(storyBookParagraph);
            logger.info("storyBookParagraph.getSortOrder() (after update): " + storyBookParagraph.getSortOrder());
        }
    }
    // Refresh the REST API cache
    storyBooksJsonService.refreshStoryBooksJSONArray();
    return "redirect:/content/storybook/edit/" + storyBook.getId() + "#ch-id-" + storyBookParagraphToBeDeleted.getStoryBookChapter().getId();
}
Also used : StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.contributor.Contributor) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with StoryBookContributionEvent

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

the class StoryBookCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@Valid StoryBook storyBook, BindingResult result, Model model, HttpServletRequest request, HttpSession session) {
    logger.info("handleSubmit");
    StoryBook existingStoryBook = storybookDao.readByTitle(storyBook.getTitle());
    if (existingStoryBook != null) {
        result.rejectValue("title", "NonUnique");
    }
    if (result.hasErrors()) {
        model.addAttribute("storybook", storyBook);
        model.addAttribute("timeStart", System.currentTimeMillis());
        model.addAttribute("contentLicenses", ContentLicense.values());
        List<Image> coverImages = imageDao.readAllOrdered();
        model.addAttribute("coverImages", coverImages);
        model.addAttribute("readingLevels", ReadingLevel.values());
        return "content/storybook/create";
    } else {
        storyBook.setTimeLastUpdate(Calendar.getInstance());
        storybookDao.create(storyBook);
        StoryBookContributionEvent storyBookContributionEvent = new StoryBookContributionEvent();
        storyBookContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
        storyBookContributionEvent.setTime(Calendar.getInstance());
        storyBookContributionEvent.setStoryBook(storyBook);
        storyBookContributionEvent.setRevisionNumber(storyBook.getRevisionNumber());
        storyBookContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
        storyBookContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
        storyBookContributionEvent.setPlatform(Platform.WEBAPP);
        storyBookContributionEventDao.create(storyBookContributionEvent);
        String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/storybook/edit/" + storyBook.getId();
        String embedThumbnailUrl = null;
        if (storyBook.getCoverImage() != null) {
            embedThumbnailUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/image/" + storyBook.getCoverImage().getId() + "_r" + storyBook.getCoverImage().getRevisionNumber() + "." + storyBook.getCoverImage().getImageFormat().toString().toLowerCase();
        }
        DiscordHelper.sendChannelMessage("Storybook created: " + contentUrl, "\"" + storyBookContributionEvent.getStoryBook().getTitle() + "\"", "Comment: \"" + storyBookContributionEvent.getComment() + "\"", null, embedThumbnailUrl);
        return "redirect:/content/storybook/list#" + storyBook.getId();
    }
}
Also used : StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) StoryBook(ai.elimu.model.content.StoryBook) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with StoryBookContributionEvent

use of ai.elimu.model.contributor.StoryBookContributionEvent 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 5 with StoryBookContributionEvent

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

the class StoryBookChapterCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long storyBookId, @Valid StoryBookChapter storyBookChapter, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (result.hasErrors()) {
        model.addAttribute("storyBookChapter", storyBookChapter);
        List<Image> images = imageDao.readAllOrdered();
        model.addAttribute("images", images);
        return "content/storybook/chapter/create";
    } else {
        storyBookChapterDao.create(storyBookChapter);
        // Update the storybook's metadata
        StoryBook storyBook = storyBookChapter.getStoryBook();
        storyBook.setTimeLastUpdate(Calendar.getInstance());
        storyBook.setRevisionNumber(storyBook.getRevisionNumber() + 1);
        storyBook.setPeerReviewStatus(PeerReviewStatus.PENDING);
        storyBookDao.update(storyBook);
        // Store contribution event
        StoryBookContributionEvent storyBookContributionEvent = new StoryBookContributionEvent();
        storyBookContributionEvent.setContributor(contributor);
        storyBookContributionEvent.setTime(Calendar.getInstance());
        storyBookContributionEvent.setStoryBook(storyBook);
        storyBookContributionEvent.setRevisionNumber(storyBook.getRevisionNumber());
        storyBookContributionEvent.setComment("Created storybook chapter " + (storyBookChapter.getSortOrder() + 1) + " (🤖 auto-generated comment)");
        storyBookContributionEvent.setTimeSpentMs(0L);
        storyBookContributionEvent.setPlatform(Platform.WEBAPP);
        storyBookContributionEventDao.create(storyBookContributionEvent);
        String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/storybook/edit/" + storyBook.getId();
        String embedThumbnailUrl = null;
        if (storyBook.getCoverImage() != null) {
            embedThumbnailUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/image/" + storyBook.getCoverImage().getId() + "_r" + storyBook.getCoverImage().getRevisionNumber() + "." + storyBook.getCoverImage().getImageFormat().toString().toLowerCase();
        }
        DiscordHelper.sendChannelMessage("Storybook chapter created: " + contentUrl, "\"" + storyBookContributionEvent.getStoryBook().getTitle() + "\"", "Comment: \"" + storyBookContributionEvent.getComment() + "\"", null, embedThumbnailUrl);
        return "redirect:/content/storybook/edit/" + storyBookId + "#ch-id-" + storyBookChapter.getId();
    }
}
Also used : StoryBookContributionEvent(ai.elimu.model.contributor.StoryBookContributionEvent) StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.contributor.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Contributor (ai.elimu.model.contributor.Contributor)10 StoryBook (ai.elimu.model.content.StoryBook)9 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)6 Image (ai.elimu.model.content.multimedia.Image)5 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)4 ArrayList (java.util.ArrayList)4 NumberContributionEvent (ai.elimu.model.contributor.NumberContributionEvent)3 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)3 HashMap (java.util.HashMap)3 Letter (ai.elimu.model.content.Letter)2 Word (ai.elimu.model.content.Word)2 Audio (ai.elimu.model.content.multimedia.Audio)2 StoryBookPeerReviewEvent (ai.elimu.model.contributor.StoryBookPeerReviewEvent)2 File (java.io.File)2 URL (java.net.URL)2 List (java.util.List)2 StoryBookLearningEvent (ai.elimu.model.analytics.StoryBookLearningEvent)1 Emoji (ai.elimu.model.content.Emoji)1