use of ai.elimu.model.project.Project in project webapp by elimu-ai.
the class AdminProjectCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
logger.info("handleRequest");
Project project = new Project();
model.addAttribute("project", project);
return "admin/project/create";
}
use of ai.elimu.model.project.Project in project webapp by elimu-ai.
the class AdminProjectCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Project project, BindingResult result, Model model) {
logger.info("handleSubmit");
Project existingProject = projectDao.read(project.getName());
if (existingProject != null) {
result.rejectValue("name", "NonUnique");
}
if (result.hasErrors()) {
model.addAttribute("project", project);
return "admin/project/create";
} else {
projectDao.create(project);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
Contributor contributor = (Contributor) session.getAttribute("contributor");
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new project: \"" + project.getName() + "\"");
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage("G6UR7UH2S", text, iconUrl, null);
}
return "redirect:/admin/project/list#" + project.getId();
}
}
use of ai.elimu.model.project.Project in project webapp by elimu-ai.
the class AdminProjectEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Project project, BindingResult result, Model model) {
logger.info("handleSubmit");
Project existingProject = projectDao.read(project.getName());
if ((existingProject != null) && !existingProject.getId().equals(project.getId())) {
result.rejectValue("name", "NonUnique");
}
Contributor contributor = (Contributor) session.getAttribute("contributor");
if (result.hasErrors()) {
model.addAttribute("project", project);
List<Contributor> contributors = contributorDao.readAll();
model.addAttribute("managers", contributors);
return "admin/project/edit";
} else {
projectDao.update(project);
// Send invitation e-mail to newly added managers
if (project.getManagers() != null) {
for (Contributor manager : project.getManagers()) {
boolean isManagerAddedAlready = false;
if ((existingProject != null) && (existingProject.getManagers() != null)) {
for (Contributor existingManager : existingProject.getManagers()) {
if (existingManager.getId().equals(manager.getId())) {
isManagerAddedAlready = true;
break;
}
}
}
logger.info("isManagerAddedAlready: " + isManagerAddedAlready + ", manager.getEmail(): " + manager.getEmail());
if (!isManagerAddedAlready) {
// Update role so that the contributor can access the /project page
manager.getRoles().add(Role.PROJECT_MANAGER);
contributorDao.update(manager);
// Send inviation e-mail
String to = manager.getEmail();
String from = "elimu.ai <info@elimu.ai>";
String subject = "You have been added as a manager";
String title = project.getName();
String firstName = StringUtils.isBlank(manager.getFirstName()) ? "" : manager.getFirstName();
String htmlText = "<p>Hi, " + firstName + "</p>";
htmlText += "<p>" + contributor.getFirstName() + " has added you as a manager of the \"" + project.getName() + "\" project.</p>";
htmlText += "<p>To create a new app collection, click the button below:</p>";
String buttonUrl = "http://elimu.ai/project";
if (EnvironmentContextLoaderListener.env == Environment.TEST) {
buttonUrl = "http://test.elimu.ai/project";
}
Mailer.sendHtmlWithButton(to, null, from, subject, title, htmlText, "Open project", buttonUrl);
// Notify Slack channel
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just added a project manager to \"" + project.getName() + "\": " + manager.getFirstName() + " " + manager.getLastName());
String iconUrl = manager.getImageUrl();
SlackApiHelper.postMessage("G6UR7UH2S", text, iconUrl, null);
}
}
}
}
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just edited a project: \"" + project.getName() + "\"");
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage("G6UR7UH2S", text, iconUrl, null);
}
return "redirect:/admin/project/list#" + project.getId();
}
}
use of ai.elimu.model.project.Project 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.Project in project webapp by elimu-ai.
the class AppEditController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(@PathVariable Long projectId, @PathVariable Long appCategoryId, @PathVariable Long appGroupId, @PathVariable Long applicationId, Model model) {
logger.info("handleRequest");
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);
Application application = applicationDao.read(applicationId);
model.addAttribute("application", application);
List<ApplicationVersion> applicationVersions = applicationVersionDao.readAll(application);
model.addAttribute("applicationVersions", applicationVersions);
model.addAttribute("applicationStatuses", ApplicationStatus.values());
return "project/app/edit";
}
Aggregations