Search in sources :

Example 1 with AppCollection

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

the class StringToAppCollectionConverter method convert.

/**
 * Convert AppCollection id to AppCollection entity
 */
public AppCollection convert(String id) {
    if (StringUtils.isBlank(id)) {
        return null;
    } else {
        Long appCollectionId = Long.parseLong(id);
        AppCollection appCollection = appCollectionDao.read(appCollectionId);
        return appCollection;
    }
}
Also used : AppCollection(ai.elimu.model.project.AppCollection)

Example 2 with AppCollection

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

the class AppCollectionRestController method getApplications.

@RequestMapping(value = "/applications", method = RequestMethod.GET)
public String getApplications(HttpServletRequest request, @PathVariable Long appCollectionId, @RequestParam String licenseEmail, @RequestParam String licenseNumber) {
    logger.info("getApplications");
    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
            JSONArray applications = jsonService.getApplications(appCollection);
            jsonObject.put("result", "success");
            jsonObject.put("applications", applications);
        }
    }
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) License(ai.elimu.model.project.License) JSONArray(org.json.JSONArray) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AppCollection

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

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

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

the class AppCategoryListController method handlRequest.

@RequestMapping(value = "/list", method = RequestMethod.GET)
public String handlRequest(Model model, @PathVariable Long projectId, HttpSession session) {
    logger.info("handleRequest");
    logger.info("projectId: " + projectId);
    Project project = projectDao.read(projectId);
    model.addAttribute("project", project);
    List<AppCollection> appCollections = appCollectionDao.readAll(project);
    model.addAttribute("appCollections", appCollections);
    return "project/app-category/list";
}
Also used : Project(ai.elimu.model.project.Project) 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