Search in sources :

Example 1 with License

use of ai.elimu.model.project.License in project webapp by elimu-ai.

the class AppCollectionRestController method getApplications.

@RequestMapping(value = "/applications", method = RequestMethod.GET)
public String getApplications(HttpServletRequest request, @PathVariable Long appCollectionId, @RequestParam String licenseEmail, @RequestParam String licenseNumber) {
    logger.info("getApplications");
    logger.info("request.getQueryString(): " + request.getQueryString());
    logger.info("request.getRemoteAddr(): " + request.getRemoteAddr());
    JSONObject jsonObject = new JSONObject();
    License license = licenseDao.read(licenseEmail, licenseNumber);
    if (license == null) {
        jsonObject.put("result", "error");
        jsonObject.put("description", "Invalid license");
    } else {
        AppCollection appCollection = appCollectionDao.read(appCollectionId);
        if (appCollection == null) {
            jsonObject.put("result", "error");
            jsonObject.put("description", "AppCollection not found");
        } else {
            // TODO: verify that the AppCollection matches the one associated with the provided License
            JSONArray applications = jsonService.getApplications(appCollection);
            jsonObject.put("result", "success");
            jsonObject.put("applications", applications);
        }
    }
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) License(ai.elimu.model.project.License) JSONArray(org.json.JSONArray) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with License

use of ai.elimu.model.project.License in project webapp by elimu-ai.

the class LicenseRestController method read.

@RequestMapping(method = RequestMethod.GET)
public String read(HttpServletRequest request, @RequestParam String licenseEmail, @RequestParam String licenseNumber) {
    logger.info("read");
    logger.info("request.getQueryString(): " + request.getQueryString());
    logger.info("request.getRemoteAddr(): " + request.getRemoteAddr());
    JSONObject jsonObject = new JSONObject();
    License license = licenseDao.read(licenseEmail, licenseNumber);
    if (license != null) {
        jsonObject.put("result", "success");
        jsonObject.put("appCollectionId", license.getAppCollection().getId());
    } else {
        jsonObject.put("result", "error");
        jsonObject.put("description", "Invalid license");
    }
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) License(ai.elimu.model.project.License) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with License

use of ai.elimu.model.project.License in project webapp by elimu-ai.

the class AppCollectionEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @Valid AppCollection appCollection, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Disallow app collections with identical name
    Project project = projectDao.read(projectId);
    List<AppCollection> existingAppCollections = appCollectionDao.readAll(project);
    for (AppCollection existingAppCollection : existingAppCollections) {
        if (existingAppCollection.getName().equals(appCollection.getName()) && !existingAppCollection.getId().equals(appCollection.getId())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCollection", appCollection);
        List<License> licenses = licenseDao.readAll(appCollection);
        model.addAttribute("licenses", licenses);
        return "project/app-collection/edit";
    } else {
        appCollectionDao.update(appCollection);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an App Collection:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) License(ai.elimu.model.project.License) Contributor(ai.elimu.model.Contributor) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with License

use of ai.elimu.model.project.License in project webapp by elimu-ai.

the class LicenseDaoTest method testRead.

@Test
public void testRead() {
    License license = new License();
    license.setLicenseEmail("info@elimu.ai");
    license.setLicenseNumber("bddf-d8f4-2adf-a365");
    License existingLicense = licenseDao.read(license.getLicenseEmail(), license.getLicenseNumber());
    assertThat(existingLicense, is(nullValue()));
    licenseDao.create(license);
    existingLicense = licenseDao.read(license.getLicenseEmail(), license.getLicenseNumber());
    assertThat(existingLicense.getLicenseEmail(), is("info@elimu.ai"));
    assertThat(existingLicense.getLicenseNumber(), is("bddf-d8f4-2adf-a365"));
}
Also used : License(ai.elimu.model.project.License) Test(org.junit.Test)

Example 5 with License

use of ai.elimu.model.project.License 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)

Aggregations

License (ai.elimu.model.project.License)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 AppCollection (ai.elimu.model.project.AppCollection)7 Project (ai.elimu.model.project.Project)5 JSONObject (org.json.JSONObject)3 Contributor (ai.elimu.model.Contributor)2 Application (ai.elimu.model.admin.Application)1 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)1 AppCollectionGson (ai.elimu.model.gson.project.AppCollectionGson)1 AppCategory (ai.elimu.model.project.AppCategory)1 AppGroup (ai.elimu.model.project.AppGroup)1 Gson (com.google.gson.Gson)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1