Merge branch '69-take-part-conf' into 'dev'

Resolve "Принять участие в конференции пользователю"

Closes #69

See merge request romanov73/ng-tracker!56
This commit is contained in:
Anton Romanov 2019-04-19 13:05:07 +00:00
commit 2d0f2aeecd
14 changed files with 330 additions and 70 deletions

View File

@ -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<Integer>()));
modelMap.put("conferenceDto", conferenceDto);
modelMap.put("conferenceDto", conferenceService.getNewConference());
}
}
@ -104,8 +100,23 @@ public class ConferenceController {
return CONFERENCE_PAGE;
}
public List<Paper> getNotSelectPapers(List<Integer> 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<ConferenceUser.Participation> getAllParticipation() {
return conferenceService.getAllParticipations();
}
@ModelAttribute("allDeposit")
public List<ConferenceUser.Deposit> getAllDeposit() {
return conferenceService.getAllDeposit();
}
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {

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.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<Paper> papers = new ArrayList<>();
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "users_conference",
joinColumns = {@JoinColumn(name = "conference_id")},
inverseJoinColumns = {@JoinColumn(name = "users_id")})
private Set<User> users = new HashSet<>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "conference_id", unique = true)
@Fetch(FetchMode.SUBSELECT)
private List<ConferenceUser> users = new ArrayList<>();
public String getTitle() {
return title;
@ -132,11 +128,11 @@ public class Conference extends BaseEntity {
this.papers = papers;
}
public Set<User> getUsers() {
public List<ConferenceUser> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
public void setUsers(List<ConferenceUser> users) {
this.users = users;
}
}

View File

@ -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<Deadline> deadlines = 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<Paper> papers = new ArrayList<>();
private List<Paper> notSelectedPapers = new ArrayList<>();
private Set<UserDto> users = new HashSet<>();
private Integer filterUserId;
private List<ConferenceUser> 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<Deadline> deadlines,
@JsonProperty("userIds") Set<Integer> userIds,
@JsonProperty("userIds") List<Integer> userIds,
@JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("users") Set<UserDto> users,
@JsonProperty("users") List<ConferenceUser> users,
@JsonProperty("papers") List<Paper> papers,
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
@JsonProperty("notSelectedPapers") List<Paper> 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<Integer> getUserIds() {
public List<Integer> getUserIds() {
return userIds;
}
public void setUserIds(Set<Integer> userIds) {
public void setUserIds(List<Integer> userIds) {
this.userIds = userIds;
}
@ -183,20 +179,20 @@ public class ConferenceDto {
this.papers = papers;
}
public Set<UserDto> getUsers() {
public List<ConferenceUser> getUsers() {
return users;
}
public void setUsers(Set<UserDto> users) {
public void setUsers(List<ConferenceUser> 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<Integer> getRemovedDeadlineIds() {

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

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

View File

@ -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<Integer>()));
return conferenceDto;
}
public List<Conference> findAll() {
return conferenceRepository.findAll();
}
@ -88,10 +112,23 @@ public class ConferenceService {
conferenceDto.getNotSelectedPapers().add(removedPaper);
}
public List<Paper> getConferencePapers(List<Integer> paperIds) {
public void takePart(ConferenceDto conferenceDto) throws IOException {
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
conferenceDto.setDisabledTakePart(true);
}
public List<Paper> getNotSelectPapers(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());
@ -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<ConferenceUser> conferenceUsers) {
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
}
}

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.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<ConferenceUser> saveOrCreate(List<ConferenceUser> 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;
}
}

View File

@ -33,5 +33,5 @@ public interface UserRepository extends JpaRepository<User, Integer> {
"AND (u.degree = 'CANDIDATE' OR :hasDegree = FALSE)" +
"ORDER BY u.lastName")
List<User> filterByAgeAndDegree(@Param("hasAge") boolean hasAge,
@Param("hasDegree") boolean hasDegree);
@Param("hasDegree") boolean hasDegree);
}

View File

@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="vova" id="20190417_000000-1">
<addColumn tableName="users_conference">
<column name="id" type="integer"></column>
<column name="version" type="integer"></column>
</addColumn>
<addPrimaryKey columnNames="id" constraintName="pk_users_conference" tableName="users_conference"/>
<modifyDataType tableName="users_conference" columnName="participation" newDataType="varchar(255)"/>
</changeSet>
</databaseChangeLog>

View File

@ -24,6 +24,7 @@
<include file="db/changelog-20190331_000000-schema.xml"/>
<include file="db/changelog-20190331_000010-schema.xml"/>
<include file="db/changelog-20190410_000000-schema.xml"/>
<include file="db/changelog-20190417_000000-schema.xml"/>
<include file="db/changelog-20190418_000000-schema.xml"/>
<include file="db/changelog-20190323_000001-schema.xml"/>
<include file="db/common/changelog-20190312_130000-schema.xml"/>

View File

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

View File

@ -97,38 +97,35 @@
<div class="form-group">
<label for="members">Участники:</label>
<div class="member-list form-control list-group" id="members">
<div class="member d-flex list-group-item justify-content-between p-1">
<div class="member-name">
Пользователь 1
</div>
<div class="member-participation">
очная
</div>
<div class="member-deposit">
статья
</div>
</div>
<div class="member d-flex list-group-item p-0"
th:each="user, rowStat : *{users}">
<input type="hidden" th:field="*{users[__${rowStat.index}__].id}"/>
<input type="hidden" th:field="*{users[__${rowStat.index}__].user}"/>
<input class="member-name w-100" readonly="true"
th:field="*{users[__${rowStat.index}__].user.lastName}"/>
<select class="member-participation w-auto"
th:field="*{users[__${rowStat.index}__].participation}">
<option th:each="participation : ${allParticipation}"
th:value="${participation}"
th:text="${participation.participation}">Participation
</option>
<div class="member d-flex list-group-item justify-content-between p-1">
<div class="member-name">
Пользователь 1
</div>
<div class="member-participation">
очная
</div>
<div class="member-deposit">
доклад
</div>
</select>
<select class="member-deposit w-auto"
th:field="*{users[__${rowStat.index}__].deposit}">
<option th:each="deposit : ${allDeposit}" th:value="${deposit}"
th:text="${deposit.deposit}">Deposit
</option>
</select>
</div>
</div>
</div>
<div class="form-group d-flex justify-content-end">
<button id="take-part" class="btn btn-primary"
type="button">
Принять участие
</button>
<input type="hidden" th:value="*{disabledTakePart}" th:name="disabledTakePart"/>
<input id="take-part" class="btn btn-primary"
type="submit" name="takePart" value="Принять участие"
th:disabled="*{disabledTakePart}"/>
</div>
<div class="form-group">

View File

@ -202,6 +202,7 @@
});
/*]]>*/
</script>
<script type="text/javascript">
function updateAuthors() {

View File

@ -139,6 +139,7 @@
});
/*]]>*/
</script>
</div>
</body>