Resolve "Реализовать интеграционные автотесты для проверки модулей" #217

Merged
VladimirZarayskiy merged 8 commits from 103-autotest-conf into dev 2019-05-13 23:46:30 +04:00
17 changed files with 162 additions and 44 deletions

View File

@ -13,7 +13,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.service.GrantService; import ru.ulstu.grant.service.GrantService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
@ -104,7 +104,6 @@ public class GrantController {
return GRANT_PAGE; return GRANT_PAGE;
} }
@PostMapping(value = "/grant", params = "createProject") @PostMapping(value = "/grant", params = "createProject")
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
if (errors.hasErrors()) { if (errors.hasErrors()) {
@ -131,7 +130,7 @@ public class GrantController {
} }
@ModelAttribute("allPapers") @ModelAttribute("allPapers")
public List<Paper> getAllPapers() { public List<PaperDto> getAllPapers() {
return grantService.getAllUncompletedPapers(); return grantService.getAllUncompletedPapers();
} }

View File

@ -74,7 +74,6 @@ public class Grant extends BaseEntity implements UserContainer {
@Fetch(FetchMode.SUBSELECT) @Fetch(FetchMode.SUBSELECT)
private List<FileData> files = new ArrayList<>(); private List<FileData> files = new ArrayList<>();
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "project_id") @JoinColumn(name = "project_id")
private Project project; private Project project;

View File

@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -37,7 +37,7 @@ public class GrantDto {
private boolean hasBAKPapers; private boolean hasBAKPapers;
private boolean hasScopusPapers; private boolean hasScopusPapers;
private List<Integer> paperIds = new ArrayList<>(); private List<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>(); private List<PaperDto> papers = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>(); private List<Integer> removedDeadlineIds = new ArrayList<>();
public GrantDto() { public GrantDto() {
@ -54,12 +54,12 @@ public class GrantDto {
@JsonProperty("project") ProjectDto project, @JsonProperty("project") ProjectDto project,
@JsonProperty("authorIds") Set<Integer> authorIds, @JsonProperty("authorIds") Set<Integer> authorIds,
@JsonProperty("authors") Set<UserDto> authors, @JsonProperty("authors") Set<UserDto> authors,
@JsonProperty("leader") Integer leaderId, @JsonProperty("leaderId") Integer leaderId,
@JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("wasLeader") boolean wasLeader,
@JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("hasDegree") boolean hasDegree,
@JsonProperty("paperIds") List<Integer> paperIds, @JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("papers") List<Paper> papers) { @JsonProperty("papers") List<PaperDto> papers) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -92,7 +92,7 @@ public class GrantDto {
this.hasAge = false; this.hasAge = false;
this.hasDegree = false; this.hasDegree = false;
this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
this.papers = grant.getPapers(); this.papers = convert(grant.getPapers(), PaperDto::new);
} }
public Integer getId() { public Integer getId() {
@ -214,11 +214,11 @@ public class GrantDto {
this.paperIds = paperIds; this.paperIds = paperIds;
} }
public List<Paper> getPapers() { public List<PaperDto> getPapers() {
return papers; return papers;
} }
public void setPapers(List<Paper> papers) { public void setPapers(List<PaperDto> papers) {
this.papers = papers; this.papers = papers;
} }

View File

@ -11,6 +11,7 @@ import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
@ -34,7 +35,7 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
@Service @Service
public class GrantService { public class GrantService {
private final static int MAX_DISPLAY_SIZE = 40; private final static int MAX_DISPLAY_SIZE = 50;
private final GrantRepository grantRepository; private final GrantRepository grantRepository;
private final ProjectService projectService; private final ProjectService projectService;
@ -210,17 +211,16 @@ public class GrantService {
.collect(toList()); .collect(toList());
} }
public List<Paper> getGrantPapers(List<Integer> paperIds) { public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
return paperService.findAllSelect(paperIds); return paperService.findAllSelect(paperIds);
} }
public List<Paper> getAllPapers() { public List<PaperDto> getAllUncompletedPapers() {
return paperService.findAll(); List<PaperDto> papers = paperService.findAllNotCompleted();
} papers.stream()
.forEach(paper ->
public List<Paper> getAllUncompletedPapers() { paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE)));
return paperService.findAllNotCompleted(); return papers;
} }
public void attachPaper(GrantDto grantDto) { public void attachPaper(GrantDto grantDto) {

View File

@ -248,12 +248,12 @@ public class PaperService {
} }
} }
public List<Paper> findAllNotCompleted() { public List<PaperDto> findAllNotCompleted() {
return paperRepository.findByStatusNot(COMPLETED); return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new);
} }
public List<Paper> findAllSelect(List<Integer> paperIds) { public List<PaperDto> findAllSelect(List<Integer> paperIds) {
return sortPapers(paperRepository.findAllByIdIn(paperIds)); return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new);
} }
public List<User> getPaperAuthors() { public List<User> getPaperAuthors() {

View File

@ -67,6 +67,7 @@ public class Task extends BaseEntity {
private Date updateDate = new Date(); private Date updateDate = new Date();
@ManyToMany(fetch = FetchType.EAGER) @ManyToMany(fetch = FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name = "task_tags", @JoinTable(name = "task_tags",
joinColumns = {@JoinColumn(name = "task_id")}, joinColumns = {@JoinColumn(name = "task_id")},
inverseJoinColumns = {@JoinColumn(name = "tag_id")}) inverseJoinColumns = {@JoinColumn(name = "tag_id")})
@ -127,4 +128,5 @@ public class Task extends BaseEntity {
public void setTags(List<Tag> tags) { public void setTags(List<Tag> tags) {
this.tags = tags; this.tags = tags;
} }
} }

View File

@ -11,6 +11,7 @@ import ru.ulstu.students.model.TaskFilterDto;
import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.students.repository.TaskRepository;
import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.model.Tag;
import ru.ulstu.tags.service.TagService; import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.service.EventService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -29,12 +30,14 @@ public class TaskService {
private final TaskRepository taskRepository; private final TaskRepository taskRepository;
private final DeadlineService deadlineService; private final DeadlineService deadlineService;
private final TagService tagService; private final TagService tagService;
private final EventService eventService;
public TaskService(TaskRepository taskRepository, public TaskService(TaskRepository taskRepository,
DeadlineService deadlineService, TagService tagService) { DeadlineService deadlineService, TagService tagService, EventService eventService) {
this.taskRepository = taskRepository; this.taskRepository = taskRepository;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.tagService = tagService; this.tagService = tagService;
this.eventService = eventService;
} }
public List<Task> findAll() { public List<Task> findAll() {
@ -67,6 +70,7 @@ public class TaskService {
public Integer create(TaskDto taskDto) throws IOException { public Integer create(TaskDto taskDto) throws IOException {
Task newTask = copyFromDto(new Task(), taskDto); Task newTask = copyFromDto(new Task(), taskDto);
newTask = taskRepository.save(newTask); newTask = taskRepository.save(newTask);
eventService.createFromTask(newTask);
return newTask.getId(); return newTask.getId();
} }
@ -86,6 +90,7 @@ public class TaskService {
public Integer update(TaskDto taskDto) throws IOException { public Integer update(TaskDto taskDto) throws IOException {
Task task = taskRepository.findOne(taskDto.getId()); Task task = taskRepository.findOne(taskDto.getId());
taskRepository.save(copyFromDto(task, taskDto)); taskRepository.save(copyFromDto(task, taskDto));
eventService.updateTaskDeadlines(task);
return task.getId(); return task.getId();
} }

View File

@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.students.model.Task;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -87,6 +88,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "grant_id") @JoinColumn(name = "grant_id")
private Grant grant; private Grant grant;
@ManyToOne
@JoinColumn(name = "task_id")
private Task task;
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -190,4 +195,12 @@ public class Event extends BaseEntity {
public void setGrant(Grant grant) { public void setGrant(Grant grant) {
this.grant = grant; this.grant = grant;
} }
public Task getTask() {
return task;
}
public void setTask(Task task) {
this.task = task;
}
} }

View File

@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.students.model.TaskDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -29,6 +30,7 @@ public class EventDto {
private PaperDto paperDto; private PaperDto paperDto;
private ConferenceDto conferenceDto; private ConferenceDto conferenceDto;
private GrantDto grantDto; private GrantDto grantDto;
private TaskDto taskDto;
@JsonCreator @JsonCreator
public EventDto(@JsonProperty("id") Integer id, public EventDto(@JsonProperty("id") Integer id,
@ -42,7 +44,8 @@ public class EventDto {
@JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("paperDto") PaperDto paperDto,
@JsonProperty("recipients") List<UserDto> recipients, @JsonProperty("recipients") List<UserDto> recipients,
@JsonProperty("conferenceDto") ConferenceDto conferenceDto, @JsonProperty("conferenceDto") ConferenceDto conferenceDto,
@JsonProperty("grantDto") GrantDto grantDto) { @JsonProperty("grantDto") GrantDto grantDto,
@JsonProperty("taskDto") TaskDto taskDto) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.period = period; this.period = period;
@ -55,6 +58,7 @@ public class EventDto {
this.paperDto = paperDto; this.paperDto = paperDto;
this.conferenceDto = conferenceDto; this.conferenceDto = conferenceDto;
this.grantDto = grantDto; this.grantDto = grantDto;
this.taskDto = taskDto;
} }
public EventDto(Event event) { public EventDto(Event event) {
@ -76,6 +80,9 @@ public class EventDto {
if (grantDto != null) { if (grantDto != null) {
this.grantDto = new GrantDto(event.getGrant()); this.grantDto = new GrantDto(event.getGrant());
} }
if (taskDto != null) {
this.taskDto = new TaskDto(event.getTask());
}
} }
public Integer getId() { public Integer getId() {
@ -137,4 +144,12 @@ public class EventDto {
public void setGrantDto(GrantDto grantDto) { public void setGrantDto(GrantDto grantDto) {
this.grantDto = grantDto; this.grantDto = grantDto;
} }
public TaskDto getTaskDto() {
return taskDto;
}
public void setTaskDto(TaskDto taskDto) {
this.taskDto = taskDto;
}
} }

View File

@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.students.model.Task;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import java.util.List; import java.util.List;
@ -21,4 +22,6 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
List<Event> findAllByConference(Conference conference); List<Event> findAllByConference(Conference conference);
List<Event> findAllByGrant(Grant grant); List<Event> findAllByGrant(Grant grant);
List<Event> findAllByTask(Task task);
} }

View File

@ -8,6 +8,7 @@ import ru.ulstu.conference.model.Conference;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.students.model.Task;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.EventDto;
import ru.ulstu.timeline.model.Timeline; import ru.ulstu.timeline.model.Timeline;
@ -208,4 +209,33 @@ public class EventService {
List<Event> eventList = eventRepository.findAllByConference(conference); List<Event> eventList = eventRepository.findAllByConference(conference);
eventList.forEach(event -> eventRepository.delete(event.getId())); eventList.forEach(event -> eventRepository.delete(event.getId()));
} }
public void createFromTask(Task newTask) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newTask.getDeadlines()
.stream()
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
.collect(Collectors.toList())) {
Event newEvent = new Event();
newEvent.setTitle("Дедлайн задачи");
newEvent.setStatus(Event.EventStatus.NEW);
newEvent.setExecuteDate(deadline.getDate());
newEvent.setCreateDate(new Date());
newEvent.setUpdateDate(new Date());
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'");
newEvent.getRecipients().add(userService.getCurrentUser());
newEvent.setTask(newTask);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
public void updateTaskDeadlines(Task task) {
eventRepository.delete(eventRepository.findAllByTask(task));
createFromTask(task);
}
} }

View File

@ -0,0 +1,13 @@
<?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="nastya" id="20190511_000000-1">
<addColumn tableName="event">
<column name="task_id" type="integer"></column>
</addColumn>
<addForeignKeyConstraint baseTableName="event" baseColumnNames="task_id"
constraintName="fk_event_task_id" referencedTableName="task"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -40,4 +40,5 @@
<include file="db/changelog-20190505_000000-schema.xml"/> <include file="db/changelog-20190505_000000-schema.xml"/>
<include file="db/changelog-20190507_000000-schema.xml"/> <include file="db/changelog-20190507_000000-schema.xml"/>
<include file="db/changelog-20190507_000001-schema.xml"/> <include file="db/changelog-20190507_000001-schema.xml"/>
<include file="db/changelog-20190511_000000-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -39,6 +39,42 @@
max-width: inherit; max-width: inherit;
} }
.task-row{
position: relative;
}
.task-row .col:hover{
background-color: #f8f9fa;
}
.task-row .col > a{
display: block;
text-decoration: none;
}
.task-row .col:hover .remove-task{
visibility: visible;
}
.remove-task{
visibility: hidden;
position: absolute;
right: -20px;
top: 50%;
transform: translate(-50%, -50%);
padding: 0 20px;
}
.remove-task:hover{
background-color: #ebebeb;
}
.tag { .tag {
display: inline-block; display: inline-block;
padding: .2em .6em .3em; padding: .2em .6em .3em;

View File

@ -70,17 +70,17 @@ $(document).ready(function () {
}); });
$("span[data-role=remove]").click(removeTag); $("span[data-role=remove]").click(removeTag);
$(".task-row").mouseenter(function (event) { // $(".task-row").mouseenter(function (event) {
var taskRow = $(event.target).closest(".task-row"); // var taskRow = $(event.target).closest(".task-row");
$(taskRow).css("background-color", "#f8f9fa"); // $(taskRow).css("background-color", "#f8f9fa");
$(taskRow).find(".remove-task").removeClass("d-none"); // $(taskRow).find(".remove-task").removeClass("d-none");
//
}); // });
$(".task-row").mouseleave(function (event) { // $(".task-row").mouseleave(function (event) {
var taskRow = $(event.target).closest(".task-row"); // var taskRow = $(event.target).closest(".task-row");
$(taskRow).css("background-color", "white"); // $(taskRow).css("background-color", "white");
$(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); // $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none");
}); // });
$('a[data-confirm]').click(function(ev) { $('a[data-confirm]').click(function(ev) {
var href = $(this).attr('href'); var href = $(this).attr('href');

View File

@ -184,9 +184,9 @@
value="Отобразить прикрепленную статью"/> value="Отобразить прикрепленную статью"/>
</div> </div>
<div class="row"> <div class="row">
<input th:type="hidden" th:field="*{papers}"/>
<div class="form-control list-group div-selected-papers" id="selected-papers"> <div class="form-control list-group div-selected-papers" id="selected-papers">
<div th:each="paper, rowStat : *{papers}"> <div th:each="paper, rowStat : *{papers}">
<input type="hidden" th:field="*{papers[__${rowStat.index}__].id}"/>
<div class="col"> <div class="col">
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"> <a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
<img class="icon-paper" src="/img/conference/paper.png"/> <img class="icon-paper" src="/img/conference/paper.png"/>
@ -201,6 +201,7 @@
Статус статьи Статус статьи
</span> </span>
</div> </div>
<!--
<div class="col" th:unless="${#lists.isEmpty(paper.grants)}"> <div class="col" th:unless="${#lists.isEmpty(paper.grants)}">
<label>Гранты: </label> <label>Гранты: </label>
<div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}" <div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}"
@ -225,6 +226,7 @@
</li> </li>
</div> </div>
</div> </div>
-->
</div> </div>
</div> </div>
</div> </div>

View File

@ -6,15 +6,15 @@
<body> <body>
<div th:fragment="taskLine (task)" class="row text-left task-row" style="background-color: white;"> <div th:fragment="taskLine (task)" class="row text-left task-row" style="background-color: white;">
<div class="col"> <div class="col">
<span th:replace="students/fragments/taskStatusFragment :: taskStatus(taskStatus=${task.status})"/>
<a th:href="@{'task?id='+${task.id}}"> <a th:href="@{'task?id='+${task.id}}">
<span th:replace="students/fragments/taskStatusFragment :: taskStatus(taskStatus=${task.status})"/>
<span class="h6" th:text="${task.title}"></span> <span class="h6" th:text="${task.title}"></span>
<span class="text-muted" th:text="${task.tagsString}"/> <span class="text-muted" th:text="${task.tagsString}"/>
</a> <input class="id-class" type="hidden" th:value="${task.id}"/>
<input class="id-class" type="hidden" th:value="${task.id}"/> <a class="remove-task pull-right" th:href="@{'/students/delete/'+${task.id}}"
<a class="remove-task pull-right d-none" th:href="@{'/students/delete/'+${task.id}}" data-confirm="Удалить задачу?">
data-confirm="Удалить задачу?"> <i class="fa fa-trash" aria-hidden="true"></i>
<i class="fa fa-trash" aria-hidden="true"></i> </a>
</a> </a>
</div> </div>
</div> </div>