use of ai.elimu.model.contributor.WordContributionEvent in project webapp by elimu-ai.
the class WordPeerReviewsController method handleGetRequest.
/**
* Get {@link WordContributionEvent}s pending a {@link WordPeerReviewEvent} 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 WordContributionEvent for each Word, including those made by the current Contributor
List<WordContributionEvent> mostRecentWordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
logger.info("mostRecentWordContributionEvents.size(): " + mostRecentWordContributionEvents.size());
// For each WordContributionEvent, check if the Contributor has already performed a peer-review.
// If not, add it to the list of pending peer reviews.
List<WordContributionEvent> wordContributionEventsPendingPeerReview = new ArrayList<>();
for (WordContributionEvent mostRecentWordContributionEvent : mostRecentWordContributionEvents) {
// Ignore WordContributionEvents made by the current Contributor
if (mostRecentWordContributionEvent.getContributor().getId().equals(contributor.getId())) {
continue;
}
// Check if the current Contributor has already peer-reviewed this Word contribution
List<WordPeerReviewEvent> wordPeerReviewEvents = wordPeerReviewEventDao.readAll(mostRecentWordContributionEvent, contributor);
if (wordPeerReviewEvents.isEmpty()) {
wordContributionEventsPendingPeerReview.add(mostRecentWordContributionEvent);
}
}
logger.info("wordContributionEventsPendingPeerReview.size(): " + wordContributionEventsPendingPeerReview.size());
model.addAttribute("wordContributionEventsPendingPeerReview", wordContributionEventsPendingPeerReview);
model.addAttribute("emojisByWordId", getEmojisByWordId());
return "content/word/peer-reviews/pending";
}
use of ai.elimu.model.contributor.WordContributionEvent 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";
}
use of ai.elimu.model.contributor.WordContributionEvent 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";
}
use of ai.elimu.model.contributor.WordContributionEvent in project webapp by elimu-ai.
the class WordContributionEventDaoTest method testReadMostRecent.
@Test
public void testReadMostRecent() {
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecent(10);
assertThat(wordContributionEvents.isEmpty(), is(true));
Contributor contributor = new Contributor();
contributorDao.create(contributor);
Word word = new Word();
wordDao.create(word);
WordContributionEvent wordContributionEvent = new WordContributionEvent();
wordContributionEvent.setContributor(contributor);
wordContributionEvent.setWord(word);
wordContributionEvent.setRevisionNumber(word.getRevisionNumber());
wordContributionEvent.setTime(Calendar.getInstance());
wordContributionEvent.setTimeSpentMs(10_000L);
wordContributionEventDao.create(wordContributionEvent);
wordContributionEvents = wordContributionEventDao.readMostRecent(10);
assertThat(wordContributionEvents.isEmpty(), is(false));
assertThat(wordContributionEvents.size(), is(1));
// Clean up content stored in the database, so that it won't affect the other tests
wordContributionEventDao.delete(wordContributionEvent);
}
use of ai.elimu.model.contributor.WordContributionEvent in project webapp by elimu-ai.
the class WordContributionEventDaoTest method testReadMostRecentPerWord.
@Test
public void testReadMostRecentPerWord() {
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.isEmpty(), is(true));
Contributor contributor1 = new Contributor();
contributorDao.create(contributor1);
Word word1 = new Word();
wordDao.create(word1);
WordContributionEvent wordContributionEvent1 = new WordContributionEvent();
wordContributionEvent1.setContributor(contributor1);
wordContributionEvent1.setWord(word1);
wordContributionEvent1.setRevisionNumber(word1.getRevisionNumber());
wordContributionEvent1.setTime(Calendar.getInstance());
wordContributionEvent1.setTimeSpentMs(10_000L);
wordContributionEventDao.create(wordContributionEvent1);
wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.isEmpty(), is(false));
assertThat(wordContributionEvents.size(), is(1));
assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
Word word2 = new Word();
wordDao.create(word2);
WordContributionEvent wordContributionEvent2 = new WordContributionEvent();
wordContributionEvent2.setContributor(contributor1);
wordContributionEvent2.setWord(word2);
wordContributionEvent2.setRevisionNumber(word2.getRevisionNumber());
wordContributionEvent2.setTime(Calendar.getInstance());
wordContributionEvent2.setTimeSpentMs(10_000L);
wordContributionEventDao.create(wordContributionEvent2);
wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.isEmpty(), is(false));
assertThat(wordContributionEvents.size(), is(2));
assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
assertThat(wordContributionEvents.get(1).getWord().getId(), is(wordContributionEvent2.getWord().getId()));
// Re-use a word (word2) that was used in a previous contribution event
WordContributionEvent wordContributionEvent3 = new WordContributionEvent();
wordContributionEvent3.setContributor(contributor1);
wordContributionEvent3.setWord(word2);
wordContributionEvent3.setRevisionNumber(word2.getRevisionNumber());
wordContributionEvent3.setTime(Calendar.getInstance());
wordContributionEvent3.setTimeSpentMs(10_000L);
wordContributionEventDao.create(wordContributionEvent3);
// The number of contribution events returned should not increase
wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.isEmpty(), is(false));
assertThat(wordContributionEvents.size(), is(2));
assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
assertThat(wordContributionEvents.get(1).getWord().getId(), is(wordContributionEvent3.getWord().getId()));
// Clean up content stored in the database, so that it won't affect the other tests
wordContributionEventDao.delete(wordContributionEvent1);
wordContributionEventDao.delete(wordContributionEvent2);
wordContributionEventDao.delete(wordContributionEvent3);
}
Aggregations