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;
}
}
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();
}
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();
}
}
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;
}
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";
}
Aggregations