Search in sources :

Example 26 with Contributor

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

the class AppCategoryEditController method handleSubmit.

@RequestMapping(value = "/{id}", 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()) && !existingAppCategory.getId().equals(appCategory.getId())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCategory", appCategory);
        return "project/app-category/edit";
    } else {
        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 updated an 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 27 with Contributor

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

the class AppCollectionEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @Valid AppCollection appCollection, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Disallow app collections with identical name
    Project project = projectDao.read(projectId);
    List<AppCollection> existingAppCollections = appCollectionDao.readAll(project);
    for (AppCollection existingAppCollection : existingAppCollections) {
        if (existingAppCollection.getName().equals(appCollection.getName()) && !existingAppCollection.getId().equals(appCollection.getId())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCollection", appCollection);
        List<License> licenses = licenseDao.readAll(appCollection);
        model.addAttribute("licenses", licenses);
        return "project/app-collection/edit";
    } else {
        appCollectionDao.update(appCollection);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an App Collection:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.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)

Example 28 with Contributor

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

the class DomainLocaleResolver method resolveLocale.

@Override
public Locale resolveLocale(HttpServletRequest request) {
    logger.debug("resolveLocale");
    Contributor contributor = (Contributor) request.getSession().getAttribute("contributor");
    if ((contributor != null) && (contributor.getLocale() != null)) {
        Locale contributorLocale = new Locale(contributor.getLocale().getLanguage());
        logger.debug("contributorLocale: " + contributorLocale);
        return contributorLocale;
    }
    if (EnvironmentContextLoaderListener.env == Environment.DEV) {
        // Use "?lang" parameter instead of domain name
        return super.resolveLocale(request);
    } else {
        Locale locale = new Locale("en", "US");
        String serverName = request.getServerName();
        logger.debug("serverName: " + serverName);
        if (serverName.startsWith("ar.")) {
            locale = new Locale("ar");
        } else if (serverName.startsWith("en.")) {
            locale = new Locale("en");
        } else if (serverName.startsWith("es.")) {
            locale = new Locale("es");
        } else if (serverName.startsWith("sw.")) {
            locale = new Locale("sw");
        }
        logger.debug("locale: " + locale);
        return locale;
    }
}
Also used : Locale(java.util.Locale) Contributor(ai.elimu.model.Contributor)

Example 29 with Contributor

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

the class ApplicationListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    logger.info("contributor.getLocale(): " + contributor.getLocale());
    // List count of active Android applications for each EGRA/EGMA skill
    List<Application> activeApplications = applicationDao.readAllByStatus(contributor.getLocale(), ApplicationStatus.ACTIVE);
    logger.info("activeApplications.size(): " + activeApplications.size());
    Map<LiteracySkill, Integer> literacySkillCountMap = new LinkedHashMap<>();
    for (LiteracySkill literacySkill : LiteracySkill.values()) {
        literacySkillCountMap.put(literacySkill, 0);
    }
    for (Application application : activeApplications) {
        for (LiteracySkill literacySkill : application.getLiteracySkills()) {
            int count = literacySkillCountMap.get(literacySkill);
            literacySkillCountMap.put(literacySkill, count + 1);
        }
    }
    model.addAttribute("literacySkillCountMap", literacySkillCountMap);
    int maxLiteracySkillCount = 0;
    Collection<Integer> literacySkillCountCollection = literacySkillCountMap.values();
    for (int count : literacySkillCountCollection) {
        if (count > maxLiteracySkillCount) {
            maxLiteracySkillCount = count;
        }
    }
    model.addAttribute("maxLiteracySkillCount", maxLiteracySkillCount);
    Map<NumeracySkill, Integer> numeracySkillCountMap = new LinkedHashMap<>();
    for (NumeracySkill numeracySkill : NumeracySkill.values()) {
        numeracySkillCountMap.put(numeracySkill, 0);
    }
    for (Application application : activeApplications) {
        for (NumeracySkill numeracySkill : application.getNumeracySkills()) {
            int count = numeracySkillCountMap.get(numeracySkill);
            numeracySkillCountMap.put(numeracySkill, count + 1);
        }
    }
    model.addAttribute("numeracySkillCountMap", numeracySkillCountMap);
    int maxNumeracySkillCount = 0;
    Collection<Integer> numeracySkillCountCollection = numeracySkillCountMap.values();
    for (int count : numeracySkillCountCollection) {
        if (count > maxNumeracySkillCount) {
            maxNumeracySkillCount = count;
        }
    }
    model.addAttribute("maxNumeracySkillCount", maxNumeracySkillCount);
    List<Application> applications = applicationDao.readAll(contributor.getLocale());
    model.addAttribute("applications", applications);
    return "admin/application/list";
}
Also used : LiteracySkill(ai.elimu.model.enums.content.LiteracySkill) NumeracySkill(ai.elimu.model.enums.content.NumeracySkill) Contributor(ai.elimu.model.Contributor) Application(ai.elimu.model.admin.Application) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with Contributor

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

the class AdminProjectCreateController method handleSubmit.

@RequestMapping(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) {
        result.rejectValue("name", "NonUnique");
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        return "admin/project/create";
    } else {
        projectDao.create(project);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new 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)

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