use of ai.elimu.model.admin.Application in project webapp by elimu-ai.
the class ApplicationVersionCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(ApplicationVersion applicationVersion, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model, HttpSession session) {
logger.info("handleSubmit");
logger.info("applicationVersion.getVersionCode(): " + applicationVersion.getVersionCode());
if (applicationVersion.getVersionCode() == null) {
result.rejectValue("versionCode", "NotNull");
} else {
// Verify that the versionCode is higher than previous ones
List<ApplicationVersion> existingApplicationVersions = applicationVersionDao.readAll(applicationVersion.getApplication());
for (ApplicationVersion existingApplicationVersion : existingApplicationVersions) {
if (existingApplicationVersion.getVersionCode() >= applicationVersion.getVersionCode()) {
result.rejectValue("versionCode", "TooLow");
break;
}
}
}
if (multipartFile.isEmpty()) {
result.rejectValue("bytes", "NotNull");
} else {
try {
byte[] bytes = multipartFile.getBytes();
if (applicationVersion.getBytes() != null) {
String originalFileName = multipartFile.getOriginalFilename();
logger.info("originalFileName: " + originalFileName);
if (!originalFileName.endsWith(".apk")) {
result.rejectValue("bytes", "typeMismatch");
}
String contentType = multipartFile.getContentType();
logger.info("contentType: " + contentType);
applicationVersion.setContentType(contentType);
applicationVersion.setBytes(bytes);
Integer fileSizeInKb = bytes.length / 1024;
logger.info("fileSizeInKb: " + fileSizeInKb + " (" + (fileSizeInKb / 1024) + "MB)");
applicationVersion.setFileSizeInKb(fileSizeInKb);
String checksumMd5 = ChecksumHelper.calculateMD5(bytes);
logger.info("checksumMd5: " + checksumMd5);
applicationVersion.setChecksumMd5(checksumMd5);
ByteArrayApkFile byteArrayApkFile = new ByteArrayApkFile(bytes);
ApkMeta apkMeta = byteArrayApkFile.getApkMeta();
String versionName = apkMeta.getVersionName();
logger.info("versionName: " + versionName);
applicationVersion.setVersionName(versionName);
String label = apkMeta.getLabel();
logger.info("label: " + label);
applicationVersion.setLabel(label);
Integer minSdkVersion = Integer.valueOf(apkMeta.getMinSdkVersion());
logger.info("minSdkVersion: " + minSdkVersion);
applicationVersion.setMinSdkVersion(minSdkVersion);
byte[] icon = byteArrayApkFile.getIconFile().getData();
logger.info("icon.length: " + (icon.length / 1024) + "kB");
applicationVersion.setIcon(icon);
} else {
result.rejectValue("bytes", "NotNull");
}
} catch (IOException ex) {
logger.error(ex);
}
}
if (result.hasErrors()) {
model.addAttribute("applicationVersion", applicationVersion);
return "admin/application-version/create";
} else {
Contributor contributor = (Contributor) session.getAttribute("contributor");
applicationVersion.setContributor(contributor);
applicationVersion.setTimeUploaded(Calendar.getInstance());
applicationVersionDao.create(applicationVersion);
// Update the Application entity to reflect the latest changes
Application application = applicationVersion.getApplication();
if (application.getApplicationStatus() == ApplicationStatus.MISSING_APK) {
// If first APK file, change status of application to "ACTIVE"
application.setApplicationStatus(ApplicationStatus.ACTIVE);
}
applicationDao.update(application);
// Refresh REST API cache
jsonService.refreshApplications(application.getLocale());
boolean isInfrastructureApp = "ai.elimu.appstore".equals(application.getPackageName()) || "ai.elimu.appstore_custom".equals(application.getPackageName()) || "ai.elimu.analytics".equals(application.getPackageName()) || "ai.elimu.launcher".equals(application.getPackageName()) || "ai.elimu.launcher_custom".equals(application.getPackageName());
if (isInfrastructureApp) {
jsonService.refreshApplicationsInAppCollection();
}
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just uploaded a new APK version:\n" + "• Language: " + applicationVersion.getApplication().getLocale().getLanguage() + "\n" + "• Package name: \"" + applicationVersion.getApplication().getPackageName() + "\"\n" + "• Version: " + applicationVersion.getVersionCode() + "\n" + "• Start command: " + applicationVersion.getStartCommand());
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.DEVELOPMENT), text, iconUrl, null);
}
return "redirect:/admin/application/edit/" + applicationVersion.getApplication().getId();
}
}
use of ai.elimu.model.admin.Application in project webapp by elimu-ai.
the class AppEditController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, @PathVariable Long appCategoryId, @PathVariable Long appGroupId, @PathVariable Long applicationId, Model model) {
logger.info("handleRequest");
Project project = projectDao.read(projectId);
model.addAttribute("project", project);
AppCategory appCategory = appCategoryDao.read(appCategoryId);
model.addAttribute("appCategory", appCategory);
AppGroup appGroup = appGroupDao.read(appGroupId);
model.addAttribute("appGroup", appGroup);
Application application = applicationDao.read(applicationId);
model.addAttribute("application", application);
List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
model.addAttribute("applicationVersions", applicationVersions);
model.addAttribute("applicationStatuses", ApplicationStatus.values());
return "project/app/edit";
}
use of ai.elimu.model.admin.Application in project webapp by elimu-ai.
the class StringToApplicationConverter method convert.
/**
* Convert Application id to Application entity
*/
public Application convert(String id) {
if (StringUtils.isBlank(id)) {
return null;
} else {
Long applicationId = Long.parseLong(id);
Application application = applicationDao.read(applicationId);
return application;
}
}
use of ai.elimu.model.admin.Application 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;
}
use of ai.elimu.model.admin.Application in project webapp by elimu-ai.
the class ApplicationDaoTest method testCacheable.
@Test
public void testCacheable() {
Locale locale = Locale.values()[(int) (Math.random() * Locale.values().length)];
logger.info("locale: " + locale);
List<Application> applications = applicationDao.readAll(locale);
assertThat(applications.isEmpty(), is(true));
}
Aggregations