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";
}
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";
}
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";
}
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";
}
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";
}
Aggregations