Search in sources :

Example 11 with Contributor

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");
}
Also used : Locale(java.util.Locale) Contributor(ai.elimu.model.Contributor) Team(ai.elimu.model.enums.Team) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 12 with Contributor

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");
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Contributor(ai.elimu.model.Contributor) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 13 with Contributor

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";
}
Also used : Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Contributor

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";
}
Also used : Video(ai.elimu.model.content.multimedia.Video) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Contributor

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();
    }
}
Also used : Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.Contributor)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 Project (ai.elimu.model.project.Project)12 IOException (java.io.IOException)10 Allophone (ai.elimu.model.content.Allophone)9 Word (ai.elimu.model.content.Word)8 Image (ai.elimu.model.content.multimedia.Image)8 Audio (ai.elimu.model.content.multimedia.Audio)6 Letter (ai.elimu.model.content.Letter)5 Number (ai.elimu.model.content.Number)5 AppCategory (ai.elimu.model.project.AppCategory)5 StoryBook (ai.elimu.model.content.StoryBook)4 Video (ai.elimu.model.content.multimedia.Video)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 AppCollection (ai.elimu.model.project.AppCollection)3 AppGroup (ai.elimu.model.project.AppGroup)3 Locale (java.util.Locale)3 Application (ai.elimu.model.admin.Application)2 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)2 Syllable (ai.elimu.model.content.Syllable)2