From f1f7c1f0f61fa211151d4a2a9b7a947c338a8eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Thu, 18 Apr 2019 16:49:10 +0300 Subject: [PATCH 1/5] #97 cancel button edited --- src/main/resources/templates/projects/project.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 3d356a7..437927a 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -88,8 +88,8 @@ class="alert alert-danger">Incorrect title

- +
@@ -107,7 +107,9 @@ type="submit"> Сохранить -
From 349e7373ffe829ad7a84081575beba6bec0ade36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 22 Apr 2019 14:19:01 +0300 Subject: [PATCH 2/5] #97 save function --- .../project/controller/ProjectController.java | 25 +++++++++++++++++++ .../ulstu/project/service/ProjectService.java | 8 +++++- .../resources/templates/projects/project.html | 15 +++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 3244ccb..7033e6d 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -2,8 +2,10 @@ package ru.ulstu.project.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; +import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.project.model.Project; @@ -11,7 +13,13 @@ import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; import springfox.documentation.annotations.ApiIgnore; +import javax.validation.Valid; +import java.io.IOException; import java.util.List; +import java.util.stream.Collectors; + +import static org.springframework.util.StringUtils.isEmpty; +import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @RequestMapping(value = "/projects") @@ -46,4 +54,21 @@ public class ProjectController { public List getProjectStatuses() { return projectService.getProjectStatuses(); } + + @PostMapping(value = "/project", params = "save") + public String save(@Valid ProjectDto projectDto, Errors errors) throws IOException { + filterEmptyDeadlines(projectDto); + if (projectDto.getDeadlines().isEmpty()) { + errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); + } + hasErrors(errors, "/projects/project"); + projectService.save(projectDto); + return String.format("redirect:%s", "/projects/projects"); + } + + private void filterEmptyDeadlines(ProjectDto projectDto) { + projectDto.setDeadlines(projectDto.getDeadlines().stream() + .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .collect(Collectors.toList())); + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 99d8919..49a6688 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -3,16 +3,20 @@ package ru.ulstu.project.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.grant.model.Grant; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; +import static ru.ulstu.project.model.Project.ProjectStatus.APPLICATION; @Service public class ProjectService { @@ -53,8 +57,10 @@ public class ProjectService { } private Project copyFromDto(Project project, ProjectDto projectDto) { + project.setDescription(projectDto.getDescription()); + project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); project.setTitle(projectDto.getTitle()); - project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines())); + project.setRepository(projectDto.getRepository()); return project; } diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 437927a..a716ff2 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -70,16 +70,21 @@
-
- +
+
- +
- +
-
From 519dd51446de64feacd9a6980ad8a74e56a5d3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 22 Apr 2019 14:31:46 +0300 Subject: [PATCH 3/5] #97 dashboard added --- .../templates/projects/dashboard.html | 4 ++-- .../fragments/projectDashboardFragment.html | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/projects/fragments/projectDashboardFragment.html diff --git a/src/main/resources/templates/projects/dashboard.html b/src/main/resources/templates/projects/dashboard.html index 882c202..c48b035 100644 --- a/src/main/resources/templates/projects/dashboard.html +++ b/src/main/resources/templates/projects/dashboard.html @@ -13,8 +13,8 @@
- -
+ +
diff --git a/src/main/resources/templates/projects/fragments/projectDashboardFragment.html b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html new file mode 100644 index 0000000..1f66c4f --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html @@ -0,0 +1,19 @@ + + + + + + +
+
+
+ +
+
+ title +

status

+
+
+
+ + \ No newline at end of file From 53cc947a17b66a36436945480c08857b7c4940f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 22 Apr 2019 15:48:29 +0300 Subject: [PATCH 4/5] #97 copy from DTO edited --- .../grant/controller/GrantController.java | 2 +- .../ru/ulstu/grant/service/GrantService.java | 2 +- .../java/ru/ulstu/project/model/Project.java | 13 +++++++++ .../ru/ulstu/project/model/ProjectDto.java | 11 ++++++++ .../ulstu/project/service/ProjectService.java | 27 ++++++++++++++----- .../db/changelog-20190422_000000-schema.xml | 16 +++++++++++ src/main/resources/db/changelog-master.xml | 1 + 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/db/changelog-20190422_000000-schema.xml diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 0731188..a0bb916 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -89,7 +89,7 @@ public class GrantController { } @PostMapping(value = "/grant", params = "createProject") - public String createProject(@Valid GrantDto grantDto, Errors errors) { + public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { return GRANT_PAGE; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 8427da3..44c0dfa 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -89,7 +89,7 @@ public class GrantService { return grant; } - public void createProject(GrantDto grantDto) { + public void createProject(GrantDto grantDto) throws IOException { grantDto.setProject( new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle())))); } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 2e0e86c..c971c4b 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -3,6 +3,7 @@ package ru.ulstu.project.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; import javax.persistence.CascadeType; @@ -57,6 +58,10 @@ public class Project extends BaseEntity { @NotNull private String repository; + @ManyToOne + @JoinColumn(name = "file_id") + private FileData application; + public String getTitle() { return title; } @@ -104,4 +109,12 @@ public class Project extends BaseEntity { public void setDeadlines(List deadlines) { this.deadlines = deadlines; } + + public FileData getApplication() { + return application; + } + + public void setApplication(FileData application) { + this.application = application; + } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 6c83d59..4e03365 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -19,6 +19,7 @@ public class ProjectDto { private List deadlines = new ArrayList<>(); private GrantDto grant; private String repository; + private String applicationFileName; public ProjectDto() { } @@ -42,6 +43,7 @@ public class ProjectDto { this.grant = grant; this.repository = repository; this.deadlines = deadlines; + this.applicationFileName = null; } @@ -50,6 +52,7 @@ public class ProjectDto { this.title = project.getTitle(); this.status = project.getStatus(); this.description = project.getDescription(); + this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName(); this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); @@ -110,4 +113,12 @@ public class ProjectDto { public void setDeadlines(List deadlines) { this.deadlines = deadlines; } + + public String getApplicationFileName() { + return applicationFileName; + } + + public void setApplicationFileName(String applicationFileName) { + this.applicationFileName = applicationFileName; + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 49a6688..c15d590 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -3,15 +3,15 @@ package ru.ulstu.project.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; -import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.grant.model.Grant; +import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; +import java.io.IOException; import java.util.Arrays; -import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -24,11 +24,17 @@ public class ProjectService { private final ProjectRepository projectRepository; private final DeadlineService deadlineService; + private final GrantRepository grantRepository; + private final FileService fileService; public ProjectService(ProjectRepository projectRepository, - DeadlineService deadlineService) { + DeadlineService deadlineService, + GrantRepository grantRepository, + FileService fileService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; + this.grantRepository = grantRepository; + this.fileService = fileService; } public List findAll() { @@ -50,21 +56,28 @@ public class ProjectService { } @Transactional - public Project create(ProjectDto projectDto) { + public Project create(ProjectDto projectDto) throws IOException { Project newProject = copyFromDto(new Project(), projectDto); newProject = projectRepository.save(newProject); return newProject; } - private Project copyFromDto(Project project, ProjectDto projectDto) { + private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { project.setDescription(projectDto.getDescription()); project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); project.setTitle(projectDto.getTitle()); + if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) { + project.setGrant(grantRepository.findOne(projectDto.getGrant().getId())); + } project.setRepository(projectDto.getRepository()); + project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines())); + if (projectDto.getApplicationFileName() != null) { + project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName())); + } return project; } - public Project save(ProjectDto projectDto) { + public Project save(ProjectDto projectDto) throws IOException { if (isEmpty(projectDto.getId())) { return create(projectDto); } else { diff --git a/src/main/resources/db/changelog-20190422_000000-schema.xml b/src/main/resources/db/changelog-20190422_000000-schema.xml new file mode 100644 index 0000000..f110910 --- /dev/null +++ b/src/main/resources/db/changelog-20190422_000000-schema.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index d0f1837..1201a65 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -31,4 +31,5 @@ + \ No newline at end of file From 019fe7c652f7fdfc6ed457a52e2d5ac99d4e72c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 23 Apr 2019 10:32:23 +0300 Subject: [PATCH 5/5] #97 adding deadlines --- .../project/controller/ProjectController.java | 16 +++++++++++++++- .../resources/templates/projects/project.html | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 7033e6d..1d0272d 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -61,11 +63,23 @@ public class ProjectController { if (projectDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } - hasErrors(errors, "/projects/project"); + if (errors.hasErrors()) { + return "/projects/project"; + } projectService.save(projectDto); return String.format("redirect:%s", "/projects/projects"); } + @PostMapping(value = "/project", params = "addDeadline") + public String addDeadline(@Valid ProjectDto projectDto, Errors errors) { + filterEmptyDeadlines(projectDto); + if (errors.hasErrors()) { + return "/projects/project"; + } + projectDto.getDeadlines().add(new Deadline()); + return "/projects/project"; + } + private void filterEmptyDeadlines(ProjectDto projectDto) { projectDto.setDeadlines(projectDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index ad4df25..dc3fa6d 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -73,11 +73,11 @@
-
- +
-
+