#69 fixed not working code, now user can take part in conference and choose participation and deposit

This commit is contained in:
Nightblade73 2019-04-18 11:20:44 +04:00
parent 7e4d8d4918
commit 918079ac89
9 changed files with 159 additions and 102 deletions

View File

@ -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<ConferenceUser.Participation> getAllParticipation() {
return conferenceService.getAllParticipations();
}
@ModelAttribute("allDeposit")
public List<ConferenceUser.Deposit> getAllDeposit() {
return conferenceService.getAllDeposit();
}
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -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<Paper> 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<UserConference> users = new ArrayList<>();
private List<ConferenceUser> users = new ArrayList<>();
public String getTitle() {
return title;
@ -131,11 +128,11 @@ public class Conference extends BaseEntity {
this.papers = papers;
}
public List<UserConference> getUsers() {
public List<ConferenceUser> getUsers() {
return users;
}
public void setUsers(List<UserConference> users) {
public void setUsers(List<ConferenceUser> users) {
this.users = users;
}
}

View File

@ -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<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>();
private List<Paper> notSelectedPapers = new ArrayList<>();
private List<UserConference> users = new ArrayList<>();
private List<ConferenceUser> users = new ArrayList<>();
private Integer filterUserId;
public ConferenceDto() {
@ -57,7 +56,7 @@ public class ConferenceDto {
@JsonProperty("deadlines") List<Deadline> deadlines,
@JsonProperty("userIds") List<Integer> userIds,
@JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("users") List<UserConference> users,
@JsonProperty("users") List<ConferenceUser> users,
@JsonProperty("papers") List<Paper> papers,
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
this.id = id;
@ -179,11 +178,11 @@ public class ConferenceDto {
this.papers = papers;
}
public List<UserConference> getUsers() {
public List<ConferenceUser> getUsers() {
return users;
}
public void setUsers(List<UserConference> users) {
public void setUsers(List<ConferenceUser> users) {
this.users = users;
}

View File

@ -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;
}
}

View File

@ -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<UserConference, Integer> {
public interface ConferenceUserRepository extends JpaRepository<ConferenceUser, Integer> {
}

View File

@ -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<Paper> getConferencePapers(List<Integer> paperIds) {
return paperService.findAllNotSelect(paperIds);
}
public List<ConferenceUser.Participation> getAllParticipations() {
return Arrays.asList(ConferenceUser.Participation.values());
}
public List<ConferenceUser.Deposit> 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 ->

View File

@ -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<UserConference> saveOrCreate(List<UserConference> users) {
public List<ConferenceUser> saveOrCreate(List<ConferenceUser> 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());

View File

@ -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;
}
}

View File

@ -97,20 +97,26 @@
<div class="form-group">
<label for="members">Участники:</label>
<div class="member-list form-control list-group" id="members">
<input th:type="hidden" th:value="*{users}"/>
<!--<input th:type="hidden" th:value="*{users}"/>-->
<div class="member d-flex list-group-item justify-content-between p-1"
th:each="user, rowStat : *{users}">
<input type="hidden" th:field="*{users[__${rowStat.index}__].id}"/>
<input type="hidden" th:field="*{users[__${rowStat.index}__].user.id}"/>
<input type="hidden" th:field="*{users[__${rowStat.index}__].user}"/>
<input class="member-name" readonly="true"
th:field="*{users[__${rowStat.index}__].user.lastName}"/>
<select class="member-participation"
th:field="*{users[__${rowStat.index}__].participation}">
<option th:each="participation : ${allParticipation}"
th:value="${participation}"
th:text="${participation.participation}">Participation
</option>
</select>
<select class="member-deposit"
th:field="*{users[__${rowStat.index}__].deposit}">
<option th:each="deposit : ${allDeposit}" th:value="${deposit}"
th:text="${deposit.deposit}">Deposit
</option>
</select>
</div>
</div>