Search in sources :

Example 11 with Application

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

the class LetterLearningEventDaoTest method testReadAllByApplication.

@Test
public void testReadAllByApplication() {
    Application application = new Application();
    application.setPackageName("ai.elimu.handwriting");
    applicationDao.create(application);
    List<LetterLearningEvent> letterLearningEvents = letterLearningEventDao.readAll(application);
    assertThat(letterLearningEvents.size(), is(0));
    LetterLearningEvent letterLearningEvent = new LetterLearningEvent();
    letterLearningEvent.setApplication(application);
    letterLearningEventDao.create(letterLearningEvent);
    letterLearningEvents = letterLearningEventDao.readAll(application);
    assertThat(letterLearningEvents.size(), is(1));
    assertThat(letterLearningEvents.get(0).getApplication().getPackageName(), is("ai.elimu.handwriting"));
}
Also used : Application(ai.elimu.model.admin.Application) LetterLearningEvent(ai.elimu.model.analytics.LetterLearningEvent) Test(org.junit.Test)

Example 12 with Application

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

the class NumberLearningEventDaoTest method testReadAllByApplication.

@Test
public void testReadAllByApplication() {
    Application application = new Application();
    application.setPackageName("ai.elimu.handwriting");
    applicationDao.create(application);
    List<NumberLearningEvent> numberLearningEvents = numberLearningEventDao.readAll(application);
    assertThat(numberLearningEvents.size(), is(0));
    NumberLearningEvent numberLearningEvent = new NumberLearningEvent();
    numberLearningEvent.setApplication(application);
    numberLearningEventDao.create(numberLearningEvent);
    numberLearningEvents = numberLearningEventDao.readAll(application);
    assertThat(numberLearningEvents.size(), is(1));
    assertThat(numberLearningEvents.get(0).getApplication().getPackageName(), is("ai.elimu.handwriting"));
}
Also used : NumberLearningEvent(ai.elimu.model.analytics.NumberLearningEvent) Application(ai.elimu.model.admin.Application) Test(org.junit.Test)

Example 13 with Application

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

the class ApplicationVersionDaoTest method testCacheable.

@Test
public void testCacheable() {
    Application application = new Application();
    applicationDao.create(application);
    List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
    assertThat(applicationVersions.isEmpty(), is(true));
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) Application(ai.elimu.model.admin.Application) Test(org.junit.Test)

Example 14 with Application

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

the class ApkController method handleRequest.

@RequestMapping(value = "/{packageName}-{versionCode}.apk", method = RequestMethod.GET)
public void handleRequest(@PathVariable String packageName, @PathVariable Integer versionCode, @RequestParam String deviceId, @RequestParam String checksum, @RequestParam Locale locale, @RequestParam String deviceModel, @RequestParam Integer osVersion, @RequestParam Integer appVersionCode, // Custom Project
@RequestParam(required = false) String licenseEmail, @RequestParam(required = false) String licenseNumber, @RequestParam(required = false) Long applicationId, HttpServletRequest request, HttpServletResponse response, OutputStream outputStream) {
    logger.info("handleRequest");
    logger.info("packageName: " + packageName);
    logger.info("versionCode: " + versionCode);
    logger.info("request.getQueryString(): " + request.getQueryString());
    logger.info("request.getRemoteAddr(): " + request.getRemoteAddr());
    // TODO: validate checksum
    // See AppCollectionRestController#addInfrastructureApps
    boolean isInfrastructureApp = "ai.elimu.appstore".equals(packageName) || "ai.elimu.appstore_custom".equals(packageName) || "ai.elimu.analytics".equals(packageName) || "ai.elimu.launcher".equals(packageName) || "ai.elimu.launcher_custom".equals(packageName);
    Application application = null;
    if (TextUtils.isBlank(licenseEmail) || isInfrastructureApp) {
        application = applicationDao.readByPackageName(locale, packageName);
    } else {
        // Custom Project
        License license = licenseDao.read(licenseEmail, licenseNumber);
        if (license != null) {
            // TODO: fetch Application based on License instead of additional applicationId parameter
            application = applicationDao.read(applicationId);
        }
    }
    ApplicationVersion applicationVersion = applicationVersionDao.read(application, versionCode);
    response.setContentType(applicationVersion.getContentType());
    byte[] bytes = applicationVersion.getBytes();
    response.setContentLength(bytes.length);
    try {
        outputStream.write(bytes);
    } catch (EOFException ex) {
        // org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
        logger.warn(ex);
    } catch (IOException ex) {
        logger.error(null, ex);
    } finally {
        try {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (EOFException ex) {
                // org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
                logger.warn(ex);
            }
        } catch (IOException ex) {
            logger.error(null, ex);
        }
    }
}
Also used : ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) License(ai.elimu.model.project.License) EOFException(java.io.EOFException) IOException(java.io.IOException) Application(ai.elimu.model.admin.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Application

use of ai.elimu.model.admin.Application 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";
}
Also used : LiteracySkill(ai.elimu.model.enums.content.LiteracySkill) NumeracySkill(ai.elimu.model.enums.content.NumeracySkill) Contributor(ai.elimu.model.Contributor) Application(ai.elimu.model.admin.Application) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Application (ai.elimu.model.admin.Application)20 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Contributor (ai.elimu.model.Contributor)4 ApplicationGson (ai.elimu.model.gson.admin.ApplicationGson)4 AppCategory (ai.elimu.model.project.AppCategory)4 AppGroup (ai.elimu.model.project.AppGroup)4 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 ApplicationVersionGson (ai.elimu.model.gson.admin.ApplicationVersionGson)3 Project (ai.elimu.model.project.Project)3 Gson (com.google.gson.Gson)3 IOException (java.io.IOException)3 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 LetterLearningEvent (ai.elimu.model.analytics.LetterLearningEvent)1