Search in sources :

Example 31 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class AdminProjectEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Project project, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Project existingProject = projectDao.read(project.getName());
    if ((existingProject != null) && !existingProject.getId().equals(project.getId())) {
        result.rejectValue("name", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        List<Contributor> contributors = contributorDao.readAll();
        model.addAttribute("managers", contributors);
        return "admin/project/edit";
    } else {
        projectDao.update(project);
        // Send invitation e-mail to newly added managers
        if (project.getManagers() != null) {
            for (Contributor manager : project.getManagers()) {
                boolean isManagerAddedAlready = false;
                if ((existingProject != null) && (existingProject.getManagers() != null)) {
                    for (Contributor existingManager : existingProject.getManagers()) {
                        if (existingManager.getId().equals(manager.getId())) {
                            isManagerAddedAlready = true;
                            break;
                        }
                    }
                }
                logger.info("isManagerAddedAlready: " + isManagerAddedAlready + ", manager.getEmail(): " + manager.getEmail());
                if (!isManagerAddedAlready) {
                    // Update role so that the contributor can access the /project page
                    manager.getRoles().add(Role.PROJECT_MANAGER);
                    contributorDao.update(manager);
                    // Send inviation e-mail
                    String to = manager.getEmail();
                    String from = "elimu.ai <info@elimu.ai>";
                    String subject = "You have been added as a manager";
                    String title = project.getName();
                    String firstName = StringUtils.isBlank(manager.getFirstName()) ? "" : manager.getFirstName();
                    String htmlText = "<p>Hi, " + firstName + "</p>";
                    htmlText += "<p>" + contributor.getFirstName() + " has added you as a manager of the \"" + project.getName() + "\" project.</p>";
                    htmlText += "<p>To create a new app collection, click the button below:</p>";
                    String buttonUrl = "http://elimu.ai/project";
                    if (EnvironmentContextLoaderListener.env == Environment.TEST) {
                        buttonUrl = "http://test.elimu.ai/project";
                    }
                    Mailer.sendHtmlWithButton(to, null, from, subject, title, htmlText, "Open project", buttonUrl);
                    // Notify Slack channel
                    if (EnvironmentContextLoaderListener.env == Environment.PROD) {
                        String text = URLEncoder.encode(contributor.getFirstName() + " just added a project manager to \"" + project.getName() + "\": " + manager.getFirstName() + " " + manager.getLastName());
                        String iconUrl = manager.getImageUrl();
                        SlackApiHelper.postMessage("G6UR7UH2S", text, iconUrl, null);
                    }
                }
            }
        }
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just edited a project: \"" + project.getName() + "\"");
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage("G6UR7UH2S", text, iconUrl, null);
        }
        return "redirect:/admin/project/list#" + project.getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class AllophoneCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@Valid Allophone allophone, BindingResult result, Model model, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isNotBlank(allophone.getValueIpa())) {
        Allophone existingAllophone = allophoneDao.readByValueIpa(allophone.getLocale(), allophone.getValueIpa());
        if (existingAllophone != null) {
            result.rejectValue("valueIpa", "NonUnique");
        }
    }
    if (StringUtils.isNotBlank(allophone.getValueSampa())) {
        Allophone existingAllophone = allophoneDao.readByValueSampa(allophone.getLocale(), allophone.getValueSampa());
        if (existingAllophone != null) {
            result.rejectValue("valueSampa", "NonUnique");
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("allophone", allophone);
        model.addAttribute("soundTypes", SoundType.values());
        return "content/allophone/create";
    } else {
        allophone.setTimeLastUpdate(Calendar.getInstance());
        allophoneDao.create(allophone);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just created an Allophone:\n" + "• Language: \"" + allophone.getLocale().getLanguage() + "\"\n" + "• IPA: /" + allophone.getValueIpa() + "/\n" + "• X-SAMPA: \"" + allophone.getValueSampa() + "\"\n" + "• Sound type: \"" + allophone.getSoundType() + "\"\n" + "See ") + "http://elimu.ai/content/allophone/edit/" + allophone.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/allophone/list#" + allophone.getId();
    }
}
Also used : Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class AllophoneEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(@PathVariable Long id, @Valid Allophone allophone, BindingResult result, Model model, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isNotBlank(allophone.getValueIpa())) {
        Allophone existingAllophone = allophoneDao.readByValueIpa(allophone.getLocale(), allophone.getValueIpa());
        if ((existingAllophone != null) && !existingAllophone.getId().equals(allophone.getId())) {
            result.rejectValue("valueIpa", "NonUnique");
        }
    }
    if (StringUtils.isNotBlank(allophone.getValueSampa())) {
        Allophone existingAllophone = allophoneDao.readByValueSampa(allophone.getLocale(), allophone.getValueSampa());
        if ((existingAllophone != null) && !existingAllophone.getId().equals(allophone.getId())) {
            result.rejectValue("valueSampa", "NonUnique");
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("allophone", allophone);
        model.addAttribute("soundTypes", SoundType.values());
        return "content/allophone/edit";
    } else {
        allophone.setTimeLastUpdate(Calendar.getInstance());
        allophone.setRevisionNumber(allophone.getRevisionNumber() + 1);
        allophoneDao.update(allophone);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an Allophone:\n" + "• Language: \"" + allophone.getLocale().getLanguage() + "\"\n" + "• IPA: /" + allophone.getValueIpa() + "/\n" + "• X-SAMPA: \"" + allophone.getValueSampa() + "\"\n" + "• Sound type: \"" + allophone.getSoundType() + "\"\n" + "See ") + "http://elimu.ai/content/allophone/edit/" + allophone.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/allophone/list#" + allophone.getId();
    }
}
Also used : Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class EditTimeController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @RequestParam Integer timePerWeek, Model model) {
    logger.info("handleSubmit");
    logger.info("timePerWeek: " + timePerWeek);
    // TODO: validate timePerWeek
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    contributor.setTimePerWeek(timePerWeek);
    contributorDao.update(contributor);
    session.setAttribute("contributor", contributor);
    if (EnvironmentContextLoaderListener.env == Environment.PROD) {
        String text = URLEncoder.encode(contributor.getFirstName() + " just updated his/her available time:\n" + contributor.getTimePerWeek() + " minutes per week\n" + "See ") + "http://elimu.ai/content/community/contributors";
        String iconUrl = contributor.getImageUrl();
        SlackApiHelper.postMessage(null, text, iconUrl, null);
    }
    return "redirect:/content";
}
Also used : Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class LetterCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Letter letter, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    Letter existingLetter = letterDao.readByText(letter.getLocale(), letter.getText());
    if (existingLetter != null) {
        result.rejectValue("text", "NonUnique");
    }
    if (result.hasErrors()) {
        model.addAttribute("letter", letter);
        List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
        model.addAttribute("allophones", allophones);
        return "content/letter/create";
    } else {
        letter.setTimeLastUpdate(Calendar.getInstance());
        letterDao.create(letter);
        return "redirect:/content/letter/list#" + letter.getId();
    }
}
Also used : Letter(ai.elimu.model.content.Letter) Allophone(ai.elimu.model.content.Allophone) 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