use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class SlackInviteScheduler method executeTeamSynchronization.
/**
* Add to (and remove from) Slack channels based on Contributor's teams
* registered on web site.
*/
// 40 past every hour
@Scheduled(cron = "00 40 * * * *")
public synchronized void executeTeamSynchronization() {
logger.info("executeTeamSynchronization");
if (EnvironmentContextLoaderListener.env != Environment.PROD) {
return;
}
List<Contributor> contributors = contributorDao.readAll();
logger.info("contributors.size(): " + contributors.size());
for (Contributor contributor : contributors) {
if (contributor.getTeams() == null) {
continue;
}
if (StringUtils.isNotBlank(contributor.getSlackId())) {
for (Team team : Team.values()) {
if (team == Team.OTHER) {
continue;
}
if (contributor.getTeams().contains(team)) {
// See https://api.slack.com/docs/rate-limits
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
boolean isResponseOk = SlackApiHelper.inviteToChannel(contributor, team);
if (isResponseOk) {
// Send welcome e-mail specific to the team
String to = contributor.getEmail();
String from = "elimu.ai <info@elimu.ai>";
Locale locale = new Locale("en");
String teamName = messageSource.getMessage("team." + team, null, locale);
String subject = "You joined the " + teamName + " team";
String title = "Team: " + teamName;
String firstName = StringUtils.isBlank(contributor.getFirstName()) ? "" : contributor.getFirstName();
String htmlText = "<p>Hi, " + firstName + "</p>";
htmlText += "<p>You were added to the \"" + teamName + "\" team. The responsibility of this team is the following:</p>";
String teamMissionStatement = messageSource.getMessage("team." + team + ".mission.statement", null, locale);
htmlText += "<p><blockquote>\"" + teamMissionStatement + "\"</blockquote></p>";
// Team-specific content
if (team == Team.DEVELOPMENT) {
htmlText += "<h2>GitHub</h2>";
htmlText += "<p>The source code of the project is located at https://github.com/elimu-ai</p>";
htmlText += "<p>Please send us your GitHub username so that we can add you as a GitHub team member. Either send your username by replying to this e-mail or posting it at the Slack channel (see below).</p>";
htmlText += "<p>If you don't yet have a GitHub user, you can create one here: https://github.com/join</p>";
htmlText += "<p>Are you new to GitHub? See https://guides.github.com/introduction/flow</p>";
}
htmlText += "<h2>Slack channel</h2>";
htmlText += "<p>We just added you to the Slack channel <a href=\"https://elimu-ai.slack.com/messages/" + SlackApiHelper.getChannelId(team) + "\">#" + SlackApiHelper.getChannelId(team) + "</a></p>";
htmlText += "<p>To chat with the other team members, click the button below:</p>";
String buttonText = "Go to Slack channel";
String buttonUrl = "https://elimu-ai.slack.com/messages/" + SlackApiHelper.getChannelId(team);
Mailer.sendHtmlWithButton(to, null, from, subject, title, htmlText, buttonText, buttonUrl);
}
}
/*else {
SlackApiHelper.kickFromChannel(contributor, team);
}*/
}
}
}
logger.info("executeTeamSynchronization complete");
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class SlackInviteScheduler method executeInvite.
// 30 past every hour
@Scheduled(cron = "00 30 * * * *")
public synchronized void executeInvite() {
logger.info("executeInvite");
if (EnvironmentContextLoaderListener.env != Environment.PROD) {
return;
}
JSONArray slackMembers = SlackApiHelper.getUserList();
if (slackMembers != null) {
logger.info("slackMembers.length(): " + slackMembers.length());
List<Contributor> contributors = contributorDao.readAll();
logger.info("contributors.size(): " + contributors.size());
for (Contributor contributor : contributors) {
// If the Contributor has already joined Slack, store the Slack id
if (StringUtils.isBlank(contributor.getSlackId())) {
for (int i = 0; i < slackMembers.length(); i++) {
JSONObject member = slackMembers.getJSONObject(i);
String slackId = member.getString("id");
JSONObject memberProfile = member.getJSONObject("profile");
if (!memberProfile.isNull("email")) {
String email = memberProfile.getString("email");
if (contributor.getEmail().equals(email)) {
contributor.setSlackId(slackId);
contributorDao.update(contributor);
}
}
}
}
// If the Contributor has not already joined Slack, send an invite
if (StringUtils.isBlank(contributor.getSlackId())) {
SlackApiHelper.sendMemberInvite(contributor);
}
}
}
logger.info("executeInvite complete");
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class ImageEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
Image image = imageDao.read(id);
model.addAttribute("image", image);
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
// model.addAttribute("imageRevisionEvents", imageRevisionEventDao.readAll(image));
model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
Audio audio = audioDao.read(image.getTitle(), contributor.getLocale());
model.addAttribute("audio", audio);
return "content/multimedia/image/edit";
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class VideoEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
Video video = videoDao.read(id);
model.addAttribute("video", video);
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
model.addAttribute("videoRevisionEvents", videoRevisionEventDao.readAll(video));
model.addAttribute("letters", letterDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("numbers", numberDao.readAllOrdered(contributor.getLocale()));
model.addAttribute("words", wordDao.readAllOrdered(contributor.getLocale()));
return "content/multimedia/video/edit";
}
use of ai.elimu.model.Contributor in project webapp by elimu-ai.
the class NumberCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Number number, BindingResult result, Model model) {
logger.info("handleSubmit");
if (number.getLocale() == Locale.AR) {
if (StringUtils.isBlank(number.getSymbol())) {
result.rejectValue("symbol", "NotNull");
}
}
Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
if (existingNumber != null) {
result.rejectValue("value", "NonUnique");
}
Contributor contributor = (Contributor) session.getAttribute("contributor");
if (result.hasErrors()) {
model.addAttribute("number", number);
List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
model.addAttribute("words", words);
return "content/number/create";
} else {
number.setTimeLastUpdate(Calendar.getInstance());
numberDao.create(number);
return "redirect:/content/number/list#" + number.getId();
}
}
Aggregations