Search in sources :

Example 1 with ApplicationGson

use of ai.elimu.model.gson.admin.ApplicationGson in project webapp by elimu-ai.

the class JavaToGsonConverter method getAppGroupGson.

public static AppGroupGson getAppGroupGson(AppGroup appGroup) {
    if (appGroup == null) {
        return null;
    } else {
        AppGroupGson appGroupGson = new AppGroupGson();
        appGroupGson.setId(appGroup.getId());
        List<ApplicationGson> applications = new ArrayList<>();
        for (Application application : appGroup.getApplications()) {
            ApplicationGson applicationGson = getApplicationGson(application);
            applications.add(applicationGson);
        }
        appGroupGson.setApplications(applications);
        return appGroupGson;
    }
}
Also used : ArrayList(java.util.ArrayList) AppGroupGson(ai.elimu.model.gson.project.AppGroupGson) Application(ai.elimu.model.admin.Application) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson)

Example 2 with ApplicationGson

use of ai.elimu.model.gson.admin.ApplicationGson 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 3 with ApplicationGson

use of ai.elimu.model.gson.admin.ApplicationGson 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)

Example 4 with ApplicationGson

use of ai.elimu.model.gson.admin.ApplicationGson in project webapp by elimu-ai.

the class JavaToGsonConverter method getApplicationGson.

public static ApplicationGson getApplicationGson(Application application) {
    if (application == null) {
        return null;
    } else {
        ApplicationGson applicationGson = new ApplicationGson();
        applicationGson.setId(application.getId());
        applicationGson.setLocale(application.getLocale());
        applicationGson.setPackageName(application.getPackageName());
        applicationGson.setLiteracySkills(application.getLiteracySkills());
        applicationGson.setNumeracySkills(application.getNumeracySkills());
        applicationGson.setApplicationStatus(application.getApplicationStatus());
        return applicationGson;
    }
}
Also used : ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson)

Example 5 with ApplicationGson

use of ai.elimu.model.gson.admin.ApplicationGson in project webapp by elimu-ai.

the class JsonService method getApplications.

@Cacheable("applications")
public JSONArray getApplications(Locale locale) {
    logger.info("getApplications");
    Date dateStart = new Date();
    JSONArray applications = new JSONArray();
    for (Application application : applicationDao.readAll(locale)) {
        ApplicationGson applicationGson = JavaToGsonConverter.getApplicationGson(application);
        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("getApplications duration: " + (dateEnd.getTime() - dateStart.getTime()) + " ms");
    return applications;
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) JSONObject(org.json.JSONObject) 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) Application(ai.elimu.model.admin.Application) Date(java.util.Date) ApplicationGson(ai.elimu.model.gson.admin.ApplicationGson) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ApplicationGson (ai.elimu.model.gson.admin.ApplicationGson)5 Application (ai.elimu.model.admin.Application)4 ArrayList (java.util.ArrayList)4 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)3 ApplicationVersionGson (ai.elimu.model.gson.admin.ApplicationVersionGson)3 Gson (com.google.gson.Gson)3 JSONObject (org.json.JSONObject)3 Date (java.util.Date)2 JSONArray (org.json.JSONArray)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 AppGroupGson (ai.elimu.model.gson.project.AppGroupGson)1 AppCategory (ai.elimu.model.project.AppCategory)1 AppGroup (ai.elimu.model.project.AppGroup)1