From 918079ac890188e3a0f60217bf9053f5bee5b0ae Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 18 Apr 2019 11:20:44 +0400 Subject: [PATCH] #69 fixed not working code, now user can take part in conference and choose participation and deposit --- .../controller/ConferenceController.java | 12 ++ .../ru/ulstu/conference/model/Conference.java | 13 +-- .../ulstu/conference/model/ConferenceDto.java | 9 +- .../conference/model/ConferenceUser.java | 110 ++++++++++++++++++ .../repository/ConferenceUserRepository.java | 4 +- .../conference/service/ConferenceService.java | 14 ++- .../service/ConferenceUserService.java | 12 +- .../ru/ulstu/user/model/UserConference.java | 75 ------------ .../templates/conferences/conference.html | 12 +- 9 files changed, 159 insertions(+), 102 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/model/ConferenceUser.java delete mode 100644 src/main/java/ru/ulstu/user/model/UserConference.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index c25009a..b88a0e6 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -5,12 +5,14 @@ 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.PathVariable; 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.model.ConferenceUser; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; @@ -117,6 +119,16 @@ public class ConferenceController { return conferenceService.getConferencePapers(paperIds); } + @ModelAttribute("allParticipation") + public List getAllParticipation() { + return conferenceService.getAllParticipations(); + } + + @ModelAttribute("allDeposit") + public List getAllDeposit() { + return conferenceService.getAllDeposit(); + } + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index bd1d907..e252e4d 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -7,7 +7,6 @@ import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; -import ru.ulstu.user.model.UserConference; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -60,12 +59,10 @@ public class Conference extends BaseEntity { inverseJoinColumns = {@JoinColumn(name = "paper_id")}) private List papers = new ArrayList<>(); - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "users_conference", - joinColumns = {@JoinColumn(name = "conference_id")}, - inverseJoinColumns = {@JoinColumn(name = "users_id")}) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "conference_id", unique = true) @Fetch(FetchMode.SUBSELECT) - private List users = new ArrayList<>(); + private List users = new ArrayList<>(); public String getTitle() { return title; @@ -131,11 +128,11 @@ public class Conference extends BaseEntity { this.papers = papers; } - public List getUsers() { + public List getUsers() { return users; } - public void setUsers(List users) { + public void setUsers(List users) { this.users = users; } } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index c45cd05..b18e914 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -6,7 +6,6 @@ import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; -import ru.ulstu.user.model.UserConference; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -40,7 +39,7 @@ public class ConferenceDto { private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); private List notSelectedPapers = new ArrayList<>(); - private List users = new ArrayList<>(); + private List users = new ArrayList<>(); private Integer filterUserId; public ConferenceDto() { @@ -57,7 +56,7 @@ public class ConferenceDto { @JsonProperty("deadlines") List deadlines, @JsonProperty("userIds") List userIds, @JsonProperty("paperIds") List paperIds, - @JsonProperty("users") List users, + @JsonProperty("users") List users, @JsonProperty("papers") List papers, @JsonProperty("notSelectedPapers") List notSelectedPapers) { this.id = id; @@ -179,11 +178,11 @@ public class ConferenceDto { this.papers = papers; } - public List getUsers() { + public List getUsers() { return users; } - public void setUsers(List users) { + public void setUsers(List users) { this.users = users; } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceUser.java b/src/main/java/ru/ulstu/conference/model/ConferenceUser.java new file mode 100644 index 0000000..63eeb6d --- /dev/null +++ b/src/main/java/ru/ulstu/conference/model/ConferenceUser.java @@ -0,0 +1,110 @@ +package ru.ulstu.conference.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +@Entity +@Table(name = "users_conference") +public class ConferenceUser extends BaseEntity { + + public enum Participation { + INTRAMURAL("Очная"), + EXTRAMURAL("Заочная"); + + private String participationName; + + Participation(String name) { + this.participationName = name; + } + + public String getParticipation() { + return participationName; + } + } + + public enum Deposit { + ARTICLE("Статья"), + REPORT("Доклад"), + PRESENTATION("Презентация"); + + private String depositName; + + Deposit(String name) { + this.depositName = name; + } + + public String getDeposit() { + return depositName; + } + } + + + @NotNull + @Column(name = "participation", nullable = false) + @Enumerated(value = EnumType.STRING) + private Participation participation = Participation.INTRAMURAL; + + @NotNull + @Column(name = "deposit", nullable = false) + @Enumerated(value = EnumType.STRING) + private Deposit deposit = Deposit.ARTICLE; + + @ManyToOne(optional = false) + @JoinColumn(name = "users_id") + private User user; + + public ConferenceUser() { + } + + public ConferenceUser(User user) { + this.user = user; + } + + @JsonCreator + public ConferenceUser(@JsonProperty("id") Integer id, + @JsonProperty("deposit") Participation participation, + @JsonProperty("deposit") Deposit deposit, + @JsonProperty("user") User user) { + this.setId(id); + this.participation = participation; + this.deposit = deposit; + this.user = user; + } + + + public Participation getParticipation() { + return participation; + } + + public void setParticipation(Participation participation) { + this.participation = participation; + } + + public Deposit getDeposit() { + return deposit; + } + + public void setDeposit(Deposit deposit) { + this.deposit = deposit; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + +} diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java index 0eb546c..5e654d5 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java @@ -1,7 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.user.model.UserConference; +import ru.ulstu.conference.model.ConferenceUser; -public interface ConferenceUserRepository extends JpaRepository { +public interface ConferenceUserRepository extends JpaRepository { } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 58e8da8..f9e662e 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -5,14 +5,15 @@ 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.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; -import ru.ulstu.user.model.UserConference; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.Arrays; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -98,13 +99,21 @@ public class ConferenceService { } public void takePart(ConferenceDto conferenceDto) throws IOException { - conferenceDto.getUsers().add(new UserConference("test", "test", userService.getCurrentUser())); + conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser())); } public List getConferencePapers(List paperIds) { return paperService.findAllNotSelect(paperIds); } + public List getAllParticipations() { + return Arrays.asList(ConferenceUser.Participation.values()); + } + + public List getAllDeposit() { + return Arrays.asList(ConferenceUser.Deposit.values()); + } + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); @@ -114,7 +123,6 @@ public class ConferenceService { conference.setEndDate(conferenceDto.getEndDate()); conference.setPapers(conferenceDto.getPapers()); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); - conferenceDto.getUsers().forEach(user -> userService.findById(user.getUser().getId())); conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { conferenceDto.getPaperIds().forEach(paperId -> diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java index e05491e..f771b2a 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java @@ -2,8 +2,8 @@ package ru.ulstu.conference.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceUserRepository; -import ru.ulstu.user.model.UserConference; import java.util.List; import java.util.stream.Collectors; @@ -17,7 +17,7 @@ public class ConferenceUserService { this.conferenceUserRepository = conferenceUserRepository; } - public List saveOrCreate(List users) { + public List saveOrCreate(List users) { return users .stream() .map(user -> { @@ -26,8 +26,8 @@ public class ConferenceUserService { } @Transactional - public UserConference update(UserConference user) { - UserConference updateUser = conferenceUserRepository.findOne(user.getId()); + public ConferenceUser update(ConferenceUser user) { + ConferenceUser updateUser = conferenceUserRepository.findOne(user.getId()); updateUser.setDeposit(user.getDeposit()); updateUser.setParticipation(user.getParticipation()); conferenceUserRepository.save(updateUser); @@ -35,8 +35,8 @@ public class ConferenceUserService { } @Transactional - public UserConference create(UserConference user) { - UserConference newUser = new UserConference(); + public ConferenceUser create(ConferenceUser user) { + ConferenceUser newUser = new ConferenceUser(); newUser.setDeposit(user.getDeposit()); newUser.setParticipation(user.getParticipation()); newUser.setUser(user.getUser()); diff --git a/src/main/java/ru/ulstu/user/model/UserConference.java b/src/main/java/ru/ulstu/user/model/UserConference.java deleted file mode 100644 index 9afef4c..0000000 --- a/src/main/java/ru/ulstu/user/model/UserConference.java +++ /dev/null @@ -1,75 +0,0 @@ -package ru.ulstu.user.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import ru.ulstu.core.model.BaseEntity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; - -@Entity -@Table(name = "users_conference") -public class UserConference extends BaseEntity { - - @NotNull - @Column(name = "participation", nullable = false) - private String participation; - - @NotNull - @Column(name = "deposit", nullable = false) - private String deposit; - - @ManyToOne(optional = false) - @JoinColumn(name = "users_id") - private User user; - - public UserConference() { - } - - public UserConference(String participation, String deposit, User user) { - this.participation = participation; - this.deposit = deposit; - this.user = user; - } - - @JsonCreator - public UserConference(@JsonProperty("id") Integer id, - @JsonProperty("participation") String participation, - @JsonProperty("deposit") String deposit, - @JsonProperty("user") User user) { - this.setId(id); - this.participation = participation; - this.deposit = deposit; - this.user = user; - } - - - public String getParticipation() { - return participation; - } - - public void setParticipation(String participation) { - this.participation = participation; - } - - public String getDeposit() { - return deposit; - } - - public void setDeposit(String deposit) { - this.deposit = deposit; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - -} diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 35a6926..a1d7049 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -97,20 +97,26 @@
- +
- +