Search in sources :

Example 1 with ApplicationVersionGson

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

the class JavaToGsonConverter method getApplicationVersionGson.

public static ApplicationVersionGson getApplicationVersionGson(ApplicationVersion applicationVersion) {
    if (applicationVersion == null) {
        return null;
    } else {
        ApplicationVersionGson applicationVersionGson = new ApplicationVersionGson();
        applicationVersionGson.setId(applicationVersion.getId());
        applicationVersionGson.setApplication(getApplicationGson(applicationVersion.getApplication()));
        applicationVersionGson.setFileSizeInKb(applicationVersion.getFileSizeInKb());
        applicationVersionGson.setFileUrl("/apk/" + applicationVersion.getApplication().getPackageName() + "-" + applicationVersion.getVersionCode() + ".apk");
        applicationVersionGson.setChecksumMd5(applicationVersion.getChecksumMd5());
        applicationVersionGson.setContentType(applicationVersion.getContentType());
        applicationVersionGson.setVersionCode(applicationVersion.getVersionCode());
        applicationVersionGson.setVersionName(applicationVersion.getVersionName());
        applicationVersionGson.setLabel(applicationVersion.getLabel());
        applicationVersionGson.setMinSdkVersion(applicationVersion.getMinSdkVersion());
        applicationVersionGson.setStartCommand(applicationVersion.getStartCommand());
        applicationVersionGson.setTimeUploaded(applicationVersion.getTimeUploaded());
        return applicationVersionGson;
    }
}
Also used : ApplicationVersionGson(ai.elimu.model.gson.admin.ApplicationVersionGson)

Example 2 with ApplicationVersionGson

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

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

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

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