From be2dd291f69111144da7a1a32ffcc6f4db1e60ec Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 12:48:05 +0400 Subject: [PATCH 01/14] #55 added conference model without user's participation and deposit. May be needed new user model. --- .../ru/ulstu/conference/model/Conference.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index b2851ed..12e1869 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -1,11 +1,60 @@ package ru.ulstu.conference.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; @Entity @Table(name = "conference") public class Conference extends BaseEntity { + + @NotBlank + private String title; + + private String description; + + private String url; + + private int ping; + + @Column(name = "begin_date") + @Temporal(TemporalType.TIMESTAMP) + private Date beginDate = new Date(); + + @Column(name = "end_date") + @Temporal(TemporalType.TIMESTAMP) + private Date endDate = new Date(); + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "conference_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + @OrderBy("date") + private List deadlines = new ArrayList<>(); + + @ManyToMany(fetch = FetchType.EAGER) + private Set papers = new HashSet<>(); + + @ManyToMany(fetch = FetchType.EAGER) + private Set users = new HashSet<>(); } From dc12a671d247e0a9f820f21f7410624368534eaa Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 12:50:12 +0400 Subject: [PATCH 02/14] #55 added setters/getters --- .../ru/ulstu/conference/model/Conference.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 12e1869..10cc709 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -57,4 +57,76 @@ public class Conference extends BaseEntity { @ManyToMany(fetch = FetchType.EAGER) private Set users = new HashSet<>(); + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPing() { + return ping; + } + + public void setPing(int ping) { + this.ping = ping; + } + + public Date getBeginDate() { + return beginDate; + } + + public void setBeginDate(Date beginDate) { + this.beginDate = beginDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public Set getPapers() { + return papers; + } + + public void setPapers(Set papers) { + this.papers = papers; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } } From e3bbade40bb1552277e19130a526df5c9ad68cdc Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 17:39:28 +0400 Subject: [PATCH 03/14] #55 added ConferenceDto --- .../ru/ulstu/conference/model/Conference.java | 10 +- .../ulstu/conference/model/ConferenceDto.java | 185 ++++++++++++++++++ 2 files changed, 194 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 10cc709..8cb1c64 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -13,6 +13,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.OrderBy; @@ -42,7 +43,7 @@ public class Conference extends BaseEntity { @Temporal(TemporalType.TIMESTAMP) private Date beginDate = new Date(); - @Column(name = "end_date") + @Temporal(TemporalType.TIMESTAMP) private Date endDate = new Date(); @@ -52,10 +53,17 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "paper_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "paper_id")}) private Set papers = new HashSet<>(); @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "users_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "users_id")}) private Set users = new HashSet<>(); public String getTitle() { diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index e3f757e..d5c586f 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -1,4 +1,189 @@ package ru.ulstu.conference.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.user.model.UserDto; + +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import static ru.ulstu.core.util.StreamApiUtils.convert; + public class ConferenceDto { + + private Integer id; + @NotEmpty + @Size(min = 2, max = 400) + private String title; + @Size(max = 500) + private String description; + @Size(max = 255) + private String url; + private int ping; + private Date beginDate; + private Date endDate; + @NotEmpty + private List deadlines = new ArrayList<>(); + private Set userIds; + private Set paperIds; + private Set papers; + private Set users; + private Integer filterUserId; + + public ConferenceDto() { + deadlines.add(new Deadline()); + } + + @JsonCreator + public ConferenceDto(@JsonProperty("id") Integer id, + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("url") String url, + @JsonProperty("ping") Integer ping, + @JsonProperty("beginDate") Date beginDate, + @JsonProperty("endDate") Date endDate, + @JsonProperty("deadlines") List deadlines, + @JsonProperty("userIds") Set userIds, + @JsonProperty("paperIds") Set paperIds, + @JsonProperty("users") Set users, + @JsonProperty("papers") Set papers) { + this.id = id; + this.title = title; + this.description = description; + this.url = url; + this.ping = ping; + this.beginDate = beginDate; + this.endDate = endDate; + this.deadlines = deadlines; + this.userIds = userIds; + this.paperIds = paperIds; + this.users = users; + this.papers = papers; + } + + public ConferenceDto(Conference conference) { + this.id = conference.getId(); + this.title = conference.getTitle(); + this.description = conference.getDescription(); + this.url = conference.getUrl(); + this.ping = conference.getPing(); + this.beginDate = conference.getBeginDate(); + this.endDate = conference.getEndDate(); + this.deadlines = conference.getDeadlines(); + this.userIds = convert(conference.getUsers(), user -> user.getId()); + this.paperIds = convert(conference.getPapers(), paper -> paper.getId()); + this.users = convert(conference.getUsers(), UserDto::new); + this.papers = convert(conference.getPapers(), PaperDto::new); + + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPing() { + return ping; + } + + public void setPing(int ping) { + this.ping = ping; + } + + public Date getBeginDate() { + return beginDate; + } + + public void setBeginDate(Date beginDate) { + this.beginDate = beginDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public Set getUserIds() { + return userIds; + } + + public void setUserIds(Set userIds) { + this.userIds = userIds; + } + + public Set getPaperIds() { + return paperIds; + } + + public void setPaperIds(Set paperIds) { + this.paperIds = paperIds; + } + + public Set getPapers() { + return papers; + } + + public void setPapers(Set papers) { + this.papers = papers; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } + + public Integer getFilterUserId() { + return filterUserId; + } + + public void setFilterUserId(Integer filterUserId) { + this.filterUserId = filterUserId; + } } From d189891e8c01622bae211331918575a92819e799 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 17:47:18 +0400 Subject: [PATCH 04/14] #55 added ConferenceFilterDto --- .../controller/ConferenceController.java | 5 +++ .../conference/model/ConferenceFilterDto.java | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index aa871ba..3e4c17e 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -16,4 +16,9 @@ public class ConferenceController { public ConferenceController(ConferenceService paperService) { this.conferenceService = paperService; } +// +// @GetMapping("/papers") +// public void getPapers(ModelMap modelMap) { +// modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null)); +// } } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 379c8b6..c2447e9 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -1,4 +1,43 @@ package ru.ulstu.conference.model; +import java.util.List; + public class ConferenceFilterDto { + + private List papers; + private Integer filterAuthorId; + private Integer year; + + public ConferenceFilterDto() { + } + + public ConferenceFilterDto(List conferenceDtos, Integer filterAuthorId, Integer year) { + this.papers = conferenceDtos; + this.filterAuthorId = filterAuthorId; + this.year = year; + } + + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } + + public Integer getFilterAuthorId() { + return filterAuthorId; + } + + public void setFilterAuthorId(Integer filterAuthorId) { + this.filterAuthorId = filterAuthorId; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } } From 2d04b1b43ac89fdd22f41744b78e617c02b8f18f Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 17:58:22 +0400 Subject: [PATCH 05/14] #55 added findAll method in ConferenceService --- .../controller/ConferenceController.java | 13 +++++--- .../conference/service/ConferenceService.java | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 3e4c17e..167be2a 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -2,7 +2,10 @@ package ru.ulstu.conference.controller; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; import springfox.documentation.annotations.ApiIgnore; @@ -16,9 +19,9 @@ public class ConferenceController { public ConferenceController(ConferenceService paperService) { this.conferenceService = paperService; } -// -// @GetMapping("/papers") -// public void getPapers(ModelMap modelMap) { -// modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null)); -// } + + @GetMapping("/papers") + public void getPapers(ModelMap modelMap) { + modelMap.put("filteredPapers", new ConferenceFilterDto(conferenceService.findAllDto(), null, null)); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index a8147c9..fd9cc5b 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -1,11 +1,20 @@ package ru.ulstu.conference.service; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; +import java.util.List; + +import static ru.ulstu.core.util.StreamApiUtils.convert; + @Service public class ConferenceService { + private final static int MAX_DISPLAY_SIZE = 40; + private final ConferenceRepository conferenceRepository; private final DeadlineService deadlineService; @@ -14,4 +23,28 @@ public class ConferenceService { this.conferenceRepository = conferenceRepository; this.deadlineService = deadlineService; } + + public List findAll() { + return conferenceRepository.findAll(); + } + + public List findAllDto() { + List conferences = convert(findAll(), ConferenceDto::new); + conferences.forEach(conferenceDto -> conferenceDto.setTitle(StringUtils.abbreviate(conferenceDto.getTitle(), MAX_DISPLAY_SIZE))); + return conferences; + } + +// private List sortPapers(List conferences) { +// return conferences.stream().sorted((paper1, paper2) -> { +// int statusCompareResult = +// Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus())) +// .compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())); +// if (statusCompareResult != 0) { +// return statusCompareResult; +// } +// return paper1.getTitle().compareTo(paper2.getTitle()); +// }).collect(toList()); +// } + + } From 9d69f75530618750de2db7a38aa8c91c00e783ec Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 20:26:38 +0400 Subject: [PATCH 06/14] #55 fixes --- .../conference/controller/ConferenceController.java | 6 +++--- .../ulstu/conference/model/ConferenceFilterDto.java | 12 ++++++------ .../resources/templates/conferences/conferences.html | 6 ++++-- .../conferences/fragments/confLineFragment.html | 5 ++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 167be2a..153bd28 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -20,8 +20,8 @@ public class ConferenceController { this.conferenceService = paperService; } - @GetMapping("/papers") - public void getPapers(ModelMap modelMap) { - modelMap.put("filteredPapers", new ConferenceFilterDto(conferenceService.findAllDto(), null, null)); + @GetMapping("/conferences") + public void getConferences(ModelMap modelMap) { + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto(), null, null)); } } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index c2447e9..5b85839 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -4,7 +4,7 @@ import java.util.List; public class ConferenceFilterDto { - private List papers; + private List conferences; private Integer filterAuthorId; private Integer year; @@ -12,17 +12,17 @@ public class ConferenceFilterDto { } public ConferenceFilterDto(List conferenceDtos, Integer filterAuthorId, Integer year) { - this.papers = conferenceDtos; + this.conferences = conferenceDtos; this.filterAuthorId = filterAuthorId; this.year = year; } - public List getPapers() { - return papers; + public List getConferences() { + return conferences; } - public void setPapers(List papers) { - this.papers = papers; + public void setConferences(List conferences) { + this.conferences = conferences; } public Integer getFilterAuthorId() { diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index c725f2b..fa88aaf 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -7,7 +7,7 @@
-
+
@@ -19,7 +19,9 @@
- + +
+
diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index f54a777..c97dfbd 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -6,9 +6,8 @@
- - - + + Date: Fri, 5 Apr 2019 13:21:15 +0400 Subject: [PATCH 07/14] #55 added transition to the page new conference --- .../controller/ConferenceController.java | 14 +++++++++++++- .../conference/service/ConferenceService.java | 14 +++----------- .../templates/conferences/conference.html | 6 ++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 153bd28..291b5fc 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -5,8 +5,10 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; +import ru.ulstu.paper.model.PaperDto; import springfox.documentation.annotations.ApiIgnore; @Controller() @@ -22,6 +24,16 @@ public class ConferenceController { @GetMapping("/conferences") public void getConferences(ModelMap modelMap) { - modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto(), null, null)); + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto(), + null, null)); + } + + @GetMapping("/conference") + public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + if (id != null && id > 0) { + modelMap.put("conferenceDto", conferenceService.findOneDto(id)); + } else { + modelMap.put("conferenceDto", new PaperDto()); + } } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index fd9cc5b..8fcccb0 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -34,17 +34,9 @@ public class ConferenceService { return conferences; } -// private List sortPapers(List conferences) { -// return conferences.stream().sorted((paper1, paper2) -> { -// int statusCompareResult = -// Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus())) -// .compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())); -// if (statusCompareResult != 0) { -// return statusCompareResult; -// } -// return paper1.getTitle().compareTo(paper2.getTitle()); -// }).collect(toList()); -// } + public ConferenceDto findOneDto(Integer id) { + return new ConferenceDto(conferenceRepository.findOne(id)); + } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 59545b5..7e8d0b7 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -18,11 +18,13 @@
- +
- +
From 67bfad22f9c8183f8873f95fa88197042ee581eb Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 5 Apr 2019 16:30:45 +0400 Subject: [PATCH 08/14] #55 added create and update methods --- .../controller/ConferenceController.java | 28 +++++++++++++ .../conference/service/ConferenceService.java | 42 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 291b5fc..0da8d8d 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -3,14 +3,23 @@ package ru.ulstu.conference.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.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.paper.model.PaperDto; import springfox.documentation.annotations.ApiIgnore; +import javax.validation.Valid; +import java.io.IOException; +import java.util.stream.Collectors; + +import static org.springframework.util.StringUtils.isEmpty; + @Controller() @RequestMapping(value = "/conferences") @ApiIgnore @@ -36,4 +45,23 @@ public class ConferenceController { modelMap.put("conferenceDto", new PaperDto()); } } + + @PostMapping(value = "/conference", params = "save") + public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + filterEmptyDeadlines(conferenceDto); + if (conferenceDto.getDeadlines().isEmpty()) { + errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); + } + if (errors.hasErrors()) { + return "/conferences/conference"; + } + conferenceService.save(conferenceDto); + return "redirect:/conferences/conferences"; + } + + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { + conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() + .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .collect(Collectors.toList())); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 8fcccb0..e5afd0f 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -2,13 +2,16 @@ package ru.ulstu.conference.service; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; +import java.io.IOException; import java.util.List; +import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service @@ -38,5 +41,44 @@ public class ConferenceService { return new ConferenceDto(conferenceRepository.findOne(id)); } + public void save(ConferenceDto conferenceDto) throws IOException { + if (isEmpty(conferenceDto.getId())) { + create(conferenceDto); + } else { + update(conferenceDto); + } + } + + @Transactional + public Integer create(ConferenceDto conferenceDto) throws IOException { + Conference newConference = copyFromDto(new Conference(), conferenceDto); + newConference = conferenceRepository.save(newConference); + + + return newConference.getId(); + } + + @Transactional + public Integer update(ConferenceDto conferenceDto) throws IOException { + Conference conference = conferenceRepository.findOne(conferenceDto.getId()); + + conferenceRepository.save(copyFromDto(conference, conferenceDto)); + + return conference.getId(); + } + + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { + conference.setTitle(conferenceDto.getTitle()); + conference.setDescription(conferenceDto.getDescription()); + conference.setUrl(conferenceDto.getUrl()); + conference.setPing(0); + conference.setBeginDate(conference.getBeginDate()); + conference.setEndDate(conference.getEndDate()); + + conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); + + return conference; + } + } From eb524d49d055dc436f47803f6dcacf6a7975ba96 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 5 Apr 2019 18:01:43 +0400 Subject: [PATCH 09/14] #55 added html side, don't work, because can't parse date, like in deadlines --- .../controller/ConferenceController.java | 9 +++--- .../ru/ulstu/conference/model/Conference.java | 9 ++++-- .../templates/conferences/conference.html | 30 ++++++++++++------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 0da8d8d..f3c4864 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; -import ru.ulstu.paper.model.PaperDto; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -27,8 +26,8 @@ public class ConferenceController { private final ConferenceService conferenceService; - public ConferenceController(ConferenceService paperService) { - this.conferenceService = paperService; + public ConferenceController(ConferenceService conferenceService) { + this.conferenceService = conferenceService; } @GetMapping("/conferences") @@ -42,7 +41,7 @@ public class ConferenceController { if (id != null && id > 0) { modelMap.put("conferenceDto", conferenceService.findOneDto(id)); } else { - modelMap.put("conferenceDto", new PaperDto()); + modelMap.put("conferenceDto", new ConferenceDto()); } } @@ -53,10 +52,12 @@ public class ConferenceController { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } if (errors.hasErrors()) { + System.out.println("я здесь 2"); return "/conferences/conference"; } conferenceService.save(conferenceDto); return "redirect:/conferences/conferences"; + } private void filterEmptyDeadlines(ConferenceDto conferenceDto) { diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 8cb1c64..1c824b3 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -3,6 +3,7 @@ package ru.ulstu.conference.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; @@ -41,11 +42,13 @@ public class Conference extends BaseEntity { @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) - private Date beginDate = new Date(); - + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date beginDate; + @Column(name = "end_date") @Temporal(TemporalType.TIMESTAMP) - private Date endDate = new Date(); + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date endDate; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "conference_id", unique = true) diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 7e8d0b7..3330bed 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -28,36 +28,44 @@
-
-
-
- -
+
+ - + placeholder="Описание" + th:field="*{deadlines[__${rowStat.index}__].description}"/> + Удалить + alt="Удалить" + th:onclick="|$('#deadlines${rowStat.index}\\.description').val(''); + $('#deadlines${rowStat.index}\\.date').val(''); + $('#addDeadline').click();|"/>
+

Incorrect title

- +
- +
From 926cd02096ebb358765be277e677189b057f3abf Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 6 Apr 2019 11:05:30 +0400 Subject: [PATCH 10/14] #55 fixed adding to DB --- src/main/java/ru/ulstu/conference/model/ConferenceDto.java | 7 +++++++ .../ru/ulstu/conference/service/ConferenceService.java | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index d5c586f..a9414c1 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -3,10 +3,13 @@ package ru.ulstu.conference.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.UserDto; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; @@ -26,7 +29,11 @@ public class ConferenceDto { @Size(max = 255) private String url; private int ping; + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date beginDate; + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date endDate; @NotEmpty private List deadlines = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5afd0f..c28c637 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -72,8 +72,8 @@ public class ConferenceService { conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); conference.setPing(0); - conference.setBeginDate(conference.getBeginDate()); - conference.setEndDate(conference.getEndDate()); + conference.setBeginDate(conferenceDto.getBeginDate()); + conference.setEndDate(conferenceDto.getEndDate()); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); From 3e5aeaf29062aadc44b68aba3b8d477e09c8673a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 6 Apr 2019 14:41:10 +0400 Subject: [PATCH 11/14] #55 fast fixes --- .../ru/ulstu/conference/controller/ConferenceController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index f3c4864..d957e76 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -52,7 +52,6 @@ public class ConferenceController { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } if (errors.hasErrors()) { - System.out.println("я здесь 2"); return "/conferences/conference"; } conferenceService.save(conferenceDto); From db43da9ec0e4b5806f65052cbaf2e6221f62b39a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 7 Apr 2019 10:01:44 +0400 Subject: [PATCH 12/14] #55 added nav controller --- .../controller/ConferenceController.java | 11 +++++++---- .../controller/NavigationController.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/controller/NavigationController.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index d957e76..c3b4917 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -18,6 +18,11 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; +import static ru.ulstu.conference.controller.NavigationController.CONFERENCES_PAGE; +import static ru.ulstu.conference.controller.NavigationController.CONFERENCE_PAGE; +import static ru.ulstu.conference.controller.NavigationController.REDIRECT_TO; +import static ru.ulstu.grant.controller.Navigation.hasErrors; + @Controller() @RequestMapping(value = "/conferences") @@ -51,11 +56,9 @@ public class ConferenceController { if (conferenceDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } - if (errors.hasErrors()) { - return "/conferences/conference"; - } + hasErrors(errors, CONFERENCE_PAGE); conferenceService.save(conferenceDto); - return "redirect:/conferences/conferences"; + return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/controller/NavigationController.java b/src/main/java/ru/ulstu/conference/controller/NavigationController.java new file mode 100644 index 0000000..84f88ad --- /dev/null +++ b/src/main/java/ru/ulstu/conference/controller/NavigationController.java @@ -0,0 +1,18 @@ +package ru.ulstu.conference.controller; + +import org.springframework.validation.Errors; + +public class NavigationController { + + public static final String REDIRECT_TO = "redirect:%s"; + public static final String CONFERENCES_PAGE = "/conferences/conferences"; + public static final String CONFERENCE_PAGE = "/conferences/conference"; + + public static String hasErrors(Errors errors, String page) { + if (errors.hasErrors()) { + return page; + } + return null; + } + +} From c49b56916c14ac493440522767d49d04e49fb677 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 7 Apr 2019 10:08:13 +0400 Subject: [PATCH 13/14] #55 added initialization of fields in ConferenceDto --- .../ulstu/conference/model/ConferenceDto.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index a9414c1..277e783 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -13,6 +13,7 @@ import javax.persistence.TemporalType; import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -25,22 +26,22 @@ public class ConferenceDto { @Size(min = 2, max = 400) private String title; @Size(max = 500) - private String description; + private String description = ""; @Size(max = 255) - private String url; - private int ping; + private String url = ""; + private int ping = 0; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date beginDate; + private Date beginDate = new Date(); @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date endDate; + private Date endDate = new Date(); @NotEmpty private List deadlines = new ArrayList<>(); - private Set userIds; - private Set paperIds; - private Set papers; - private Set users; + private Set userIds = new HashSet<>(); + private Set paperIds = new HashSet<>(); + private Set papers = new HashSet<>(); + private Set users = new HashSet<>(); private Integer filterUserId; public ConferenceDto() { From e350f8b3c161ca4f23445100b6b2a333e726d808 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 8 Apr 2019 07:40:26 +0400 Subject: [PATCH 14/14] #55 refactor controller navigation, fix conference edit url --- .../controller/ConferenceController.java | 11 +++++------ .../conference/model/ConferenceFilterDto.java | 4 ++++ .../controller/Navigation.java} | 9 +++++---- .../ulstu/grant/controller/GrantController.java | 8 ++++---- .../ru/ulstu/grant/controller/Navigation.java | 16 ---------------- .../conferences/fragments/confLineFragment.html | 2 +- 6 files changed, 19 insertions(+), 31 deletions(-) rename src/main/java/ru/ulstu/{conference/controller/NavigationController.java => core/controller/Navigation.java} (69%) delete mode 100644 src/main/java/ru/ulstu/grant/controller/Navigation.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index c3b4917..528975c 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -18,10 +18,10 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.conference.controller.NavigationController.CONFERENCES_PAGE; -import static ru.ulstu.conference.controller.NavigationController.CONFERENCE_PAGE; -import static ru.ulstu.conference.controller.NavigationController.REDIRECT_TO; -import static ru.ulstu.grant.controller.Navigation.hasErrors; +import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE; +import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; +import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @@ -37,8 +37,7 @@ public class ConferenceController { @GetMapping("/conferences") public void getConferences(ModelMap modelMap) { - modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto(), - null, null)); + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto())); } @GetMapping("/conference") diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 5b85839..37878b2 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -17,6 +17,10 @@ public class ConferenceFilterDto { this.year = year; } + public ConferenceFilterDto(List conferenceDtos) { + this(conferenceDtos, null, null); + } + public List getConferences() { return conferences; } diff --git a/src/main/java/ru/ulstu/conference/controller/NavigationController.java b/src/main/java/ru/ulstu/core/controller/Navigation.java similarity index 69% rename from src/main/java/ru/ulstu/conference/controller/NavigationController.java rename to src/main/java/ru/ulstu/core/controller/Navigation.java index 84f88ad..caea429 100644 --- a/src/main/java/ru/ulstu/conference/controller/NavigationController.java +++ b/src/main/java/ru/ulstu/core/controller/Navigation.java @@ -1,10 +1,12 @@ -package ru.ulstu.conference.controller; +package ru.ulstu.core.controller; import org.springframework.validation.Errors; -public class NavigationController { - +public class Navigation { public static final String REDIRECT_TO = "redirect:%s"; + public static final String GRANTS_PAGE = "/grants/grants"; + public static final String GRANT_PAGE = "/grants/grant"; + public static final String CONFERENCES_PAGE = "/conferences/conferences"; public static final String CONFERENCE_PAGE = "/conferences/conference"; @@ -14,5 +16,4 @@ public class NavigationController { } return null; } - } diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 65b11dc..a7dc948 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -21,10 +21,10 @@ import java.util.List; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.grant.controller.Navigation.GRANTS_PAGE; -import static ru.ulstu.grant.controller.Navigation.GRANT_PAGE; -import static ru.ulstu.grant.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.grant.controller.Navigation.hasErrors; +import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE; +import static ru.ulstu.core.controller.Navigation.GRANT_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; +import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() diff --git a/src/main/java/ru/ulstu/grant/controller/Navigation.java b/src/main/java/ru/ulstu/grant/controller/Navigation.java deleted file mode 100644 index bf1626f..0000000 --- a/src/main/java/ru/ulstu/grant/controller/Navigation.java +++ /dev/null @@ -1,16 +0,0 @@ -package ru.ulstu.grant.controller; - -import org.springframework.validation.Errors; - -public class Navigation { - public static final String REDIRECT_TO = "redirect:%s"; - public static final String GRANTS_PAGE = "/grants/grants"; - public static final String GRANT_PAGE = "/grants/grant"; - - public static String hasErrors(Errors errors, String page) { - if (errors.hasErrors()) { - return page; - } - return null; - } -} diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index c97dfbd..317da03 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -6,7 +6,7 @@