Search in sources :

Example 6 with Project

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

the class AppEditController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@PathVariable Long projectId, @PathVariable Long appCategoryId, @PathVariable Long appGroupId, @PathVariable Long applicationId, HttpSession session, @Valid Application application, BindingResult result, Model model) {
    logger.info("handleSubmit");
    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);
    if (result.hasErrors()) {
        model.addAttribute("application", application);
        List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
        model.addAttribute("applicationVersions", applicationVersions);
        model.addAttribute("applicationStatuses", ApplicationStatus.values());
        return "project/app/edit";
    } else {
        applicationDao.update(application);
        if (application.getApplicationStatus() == ApplicationStatus.DELETED) {
            // Delete corresponding ApplicationVersions
            List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
            for (ApplicationVersion applicationVersion : applicationVersions) {
                applicationVersionDao.delete(applicationVersion);
            }
            // Refresh REST API cache
            // jsonService.refreshApplicationsInAppCollection(appCollection);
            jsonService.refreshApplicationsInAppCollection();
            if (EnvironmentContextLoaderListener.env == Environment.PROD) {
                // Notify project members in Slack
                Contributor contributor = (Contributor) session.getAttribute("contributor");
                String text = URLEncoder.encode(contributor.getFirstName() + " just deleted an Application:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Category: \"" + appCategory.getName() + "\"\n" + "• Package name: \"" + application.getPackageName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-category/" + appCategory.getId() + "/app-group/" + appGroup.getId() + "/app/" + application.getId() + "/edit";
                SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
            }
        }
        return "redirect:/project/" + projectId + "/app-category/" + appCategoryId + "/app-group/" + appGroupId + "/app/list";
    }
}
Also used : Project(ai.elimu.model.project.Project) ApplicationVersion(ai.elimu.model.admin.ApplicationVersion) Contributor(ai.elimu.model.Contributor) AppGroup(ai.elimu.model.project.AppGroup) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Project

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

the class AppCategoryEditController 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);
    AppCategory appCategory = appCategoryDao.read(id);
    model.addAttribute("appCategory", appCategory);
    return "project/app-category/edit";
}
Also used : Project(ai.elimu.model.project.Project) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Project

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

the class AppCategoryEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @Valid AppCategory appCategory, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Disallow app categories with identical name
    Project project = projectDao.read(projectId);
    List<AppCategory> existingAppCategories = project.getAppCategories();
    for (AppCategory existingAppCategory : existingAppCategories) {
        if (existingAppCategory.getName().equals(appCategory.getName()) && !existingAppCategory.getId().equals(appCategory.getId())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCategory", appCategory);
        return "project/app-category/edit";
    } else {
        appCategoryDao.update(appCategory);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an App Category:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Category: \"" + appCategory.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.getId() + "/app-category/list#" + appCategory.getId();
    }
}
Also used : Project(ai.elimu.model.project.Project) Contributor(ai.elimu.model.Contributor) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Project

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

the class AppCollectionEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @PathVariable Long projectId, @Valid AppCollection appCollection, BindingResult result, Model model) {
    logger.info("handleSubmit");
    // Disallow app collections with identical name
    Project project = projectDao.read(projectId);
    List<AppCollection> existingAppCollections = appCollectionDao.readAll(project);
    for (AppCollection existingAppCollection : existingAppCollections) {
        if (existingAppCollection.getName().equals(appCollection.getName()) && !existingAppCollection.getId().equals(appCollection.getId())) {
            result.rejectValue("name", "NonUnique");
            break;
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("project", project);
        model.addAttribute("appCollection", appCollection);
        List<License> licenses = licenseDao.readAll(appCollection);
        model.addAttribute("licenses", licenses);
        return "project/app-collection/edit";
    } else {
        appCollectionDao.update(appCollection);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            // Notify project members in Slack
            Contributor contributor = (Contributor) session.getAttribute("contributor");
            String text = URLEncoder.encode(contributor.getFirstName() + " just updated an App Collection:\n" + "• Project: \"" + project.getName() + "\"\n" + "• App Collection: \"" + appCollection.getName() + "\"\n" + "See ") + "http://elimu.ai/project/" + project.getId() + "/app-collection/edit/" + appCollection.getId();
            SlackApiHelper.postMessage("G6UR7UH2S", text, null, null);
        }
        return "redirect:/project/" + project.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 Project

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

the class AppGroupCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, @PathVariable Long appCategoryId, Model model, HttpSession session) {
    logger.info("handleRequest");
    // Needed by breadcrumbs
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    AppCategory appCategory = appCategoryDao.read(appCategoryId);
    model.addAttribute("appCategory", appCategory);
    AppGroup appGroup = new AppGroup();
    model.addAttribute("appGroup", appGroup);
    return "project/app-group/create";
}
Also used : Project(ai.elimu.model.project.Project) AppGroup(ai.elimu.model.project.AppGroup) AppCategory(ai.elimu.model.project.AppCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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