Search in sources :

Example 1 with ApplicationVersion

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";
    }
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ApplicationVersion

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";
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) Application(ai.elimu.model.admin.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ApplicationVersion

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";
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) Application(ai.elimu.model.admin.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ApplicationVersion

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));
    }
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) ApplicationVersionGson(ai.elimu.model.gson.admin.ApplicationVersionGson) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson) Gson(com.google.gson.Gson) ApplicationVersionGson(ai.elimu.model.gson.admin.ApplicationVersionGson) Application(ai.elimu.model.admin.Application) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson)

Example 5 with ApplicationVersion

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;
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ApplicationVersionGson(ai.elimu.model.gson.admin.ApplicationVersionGson) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson) Gson(com.google.gson.Gson) ApplicationVersionGson(ai.elimu.model.gson.admin.ApplicationVersionGson) Date(java.util.Date) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson) JSONObject(org.json.JSONObject) AppGroup(ai.elimu.model.project.AppGroup) Application(ai.elimu.model.admin.Application) AppCategory(ai.elimu.model.project.AppCategory) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)14 Application (ai.elimu.model.admin.Application)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 AppCategory (ai.elimu.model.project.AppCategory)5 AppGroup (ai.elimu.model.project.AppGroup)5 Contributor (ai.elimu.model.Contributor)4 Project (ai.elimu.model.project.Project)4 IOException (java.io.IOException)4 ApplicationGson (ai.elimu.model.gson.admin.ApplicationGson)3 ApplicationVersionGson (ai.elimu.model.gson.admin.ApplicationVersionGson)3 Gson (com.google.gson.Gson)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 EOFException (java.io.EOFException)2 Date (java.util.Date)2 ByteArrayApkFile (net.dongliu.apk.parser.ByteArrayApkFile)2 ApkMeta (net.dongliu.apk.parser.bean.ApkMeta)2 JSONArray (org.json.JSONArray)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 License (ai.elimu.model.project.License)1