#69 added method take part in conference

This commit is contained in:
Nightblade73 2019-04-17 14:51:19 +04:00
parent 8564f2cf34
commit 7e4d8d4918
8 changed files with 154 additions and 26 deletions

View File

@ -104,6 +104,15 @@ public class ConferenceController {
return CONFERENCE_PAGE; 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<Paper> getNotSelectPapers(List<Integer> paperIds) { public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
return conferenceService.getConferencePapers(paperIds); return conferenceService.getConferencePapers(paperIds);
} }

View File

@ -23,9 +23,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
@Entity @Entity
@Table(name = "conference") @Table(name = "conference")
@ -66,7 +64,8 @@ public class Conference extends BaseEntity {
@JoinTable(name = "users_conference", @JoinTable(name = "users_conference",
joinColumns = {@JoinColumn(name = "conference_id")}, joinColumns = {@JoinColumn(name = "conference_id")},
inverseJoinColumns = {@JoinColumn(name = "users_id")}) inverseJoinColumns = {@JoinColumn(name = "users_id")})
private Set<UserConference> users = new HashSet<>(); @Fetch(FetchMode.SUBSELECT)
private List<UserConference> users = new ArrayList<>();
public String getTitle() { public String getTitle() {
return title; return title;
@ -132,11 +131,11 @@ public class Conference extends BaseEntity {
this.papers = papers; this.papers = papers;
} }
public Set<UserConference> getUsers() { public List<UserConference> getUsers() {
return users; return users;
} }
public void setUsers(Set<UserConference> users) { public void setUsers(List<UserConference> users) {
this.users = users; this.users = users;
} }
} }

View File

@ -13,9 +13,7 @@ import javax.persistence.TemporalType;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
@ -38,11 +36,11 @@ public class ConferenceDto {
private Date endDate = new Date(); private Date endDate = new Date();
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>(); private List<Integer> removedDeadlineIds = new ArrayList<>();
private Set<Integer> userIds = new HashSet<>(); private List<Integer> userIds = new ArrayList<>();
private List<Integer> paperIds = new ArrayList<>(); private List<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>(); private List<Paper> papers = new ArrayList<>();
private List<Paper> notSelectedPapers = new ArrayList<>(); private List<Paper> notSelectedPapers = new ArrayList<>();
private Set<UserConference> users = new HashSet<>(); private List<UserConference> users = new ArrayList<>();
private Integer filterUserId; private Integer filterUserId;
public ConferenceDto() { public ConferenceDto() {
@ -57,9 +55,9 @@ public class ConferenceDto {
@JsonProperty("beginDate") Date beginDate, @JsonProperty("beginDate") Date beginDate,
@JsonProperty("endDate") Date endDate, @JsonProperty("endDate") Date endDate,
@JsonProperty("deadlines") List<Deadline> deadlines, @JsonProperty("deadlines") List<Deadline> deadlines,
@JsonProperty("userIds") Set<Integer> userIds, @JsonProperty("userIds") List<Integer> userIds,
@JsonProperty("paperIds") List<Integer> paperIds, @JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("users") Set<UserConference> users, @JsonProperty("users") List<UserConference> users,
@JsonProperty("papers") List<Paper> papers, @JsonProperty("papers") List<Paper> papers,
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) { @JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
this.id = id; this.id = id;
@ -157,11 +155,11 @@ public class ConferenceDto {
this.deadlines = deadlines; this.deadlines = deadlines;
} }
public Set<Integer> getUserIds() { public List<Integer> getUserIds() {
return userIds; return userIds;
} }
public void setUserIds(Set<Integer> userIds) { public void setUserIds(List<Integer> userIds) {
this.userIds = userIds; this.userIds = userIds;
} }
@ -181,11 +179,11 @@ public class ConferenceDto {
this.papers = papers; this.papers = papers;
} }
public Set<UserConference> getUsers() { public List<UserConference> getUsers() {
return users; return users;
} }
public void setUsers(Set<UserConference> users) { public void setUsers(List<UserConference> users) {
this.users = users; this.users = users;
} }

View File

@ -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<UserConference, Integer> {
}

View File

@ -9,6 +9,8 @@ import ru.ulstu.conference.repository.ConferenceRepository;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.UserConference;
import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -21,17 +23,24 @@ public class ConferenceService {
private final static int MAX_DISPLAY_SIZE = 40; private final static int MAX_DISPLAY_SIZE = 40;
private final ConferenceRepository conferenceRepository; private final ConferenceRepository conferenceRepository;
private final ConferenceUserService conferenceUserService;
private final DeadlineService deadlineService; private final DeadlineService deadlineService;
private final PaperService paperService; private final PaperService paperService;
private final UserService userService;
public ConferenceService(ConferenceRepository conferenceRepository, public ConferenceService(ConferenceRepository conferenceRepository,
ConferenceUserService conferenceUserService,
DeadlineService deadlineService, DeadlineService deadlineService,
PaperService paperService) { PaperService paperService,
UserService userService) {
this.conferenceRepository = conferenceRepository; this.conferenceRepository = conferenceRepository;
this.conferenceUserService = conferenceUserService;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.paperService = paperService; this.paperService = paperService;
this.userService = userService;
} }
public List<Conference> findAll() { public List<Conference> findAll() {
return conferenceRepository.findAll(); return conferenceRepository.findAll();
} }
@ -88,6 +97,10 @@ public class ConferenceService {
conferenceDto.getNotSelectedPapers().add(removedPaper); conferenceDto.getNotSelectedPapers().add(removedPaper);
} }
public void takePart(ConferenceDto conferenceDto) throws IOException {
conferenceDto.getUsers().add(new UserConference("test", "test", userService.getCurrentUser()));
}
public List<Paper> getConferencePapers(List<Integer> paperIds) { public List<Paper> getConferencePapers(List<Integer> paperIds) {
return paperService.findAllNotSelect(paperIds); return paperService.findAllNotSelect(paperIds);
} }
@ -101,6 +114,8 @@ public class ConferenceService {
conference.setEndDate(conferenceDto.getEndDate()); conference.setEndDate(conferenceDto.getEndDate());
conference.setPapers(conferenceDto.getPapers()); conference.setPapers(conferenceDto.getPapers());
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); 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()) { if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
conferenceDto.getPaperIds().forEach(paperId -> conferenceDto.getPaperIds().forEach(paperId ->
conference.getPapers().add(paperService.findEntityById(paperId))); conference.getPapers().add(paperService.findEntityById(paperId)));

View File

@ -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<UserConference> saveOrCreate(List<UserConference> 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;
}
}

View File

@ -1,5 +1,7 @@
package ru.ulstu.user.model; package ru.ulstu.user.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import javax.persistence.Column; import javax.persistence.Column;
@ -25,4 +27,49 @@ public class UserConference extends BaseEntity {
@JoinColumn(name = "users_id") @JoinColumn(name = "users_id")
private User user; 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,23 +97,28 @@
<div class="form-group"> <div class="form-group">
<label for="members">Участники:</label> <label for="members">Участники:</label>
<div class="member-list form-control list-group" id="members"> <div class="member-list form-control list-group" id="members">
<div class="member d-flex list-group-item justify-content-between p-1"> <input th:type="hidden" th:value="*{users}"/>
<input class="member-name" readonly="true"/> <div class="member d-flex list-group-item justify-content-between p-1"
<select class="member-participation"> 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 class="member-name" readonly="true"
th:field="*{users[__${rowStat.index}__].user.lastName}"/>
<select class="member-participation"
th:field="*{users[__${rowStat.index}__].participation}">
</select> </select>
<select class="member-deposit"> <select class="member-deposit"
статья th:field="*{users[__${rowStat.index}__].deposit}">
</select> </select>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group d-flex justify-content-end"> <div class="form-group d-flex justify-content-end">
<button id="take-part" class="btn btn-primary" <input id="take-part" class="btn btn-primary"
type="button"> type="submit" name="takePart" value="Принять участие"/>
Принять участие
</button>
</div> </div>
<div class="form-group"> <div class="form-group">