Search in sources :

Example 51 with Contributor

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

the class WordListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    // To ease development/testing, auto-generate Words
    List<Word> wordsGenerated = generateWords(contributor.getLocale());
    for (Word word : wordsGenerated) {
        Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
        if (existingWord == null) {
            wordDao.create(word);
        }
    }
    List<Word> words = wordDao.readAllOrderedByUsage(contributor.getLocale());
    model.addAttribute("words", words);
    int maxUsageCount = 0;
    for (Word word : words) {
        if (word.getUsageCount() > maxUsageCount) {
            maxUsageCount = word.getUsageCount();
        }
    }
    model.addAttribute("maxUsageCount", maxUsageCount);
    return "content/word/list";
}
Also used : Word(ai.elimu.model.content.Word) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with Contributor

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

the class AppCategoryCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @Valid AppCategory appCategory, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Disallow app categories with identical name
    Project project = projectDao.read(projectId);
    List<AppCategory> existingAppCategories = project.getAppCategories();
    for (AppCategory existingAppCategory : existingAppCategories) {
        if (existingAppCategory.getName().equals(appCategory.getName())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCategory", appCategory);
        return "project/app-category/create";
    } else {
        appCategoryDao.create(appCategory);
        project.getAppCategories().add(appCategory);
        projectDao.update(project);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new App Category:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Category: \"" + appCategory.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.getId() + "/app-category/list#" + appCategory.getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) Contributor(ai.elimu.model.Contributor) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with Contributor

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

the class AppCollectionCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid AppCollection appCollection, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Project project = appCollection.getProject();
    model.addAttribute("project", project);
    // Disallow app collections with identical name
    List<AppCollection> existingAppCollections = appCollectionDao.readAll(project);
    for (AppCollection existingAppCollection : existingAppCollections) {
        if (existingAppCollection.getName().equals(appCollection.getName())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("appCollection", appCollection);
        return "project/app-collection/create";
    } else {
        appCollectionDao.create(appCollection);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new App Collection:\n" + "• Project: \"" + appCollection.getProject().getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + appCollection.getProject().getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + appCollection.getProject().getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) Contributor(ai.elimu.model.Contributor) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 54 with Contributor

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

the class AppGroupCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @PathVariable Long appCategoryId, @Valid AppGroup appGroup, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCategory appCategory = appCategoryDao.read(appCategoryId);
    model.addAttribute("appCategory", appCategory);
    List<AppGroup> appGroups = appCategory.getAppGroups();
    if (!appGroups.isEmpty()) {
        // Do not allow creation of a new AppGroup if an empty one already exists
        for (AppGroup existingAppGroup : appGroups) {
            if (existingAppGroup.getApplications().isEmpty()) {
                result.reject("EmptyAppGroup");
                break;
            }
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("appGroup", appGroup);
        return "project/app-group/create";
    } else {
        appGroupDao.create(appGroup);
        appCategory.getAppGroups().add(appGroup);
        appCategoryDao.update(appCategory);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new App Group:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Category: \"" + appCategory.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-category/" + appCategory.getId() + "/app-group/list";
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.getId() + "/app-category/" + appCategory.getId() + "/app-group/list";
    }
}
Also used : Project(ai.elimu.model.project.Project) Contributor(ai.elimu.model.Contributor) AppGroup(ai.elimu.model.project.AppGroup) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with Contributor

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

the class LicenseCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @PathVariable Long appCollectionId, @Valid License license, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Needed by breadcrumbs and Slack post
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCollection appCollection = appCollectionDao.read(appCollectionId);
    model.addAttribute("appCollection", appCollection);
    // Disallow Licenses with identical e-mail
    List<License> existingLicenses = licenseDao.readAll(appCollection);
    for (License existingLicence : existingLicenses) {
        if (existingLicence.getLicenseEmail().equals(license.getLicenseEmail())) {
            result.rejectValue("licenseEmail", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("license", license);
        return "project/license/create";
    } else {
        licenseDao.create(license);
        // Send license information via e-mail
        Contributor contributor = (Contributor) session.getAttribute("contributor");
        sendLicenseInEmail(license, contributor);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new License:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "• E-mail: \"" + license.getLicenseEmail() + "\"\n" + "• Number: \"" + license.getLicenseNumber() + "\"\n" + "• First name: \"" + license.getFirstName() + "\"\n" + "• Last name: \"" + license.getLastName() + "\"\n" + (StringUtils.isBlank(license.getOrganization()) ? "" : "• Organization: \"" + license.getOrganization() + "\"\n") + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) License(ai.elimu.model.project.License) Contributor(ai.elimu.model.Contributor) AppCollection(ai.elimu.model.project.AppCollection) 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