Search in sources :

Example 6 with AppCollection

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

the class AppCollectionCreateController method handleSubmit.

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

Example 7 with AppCollection

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

the class AppCollectionCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, Model model, HttpSession session) {
    logger.info("handleRequest");
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCollection appCollection = new AppCollection();
    appCollection.setProject(project);
    model.addAttribute("appCollection", appCollection);
    return "project/app-collection/create";
}
Also used : Project(ai.elimu.model.project.Project) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with AppCollection

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

the class AppCollectionEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, @PathVariable Long id, Model model, HttpSession session) {
    logger.info("handleRequest");
    // Needed by breadcrumbs
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCollection appCollection = appCollectionDao.read(id);
    model.addAttribute("appCollection", appCollection);
    List<License> licenses = licenseDao.readAll(appCollection);
    model.addAttribute("licenses", licenses);
    return "project/app-collection/edit";
}
Also used : Project(ai.elimu.model.project.Project) License(ai.elimu.model.project.License) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with AppCollection

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

the class LicenseCreateController method sendLicenseInEmail.

/**
 * Sends an e-mail with the License details necessary to be able to use the Appstore application for downloading
 * an AppCollection.
 *
 * @param license The License to send in the e-mail
 * @param contributor The project manager who generated the License
 */
private void sendLicenseInEmail(License license, Contributor projectManager) {
    logger.info("sendLicenseInEmail");
    AppCollection appCollection = license.getAppCollection();
    String to = license.getLicenseEmail();
    String from = "elimu.ai <info@elimu.ai>";
    String subject = "License number - " + appCollection.getName();
    String title = "Your license is ready!";
    String firstName = license.getFirstName();
    String htmlText = "<p>Hi, " + firstName + "</p>";
    htmlText += "<p>We have prepared a license number for you so that you can download and use our software.</p>";
    htmlText += "<h2>License Details</h2>";
    htmlText += "<p>";
    htmlText += "E-mail: " + license.getLicenseEmail() + "<br />";
    htmlText += "Number: " + license.getLicenseNumber() + "<br />";
    htmlText += "</p>";
    htmlText += "<p>";
    htmlText += "First name: " + license.getFirstName() + "<br />";
    htmlText += "Last name: " + license.getLastName() + "<br />";
    if (!StringUtils.isBlank(license.getOrganization())) {
        htmlText += "Organization: " + license.getOrganization() + "<br />";
    }
    htmlText += "</p>";
    htmlText += "<h2>App Collection - " + appCollection.getName() + "</h2>";
    htmlText += "<p>This license is valid for the app collection \"" + appCollection.getName() + "\", which " + "contains the following app categories:</p>";
    htmlText += "<ul>";
    for (AppCategory appCategory : appCollection.getAppCategories()) {
        htmlText += "<li>" + appCategory.getName() + "</li>";
    }
    htmlText += "</ul>";
    htmlText += "<h2>How to Start?</h2>";
    htmlText += "<ol>";
    htmlText += "<li>Install our Appstore application</li>";
    htmlText += "<li>Open Appstore and type your e-mail + license number</li>";
    htmlText += "<li>Download apps</li>";
    htmlText += "</ol>";
    htmlText += "<h2>Download Appstore</h2>";
    htmlText += "<p>At https://github.com/elimu-ai/appstore/releases you can download the latest version of our Appstore " + "application which helps you download the entire collection of educational Android apps.</p>";
    htmlText += "<p>Make sure you download the file named \"ai.elimu.appstore<b>_custom</b>-&lt;version&gt;.apk\". " + "Start by clicking the button below:</p>";
    Mailer.sendHtmlWithButton(to, projectManager.getEmail(), from, subject, title, htmlText, "Download APK", "https://github.com/elimu-ai/appstore/releases");
}
Also used : AppCollection(ai.elimu.model.project.AppCollection) AppCategory(ai.elimu.model.project.AppCategory)

Example 10 with AppCollection

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

the class LicenseCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, @PathVariable Long appCollectionId, Model model, HttpSession session) {
    logger.info("handleRequest");
    // Needed by breadcrumbs
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCollection appCollection = appCollectionDao.read(appCollectionId);
    model.addAttribute("appCollection", appCollection);
    License license = new License();
    license.setLicenseNumber(LicenseGenerator.generateLicenseNumber());
    license.setAppCollection(appCollection);
    model.addAttribute("license", license);
    return "project/license/create";
}
Also used : Project(ai.elimu.model.project.Project) License(ai.elimu.model.project.License) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AppCollection (ai.elimu.model.project.AppCollection)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Project (ai.elimu.model.project.Project)8 License (ai.elimu.model.project.License)7 Contributor (ai.elimu.model.Contributor)3 AppCategory (ai.elimu.model.project.AppCategory)2 JSONObject (org.json.JSONObject)2 AppCollectionGson (ai.elimu.model.gson.project.AppCollectionGson)1 AppGroup (ai.elimu.model.project.AppGroup)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1