Search in sources :

Example 26 with Project

use of ai.elimu.model.project.Project 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();
    }
}
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 27 with Project

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

the class AppCategoryDaoTest method testReadAll.

@Test
public void testReadAll() {
    List<AppCategory> appCategories = appCategoryDao.readAll();
    assertThat(appCategories.size(), is(0));
    AppCategory appCategory = new AppCategory();
    appCategoryDao.create(appCategory);
    appCategories.add(appCategory);
    Project project = new Project();
    project.setAppCategories(appCategories);
    projectDao.create(project);
    assertThat(appCategories.size(), is(1));
}
Also used : Project(ai.elimu.model.project.Project) AppCategory(ai.elimu.model.project.AppCategory) Test(org.junit.Test)

Aggregations

Project (ai.elimu.model.project.Project)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 AppCategory (ai.elimu.model.project.AppCategory)14 Contributor (ai.elimu.model.Contributor)12 AppCollection (ai.elimu.model.project.AppCollection)8 AppGroup (ai.elimu.model.project.AppGroup)8 License (ai.elimu.model.project.License)5 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)4 Application (ai.elimu.model.admin.Application)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ByteArrayApkFile (net.dongliu.apk.parser.ByteArrayApkFile)1 ApkMeta (net.dongliu.apk.parser.bean.ApkMeta)1 Test (org.junit.Test)1