Search in sources :

Example 6 with License

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

the class ProjectListController method generateProjects.

private List<Project> generateProjects(Contributor contributor) {
    logger.info("generateProjects");
    List<Project> projects = new ArrayList<>();
    Project project1 = new Project();
    project1.setName("Project #1");
    project1.setManagers(Arrays.asList(contributor));
    projectDao.create(project1);
    projects.add(project1);
    AppCategory appCategory1 = new AppCategory();
    appCategory1.setName("App category #1");
    appCategoryDao.create(appCategory1);
    List<AppCategory> appCategories = new ArrayList<>();
    appCategories.add(appCategory1);
    project1.setAppCategories(appCategories);
    projectDao.update(project1);
    AppGroup appGroup1 = new AppGroup();
    appGroupDao.create(appGroup1);
    List<AppGroup> appGroups = new ArrayList<>();
    appGroups.add(appGroup1);
    appCategory1.setAppGroups(appGroups);
    appCategoryDao.update(appCategory1);
    AppCollection appCollection1 = new AppCollection();
    appCollection1.setName("App collection #1");
    appCollection1.setProject(project1);
    appCollection1.setAppCategories(Arrays.asList(appCategory1));
    appCollectionDao.create(appCollection1);
    License license1 = new License();
    license1.setAppCollection(appCollection1);
    license1.setLicenseEmail("info@elimu.ai");
    license1.setLicenseNumber("bddf-d8f4-2adf-a365");
    license1.setFirstName("Test");
    license1.setLastName("Contributor");
    licenseDao.create(license1);
    return projects;
}
Also used : Project(ai.elimu.model.project.Project) ArrayList(java.util.ArrayList) License(ai.elimu.model.project.License) AppGroup(ai.elimu.model.project.AppGroup) AppCollection(ai.elimu.model.project.AppCollection) AppCategory(ai.elimu.model.project.AppCategory)

Example 7 with License

use of ai.elimu.model.project.License 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 8 with License

use of ai.elimu.model.project.License 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)

Example 9 with License

use of ai.elimu.model.project.License 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 10 with License

use of ai.elimu.model.project.License 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();
}
Also used : AppCollectionGson(ai.elimu.model.gson.project.AppCollectionGson) JSONObject(org.json.JSONObject) License(ai.elimu.model.project.License) AppCollectionGson(ai.elimu.model.gson.project.AppCollectionGson) Gson(com.google.gson.Gson) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

License (ai.elimu.model.project.License)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 AppCollection (ai.elimu.model.project.AppCollection)7 Project (ai.elimu.model.project.Project)5 JSONObject (org.json.JSONObject)3 Contributor (ai.elimu.model.Contributor)2 Application (ai.elimu.model.admin.Application)1 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)1 AppCollectionGson (ai.elimu.model.gson.project.AppCollectionGson)1 AppCategory (ai.elimu.model.project.AppCategory)1 AppGroup (ai.elimu.model.project.AppGroup)1 Gson (com.google.gson.Gson)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1