diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 823f853..6867be5 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -5,20 +5,20 @@ 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; 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; @@ -47,13 +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())); - 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()); } } @@ -104,8 +100,23 @@ public class ConferenceController { return CONFERENCE_PAGE; } - public List getNotSelectPapers(List paperIds) { - return conferenceService.getConferencePapers(paperIds); + @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; + } + + @ModelAttribute("allParticipation") + public List getAllParticipation() { + return conferenceService.getAllParticipations(); + } + + @ModelAttribute("allDeposit") + public List getAllDeposit() { + return conferenceService.getAllDeposit(); } 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 b6affcd..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.User; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -23,9 +22,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") @@ -62,11 +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")}) - private Set users = new HashSet<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "conference_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List users = new ArrayList<>(); public String getTitle() { return title; @@ -132,11 +128,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 ec9ec92..a3f80c9 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -6,16 +6,13 @@ 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 javax.persistence.Temporal; 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,14 +35,12 @@ 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 Integer filterUserId; + private List users = new ArrayList<>(); + private boolean disabledTakePart = false; public ConferenceDto() { } @@ -59,11 +54,12 @@ 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) { + @JsonProperty("notSelectedPapers") List notSelectedPapers, + @JsonProperty("notSelectedPapers") Boolean disabledTakePart) { this.id = id; this.title = title; this.description = description; @@ -77,6 +73,7 @@ public class ConferenceDto { this.users = users; this.papers = papers; this.notSelectedPapers = notSelectedPapers; + this.disabledTakePart = disabledTakePart; } public ConferenceDto(Conference conference) { @@ -90,9 +87,8 @@ 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(); - } public Integer getId() { @@ -159,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; } @@ -183,20 +179,20 @@ 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; } - public Integer getFilterUserId() { - return filterUserId; + public boolean isDisabledTakePart() { + return disabledTakePart; } - public void setFilterUserId(Integer filterUserId) { - this.filterUserId = filterUserId; + public void setDisabledTakePart(boolean disabledTakePart) { + this.disabledTakePart = disabledTakePart; } public List getRemovedDeadlineIds() { 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 new file mode 100644 index 0000000..5e654d5 --- /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.conference.model.ConferenceUser; + +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..6295d5c 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -5,12 +5,16 @@ 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.service.UserService; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -21,17 +25,37 @@ 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 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(); } @@ -88,10 +112,23 @@ public class ConferenceService { conferenceDto.getNotSelectedPapers().add(removedPaper); } - public List getConferencePapers(List paperIds) { + public void takePart(ConferenceDto conferenceDto) throws IOException { + conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser())); + conferenceDto.setDisabledTakePart(true); + } + + public List getNotSelectPapers(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()); @@ -101,6 +138,7 @@ public class ConferenceService { conference.setEndDate(conferenceDto.getEndDate()); conference.setPapers(conferenceDto.getPapers()); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); + conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { conferenceDto.getPaperIds().forEach(paperId -> conference.getPapers().add(paperService.findEntityById(paperId))); @@ -109,4 +147,7 @@ public class ConferenceService { } + public boolean isCurrentUserParticipant(List conferenceUsers) { + return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser())); + } } 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..f771b2a --- /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.model.ConferenceUser; +import ru.ulstu.conference.repository.ConferenceUserRepository; + +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 ConferenceUser update(ConferenceUser user) { + ConferenceUser updateUser = conferenceUserRepository.findOne(user.getId()); + updateUser.setDeposit(user.getDeposit()); + updateUser.setParticipation(user.getParticipation()); + conferenceUserRepository.save(updateUser); + return updateUser; + } + + @Transactional + public ConferenceUser create(ConferenceUser user) { + ConferenceUser newUser = new ConferenceUser(); + 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/repository/UserRepository.java b/src/main/java/ru/ulstu/user/repository/UserRepository.java index f6fbc62..afcdd69 100644 --- a/src/main/java/ru/ulstu/user/repository/UserRepository.java +++ b/src/main/java/ru/ulstu/user/repository/UserRepository.java @@ -33,5 +33,5 @@ public interface UserRepository extends JpaRepository { "AND (u.degree = 'CANDIDATE' OR :hasDegree = FALSE)" + "ORDER BY u.lastName") List filterByAgeAndDegree(@Param("hasAge") boolean hasAge, - @Param("hasDegree") boolean hasDegree); + @Param("hasDegree") boolean hasDegree); } 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 e39b9b1..32651bc 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -24,6 +24,7 @@ + diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index fa3666e..fe19fd0 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -43,7 +43,44 @@ 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; +} + +#take-part[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#take-part[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + .paper-list { height: 200px; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 27c602a..478ebcb 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -97,38 +97,35 @@
-
-
- Пользователь 1 -
-
- очная -
-
- статья -
-
+
+ + + + +
-
- + +
diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 86dbde1..75dec37 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -202,6 +202,7 @@ }); /*]]>*/ +