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();
}
}
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();
}
}
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;
}
}
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";
}
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();
}
}
Aggregations