From 3e8b74f3629bce6bc3259e7fe5d3723d814d3f81 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Dec 2018 17:56:48 +0400 Subject: [PATCH] fix submit form --- src/main/java/ru/ulstu/paper/controller/PaperController.java | 4 ++++ src/main/java/ru/ulstu/paper/model/Paper.java | 1 + src/main/java/ru/ulstu/paper/model/PaperDto.java | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 36d72fe..7042e1f 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -48,6 +48,10 @@ public class PaperController { @PostMapping(value = "/paper", params = "save") public String save(@Valid PaperDto paperDto, Errors errors) throws IOException { + filterEmptyDeadlines(paperDto); + if (paperDto.getDeadlines().isEmpty()) { + errors.rejectValue("deadlines", "errorCode","Не может быть пустым"); + } if (errors.hasErrors()) { return "/papers/paper"; } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index cf83ddd..6c75f0e 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -158,6 +158,7 @@ public class Paper extends BaseEntity implements UserContainer { public Optional getNextDeadline() { return deadlines .stream() + .filter(deadline -> deadline.getDate() != null) .sorted(Comparator.comparing(Deadline::getDate)) .filter(d -> d.getDate().after(new Date())) .findFirst(); diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 51fd921..9064b5a 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.DeadlineDto; import javax.validation.constraints.Size; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; @@ -21,7 +22,7 @@ public class PaperDto { private Date createDate; private Date updateDate; @NotEmpty - private List deadlines; + private List deadlines = new ArrayList<>(); private String comment; private Boolean locked; private String tmpFileName; @@ -31,7 +32,7 @@ public class PaperDto { private Set authors; public PaperDto() { - + deadlines.add(new DeadlineDto()); } @JsonCreator