From 14c28050c7bb6d357b3e2cd2b4c0ef58e6ac8832 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 17 Apr 2019 11:19:23 +0400 Subject: [PATCH 1/8] #65 changed interface --- .../templates/conferences/conference.html | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 27c602a..6d22273 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -97,30 +97,15 @@
-
-
- Пользователь 1 -
-
+
+ + +
- -
-
- Пользователь 1 -
-
- очная -
-
- доклад -
-
-
From 8564f2cf3462ee4d1c45450cc0fc9fdc402994af Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 17 Apr 2019 13:00:48 +0400 Subject: [PATCH 2/8] #69 managed to create a connection through a new entity --- .../ru/ulstu/conference/model/Conference.java | 8 +++--- .../ulstu/conference/model/ConferenceDto.java | 14 ++++------ .../ru/ulstu/user/model/UserConference.java | 28 +++++++++++++++++++ .../db/changelog-20190417_000000-schema.xml | 14 ++++++++++ src/main/resources/db/changelog-master.xml | 1 + 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/UserConference.java create mode 100644 src/main/resources/db/changelog-20190417_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index b6affcd..c9cf20e 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -7,7 +7,7 @@ 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.User; +import ru.ulstu.user.model.UserConference; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -66,7 +66,7 @@ public class Conference extends BaseEntity { @JoinTable(name = "users_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "users_id")}) - private Set users = new HashSet<>(); + private Set users = new HashSet<>(); public String getTitle() { return title; @@ -132,11 +132,11 @@ public class Conference extends BaseEntity { this.papers = papers; } - public Set getUsers() { + public Set getUsers() { return users; } - public void setUsers(Set users) { + public void setUsers(Set 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 ec9ec92..279b13f 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -6,7 +6,7 @@ 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.UserDto; +import ru.ulstu.user.model.UserConference; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -41,10 +41,8 @@ public class ConferenceDto { private Set userIds = new HashSet<>(); private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); - - private List notSelectedPapers = new ArrayList<>(); - private Set users = new HashSet<>(); + private Set users = new HashSet<>(); private Integer filterUserId; public ConferenceDto() { @@ -61,7 +59,7 @@ public class ConferenceDto { @JsonProperty("deadlines") List deadlines, @JsonProperty("userIds") Set userIds, @JsonProperty("paperIds") List paperIds, - @JsonProperty("users") Set users, + @JsonProperty("users") Set users, @JsonProperty("papers") List papers, @JsonProperty("notSelectedPapers") List notSelectedPapers) { this.id = id; @@ -90,7 +88,7 @@ public class ConferenceDto { 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.users = conference.getUsers(); this.papers = conference.getPapers(); } @@ -183,11 +181,11 @@ public class ConferenceDto { this.papers = papers; } - public Set getUsers() { + public Set getUsers() { return users; } - public void setUsers(Set users) { + public void setUsers(Set users) { this.users = users; } diff --git a/src/main/java/ru/ulstu/user/model/UserConference.java b/src/main/java/ru/ulstu/user/model/UserConference.java new file mode 100644 index 0000000..5ae1b12 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/UserConference.java @@ -0,0 +1,28 @@ +package ru.ulstu.user.model; + +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; + +} diff --git a/src/main/resources/db/changelog-20190417_000000-schema.xml b/src/main/resources/db/changelog-20190417_000000-schema.xml new file mode 100644 index 0000000..f0a0d64 --- /dev/null +++ b/src/main/resources/db/changelog-20190417_000000-schema.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 67d3c40..58bbdeb 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -24,5 +24,6 @@ + \ No newline at end of file From 7e4d8d491845e70885e184e02ea6acf514bb2670 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 17 Apr 2019 14:51:19 +0400 Subject: [PATCH 3/8] #69 added method take part in conference --- .../controller/ConferenceController.java | 9 ++++ .../ru/ulstu/conference/model/Conference.java | 9 ++-- .../ulstu/conference/model/ConferenceDto.java | 18 ++++--- .../repository/ConferenceUserRepository.java | 7 +++ .../conference/service/ConferenceService.java | 17 ++++++- .../service/ConferenceUserService.java | 48 +++++++++++++++++++ .../ru/ulstu/user/model/UserConference.java | 47 ++++++++++++++++++ .../templates/conferences/conference.html | 25 ++++++---- 8 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java create mode 100644 src/main/java/ru/ulstu/conference/service/ConferenceUserService.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 823f853..c25009a 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -104,6 +104,15 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "takePart") + public String takePart(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.takePart(conferenceDto); + return CONFERENCE_PAGE; + } + public List getNotSelectPapers(List paperIds) { return conferenceService.getConferencePapers(paperIds); } diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index c9cf20e..bd1d907 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -23,9 +23,7 @@ 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") @@ -66,7 +64,8 @@ public class Conference extends BaseEntity { @JoinTable(name = "users_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "users_id")}) - private Set users = new HashSet<>(); + @Fetch(FetchMode.SUBSELECT) + private List users = new ArrayList<>(); public String getTitle() { return title; @@ -132,11 +131,11 @@ public class Conference extends BaseEntity { this.papers = papers; } - public Set getUsers() { + public List getUsers() { return users; } - public void setUsers(Set 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 279b13f..c45cd05 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -13,9 +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; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -38,11 +36,11 @@ public class ConferenceDto { private Date endDate = new Date(); private List deadlines = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); - private Set userIds = new HashSet<>(); + private List userIds = new ArrayList<>(); private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); private List notSelectedPapers = new ArrayList<>(); - private Set users = new HashSet<>(); + private List users = new ArrayList<>(); private Integer filterUserId; public ConferenceDto() { @@ -57,9 +55,9 @@ public class ConferenceDto { @JsonProperty("beginDate") Date beginDate, @JsonProperty("endDate") Date endDate, @JsonProperty("deadlines") List deadlines, - @JsonProperty("userIds") Set userIds, + @JsonProperty("userIds") List userIds, @JsonProperty("paperIds") List paperIds, - @JsonProperty("users") Set users, + @JsonProperty("users") List users, @JsonProperty("papers") List papers, @JsonProperty("notSelectedPapers") List notSelectedPapers) { this.id = id; @@ -157,11 +155,11 @@ public class ConferenceDto { this.deadlines = deadlines; } - public Set getUserIds() { + public List getUserIds() { return userIds; } - public void setUserIds(Set userIds) { + public void setUserIds(List userIds) { this.userIds = userIds; } @@ -181,11 +179,11 @@ public class ConferenceDto { this.papers = papers; } - public Set getUsers() { + public List getUsers() { return users; } - public void setUsers(Set users) { + public void setUsers(List users) { this.users = users; } diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java new file mode 100644 index 0000000..0eb546c --- /dev/null +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceUserRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.conference.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.user.model.UserConference; + +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 4d267d1..58e8da8 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -9,6 +9,8 @@ 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.List; @@ -21,17 +23,24 @@ public class ConferenceService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; + private final ConferenceUserService conferenceUserService; private final DeadlineService deadlineService; private final PaperService paperService; + private final UserService userService; public ConferenceService(ConferenceRepository conferenceRepository, + ConferenceUserService conferenceUserService, DeadlineService deadlineService, - PaperService paperService) { + PaperService paperService, + UserService userService) { this.conferenceRepository = conferenceRepository; + this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; + this.userService = userService; } + public List findAll() { return conferenceRepository.findAll(); } @@ -88,6 +97,10 @@ public class ConferenceService { conferenceDto.getNotSelectedPapers().add(removedPaper); } + public void takePart(ConferenceDto conferenceDto) throws IOException { + conferenceDto.getUsers().add(new UserConference("test", "test", userService.getCurrentUser())); + } + public List getConferencePapers(List paperIds) { return paperService.findAllNotSelect(paperIds); } @@ -101,6 +114,8 @@ 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 -> conference.getPapers().add(paperService.findEntityById(paperId))); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java new file mode 100644 index 0000000..e05491e --- /dev/null +++ b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java @@ -0,0 +1,48 @@ +package ru.ulstu.conference.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.repository.ConferenceUserRepository; +import ru.ulstu.user.model.UserConference; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class ConferenceUserService { + + private final ConferenceUserRepository conferenceUserRepository; + + public ConferenceUserService(ConferenceUserRepository conferenceUserRepository) { + this.conferenceUserRepository = conferenceUserRepository; + } + + public List saveOrCreate(List users) { + return users + .stream() + .map(user -> { + return user.getId() != null ? update(user) : create(user); + }).collect(Collectors.toList()); + } + + @Transactional + public UserConference update(UserConference user) { + UserConference updateUser = conferenceUserRepository.findOne(user.getId()); + updateUser.setDeposit(user.getDeposit()); + updateUser.setParticipation(user.getParticipation()); + conferenceUserRepository.save(updateUser); + return updateUser; + } + + @Transactional + public UserConference create(UserConference user) { + UserConference newUser = new UserConference(); + newUser.setDeposit(user.getDeposit()); + newUser.setParticipation(user.getParticipation()); + newUser.setUser(user.getUser()); + newUser = conferenceUserRepository.save(newUser); + return newUser; + } + + +} diff --git a/src/main/java/ru/ulstu/user/model/UserConference.java b/src/main/java/ru/ulstu/user/model/UserConference.java index 5ae1b12..9afef4c 100644 --- a/src/main/java/ru/ulstu/user/model/UserConference.java +++ b/src/main/java/ru/ulstu/user/model/UserConference.java @@ -1,5 +1,7 @@ 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; @@ -25,4 +27,49 @@ public class UserConference extends BaseEntity { @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 6d22273..35a6926 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -97,23 +97,28 @@
-
- - +
+ + + + - +
- +
From 918079ac890188e3a0f60217bf9053f5bee5b0ae Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 18 Apr 2019 11:20:44 +0400 Subject: [PATCH 4/8] #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 @@
- +
- +
From 8fd352aaa4263f7d4c02ec41badb30b8891632a4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 18 Apr 2019 14:33:49 +0400 Subject: [PATCH 5/8] #69 added styles --- src/main/resources/public/css/conference.css | 27 +++++++++++++++++++ .../templates/conferences/conference.html | 9 +++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index fa3666e..a608bbd 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -43,7 +43,34 @@ body { .member { margin: 0; + height: 40px; + max-height: 40px; } +.member select { + appearance: none; + -moz-appearance: none; + -webkit-appearance: none; + border: none; + outline: none; + padding: 0.5rem 1.75em 0.5rem 0.5em; + display: inline-block; + background: transparent url("https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-16.png") no-repeat right 7px center; + +} + +.member select:nth-child(4) { + border-right: 1px solid #ced4da; +} + + +.member-name { + padding: .75rem 1.25rem; + cursor: default; + outline: none; + border: none; + border-right: 1px solid #ced4da; +} + .paper-list { height: 200px; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index a1d7049..5c33ba0 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -97,14 +97,13 @@
- -
- - - + type="submit" name="takePart" value="Принять участие" + th:disabled="*{disabledTakePart}"/>
From 9edcebb2f571e607db810d55ffe3b00518a0afa3 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 19 Apr 2019 14:29:08 +0400 Subject: [PATCH 7/8] #69 changed isCurrentUserParticipant --- .../ru/ulstu/conference/service/ConferenceService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index a9e3fac..1bfdebd 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -134,11 +134,6 @@ public class ConferenceService { public boolean isCurrentUserParticipant(List conferenceUsers) { - for (ConferenceUser participant : conferenceUsers) { - if (participant.getUser().getId() == userService.getCurrentUser().getId()) { - return true; - } - } - return false; + return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser())); } } From b623402aa8f8cdbba6a9317f288fbf0ae79bafdb Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 19 Apr 2019 14:39:07 +0400 Subject: [PATCH 8/8] #69 changed method getConference in controller --- .../controller/ConferenceController.java | 19 ++----------------- .../conference/service/ConferenceService.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index dc57bce..6867be5 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -15,12 +15,10 @@ 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; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -49,14 +47,9 @@ public class ConferenceController { @GetMapping("/conference") public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - ConferenceDto conferenceDto = conferenceService.findOneDto(id); - conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); - conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); - modelMap.put("conferenceDto", conferenceDto); + modelMap.put("conferenceDto", conferenceService.getExistConferenceById(id)); } else { - ConferenceDto conferenceDto = new ConferenceDto(); - conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList())); - modelMap.put("conferenceDto", conferenceDto); + modelMap.put("conferenceDto", conferenceService.getNewConference()); } } @@ -116,14 +109,6 @@ public class ConferenceController { return CONFERENCE_PAGE; } - public List getNotSelectPapers(List paperIds) { - return conferenceService.getConferencePapers(paperIds); - } - - public boolean isCurrentUserParticipant(List conferenceUsers) { - return conferenceService.isCurrentUserParticipant(conferenceUsers); - } - @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 1bfdebd..6295d5c 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,6 +13,7 @@ import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -41,6 +42,19 @@ public class ConferenceService { this.userService = userService; } + public ConferenceDto getExistConferenceById(Integer id) { + ConferenceDto conferenceDto = findOneDto(id); + conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); + conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); + return conferenceDto; + } + + public ConferenceDto getNewConference() { + ConferenceDto conferenceDto = new ConferenceDto(); + conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList())); + return conferenceDto; + } + public List findAll() { return conferenceRepository.findAll(); @@ -103,7 +117,7 @@ public class ConferenceService { conferenceDto.setDisabledTakePart(true); } - public List getConferencePapers(List paperIds) { + public List getNotSelectPapers(List paperIds) { return paperService.findAllNotSelect(paperIds); }