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();
}
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();
}
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();
}
}
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"));
}
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);
}
}
}
Aggregations