use of ai.elimu.model.admin.ApplicationVersion in project webapp by elimu-ai.
the class ApplicationEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Application application, BindingResult result, Model model) {
logger.info("handleSubmit");
if (result.hasErrors()) {
model.addAttribute("application", application);
model.addAttribute("applicationStatuses", ApplicationStatus.values());
List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
model.addAttribute("applicationVersions", applicationVersions);
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
return "admin/application/edit";
} else {
applicationDao.update(application);
// Refresh REST API cache
jsonService.refreshApplications(application.getLocale());
boolean isInfrastructureApp = "ai.elimu.appstore".equals(application.getPackageName()) || "ai.elimu.appstore_custom".equals(application.getPackageName()) || "ai.elimu.analytics".equals(application.getPackageName()) || "ai.elimu.launcher".equals(application.getPackageName()) || "ai.elimu.launcher_custom".equals(application.getPackageName());
if (isInfrastructureApp) {
jsonService.refreshApplicationsInAppCollection();
}
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
Contributor contributor = (Contributor) session.getAttribute("contributor");
String text = URLEncoder.encode(contributor.getFirstName() + " just updated an Application:\n" + "• Language: " + application.getLocale().getLanguage() + "\n" + "• Package name: \"" + application.getPackageName() + "\"\n" + "• Literacy skills: " + application.getLiteracySkills() + "\n" + "• Numeracy skills: " + application.getNumeracySkills());
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.DEVELOPMENT), text, iconUrl, null);
}
return "redirect:/admin/application/list";
}
}
use of ai.elimu.model.admin.ApplicationVersion in project webapp by elimu-ai.
the class ApplicationEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(@PathVariable Long id, Model model) {
logger.info("handleRequest");
Application application = applicationDao.read(id);
model.addAttribute("application", application);
model.addAttribute("applicationStatuses", ApplicationStatus.values());
List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
model.addAttribute("applicationVersions", applicationVersions);
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
return "admin/application/edit";
}
use of ai.elimu.model.admin.ApplicationVersion in project webapp by elimu-ai.
the class ApplicationVersionCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@RequestParam Long applicationId, Model model) {
logger.info("handleRequest");
logger.info("applicationId: " + applicationId);
Application application = applicationDao.read(applicationId);
ApplicationVersion applicationVersion = new ApplicationVersion();
applicationVersion.setApplication(application);
model.addAttribute("applicationVersion", applicationVersion);
return "admin/application-version/create";
}
use of ai.elimu.model.admin.ApplicationVersion in project webapp by elimu-ai.
the class JsonService method addInfrastructureApps.
/**
* As AppCollections in Custom Projects do not include all the Applications from the open source
* version, some apps are required to form the basic infrastructure.
*/
private void addInfrastructureApps(JSONArray applications) {
logger.info("addInfrastructureApps");
// Appstore
Application applicationAppstore = applicationDao.readByPackageName(Locale.EN, "ai.elimu.appstore_custom");
if (applicationAppstore != null) {
ApplicationGson applicationGson = JavaToGsonConverter.getApplicationGson(applicationAppstore);
// Fetch the Application's ApplicationVersions
List<ApplicationVersionGson> applicationVersions = new ArrayList<>();
for (ApplicationVersion applicationVersion : applicationVersionDao.readAll(applicationAppstore)) {
ApplicationVersionGson applicationVersionGson = JavaToGsonConverter.getApplicationVersionGson(applicationVersion);
applicationVersions.add(applicationVersionGson);
}
applicationGson.setApplicationVersions(applicationVersions);
String json = new Gson().toJson(applicationGson);
applications.put(new JSONObject(json));
}
// Analytics
Application applicationAnalytics = applicationDao.readByPackageName(Locale.EN, "ai.elimu.analytics");
if (applicationAnalytics != null) {
ApplicationGson applicationGson = JavaToGsonConverter.getApplicationGson(applicationAnalytics);
// Fetch the Application's ApplicationVersions
List<ApplicationVersionGson> applicationVersions = new ArrayList<>();
for (ApplicationVersion applicationVersion : applicationVersionDao.readAll(applicationAnalytics)) {
ApplicationVersionGson applicationVersionGson = JavaToGsonConverter.getApplicationVersionGson(applicationVersion);
applicationVersions.add(applicationVersionGson);
}
applicationGson.setApplicationVersions(applicationVersions);
String json = new Gson().toJson(applicationGson);
applications.put(new JSONObject(json));
}
// Custom Launcher
Application applicationLauncher = applicationDao.readByPackageName(Locale.EN, "ai.elimu.launcher_custom");
if (applicationLauncher != null) {
ApplicationGson applicationGson = JavaToGsonConverter.getApplicationGson(applicationLauncher);
// Fetch the Application's ApplicationVersions
List<ApplicationVersionGson> applicationVersions = new ArrayList<>();
for (ApplicationVersion applicationVersion : applicationVersionDao.readAll(applicationLauncher)) {
ApplicationVersionGson applicationVersionGson = JavaToGsonConverter.getApplicationVersionGson(applicationVersion);
applicationVersions.add(applicationVersionGson);
}
applicationGson.setApplicationVersions(applicationVersions);
String json = new Gson().toJson(applicationGson);
applications.put(new JSONObject(json));
}
}
use of ai.elimu.model.admin.ApplicationVersion in project webapp by elimu-ai.
the class JsonService method getApplications.
/**
* Returns app collection for custom project.
*/
@Cacheable(value = "applicationsInAppCollection", key = "#appCollection.id")
public JSONArray getApplications(AppCollection appCollection) {
logger.info("getApplications_appCollection");
Date dateStart = new Date();
JSONArray applications = new JSONArray();
addInfrastructureApps(applications);
for (AppCategory appCategory : appCollection.getAppCategories()) {
for (AppGroup appGroup : appCategory.getAppGroups()) {
for (Application application : appGroup.getApplications()) {
ApplicationGson applicationGson = JavaToGsonConverter.getApplicationGson(application);
// Fetch the Application's ApplicationVersions
List<ApplicationVersionGson> applicationVersions = new ArrayList<>();
logger.info("applicationVersionDao.readAll(" + application.getPackageName() + ") - " + new Date());
for (ApplicationVersion applicationVersion : applicationVersionDao.readAll(application)) {
logger.info("applicationVersion: " + applicationVersion.getVersionCode() + " - " + new Date());
ApplicationVersionGson applicationVersionGson = JavaToGsonConverter.getApplicationVersionGson(applicationVersion);
applicationVersions.add(applicationVersionGson);
}
applicationGson.setApplicationVersions(applicationVersions);
String json = new Gson().toJson(applicationGson);
applications.put(new JSONObject(json));
}
}
}
Date dateEnd = new Date();
logger.info("getApplicationVersions duration: " + (dateEnd.getTime() - dateStart.getTime()) + " ms");
return applications;
}
Aggregations