use of ai.elimu.model.project.AppCollection in project webapp by elimu-ai.
the class LicenseCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @PathVariable Long appCollectionId, @Valid License license, BindingResult result, Model model) {
logger.info("handleSubmit");
// Needed by breadcrumbs and Slack post
Project project = projectDao.read(projectId);
model.addAttribute("project", project);
AppCollection appCollection = appCollectionDao.read(appCollectionId);
model.addAttribute("appCollection", appCollection);
// Disallow Licenses with identical e-mail
List<License> existingLicenses = licenseDao.readAll(appCollection);
for (License existingLicence : existingLicenses) {
if (existingLicence.getLicenseEmail().equals(license.getLicenseEmail())) {
result.rejectValue("licenseEmail", "NonUnique");
break;
}
}
if (result.hasErrors()) {
model.addAttribute("license", license);
return "project/license/create";
} else {
licenseDao.create(license);
// Send license information via e-mail
Contributor contributor = (Contributor) session.getAttribute("contributor");
sendLicenseInEmail(license, contributor);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
// Notify project members in Slack
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new License:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "• E-mail: \"" + license.getLicenseEmail() + "\"\n" + "• Number: \"" + license.getLicenseNumber() + "\"\n" + "• First name: \"" + license.getFirstName() + "\"\n" + "• Last name: \"" + license.getLastName() + "\"\n" + (StringUtils.isBlank(license.getOrganization()) ? "" : "• Organization: \"" + license.getOrganization() + "\"\n") + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
}
return "redirect:/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
}
}
use of ai.elimu.model.project.AppCollection in project webapp by elimu-ai.
the class AppCollectionRestController method get.
@RequestMapping(method = RequestMethod.GET)
public String get(HttpServletRequest request, @PathVariable Long appCollectionId, @RequestParam String licenseEmail, @RequestParam String licenseNumber) {
logger.info("get");
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
AppCollectionGson appCollectionGson = JavaToGsonConverter.getAppCollectionGson(appCollection);
String appCollectionJson = new Gson().toJson(appCollectionGson);
jsonObject.put("result", "success");
jsonObject.put("appCollection", new JSONObject(appCollectionJson));
}
}
logger.info("jsonObject: " + jsonObject);
return jsonObject.toString();
}
Aggregations