Merge branch '101-projecgt-timeline' into 'dev'

Resolve "Генерация таймлайна для проекта"

Closes #101

See merge request romanov73/ng-tracker!85
This commit is contained in:
Anton Romanov 2019-06-05 04:55:15 +00:00
commit bacd3827e3
35 changed files with 1034 additions and 148 deletions

View File

@ -5,8 +5,11 @@ import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
@ -28,7 +31,7 @@ import java.util.Optional;
@Entity @Entity
@Table(name = "conference") @Table(name = "conference")
public class Conference extends BaseEntity { public class Conference extends BaseEntity implements EventSource {
@NotBlank @NotBlank
private String title; private String title;
@ -71,6 +74,19 @@ public class Conference extends BaseEntity {
return title; return title;
} }
@Override
public List<User> getRecipients() {
List<User> list = new ArrayList<>();
getUsers().forEach(conferenceUser -> list.add(conferenceUser.getUser()));
return list;
}
@Override
public void addObjectToEvent(Event event) {
event.setConference(this);
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }

View File

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Collections;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -116,7 +117,7 @@ public class ConferenceService extends BaseService {
Conference newConference = copyFromDto(new Conference(), conferenceDto); Conference newConference = copyFromDto(new Conference(), conferenceDto);
newConference = conferenceRepository.save(newConference); newConference = conferenceRepository.save(newConference);
conferenceNotificationService.sendCreateNotification(newConference); conferenceNotificationService.sendCreateNotification(newConference);
eventService.createFromConference(newConference); eventService.createFromObject(newConference, Collections.emptyList(), false, "конференции");
return newConference; return newConference;
} }

View File

@ -0,0 +1,17 @@
package ru.ulstu.core.model;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User;
import java.util.List;
public interface EventSource {
List<Deadline> getDeadlines();
String getTitle();
List<User> getRecipients();
void addObjectToEvent(Event event);
}

View File

@ -4,6 +4,7 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.core.model.UserContainer; import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
@ -26,6 +27,7 @@ import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
@ -35,7 +37,7 @@ import java.util.Set;
@Entity @Entity
@Table(name = "grants") @Table(name = "grants")
public class Grant extends BaseEntity implements UserContainer { public class Grant extends BaseEntity implements UserContainer, EventSource {
public enum GrantStatus { public enum GrantStatus {
APPLICATION("Заявка"), APPLICATION("Заявка"),
ON_COMPETITION("Отправлен на конкурс"), ON_COMPETITION("Отправлен на конкурс"),
@ -134,6 +136,16 @@ public class Grant extends BaseEntity implements UserContainer {
return title; return title;
} }
@Override
public List<User> getRecipients() {
return authors != null ? new ArrayList<>(authors) : Collections.emptyList();
}
@Override
public void addObjectToEvent(Event event) {
event.setGrant(this);
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }

View File

@ -14,6 +14,8 @@ public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepo
Grant findByTitle(String title); Grant findByTitle(String title);
Grant findGrantById(Integer grantId);
@Override @Override
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ") @Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);

View File

@ -90,7 +90,7 @@ public class GrantService extends BaseService {
public Integer create(GrantDto grantDto) throws IOException { public Integer create(GrantDto grantDto) throws IOException {
Grant newGrant = copyFromDto(new Grant(), grantDto); Grant newGrant = copyFromDto(new Grant(), grantDto);
newGrant = grantRepository.save(newGrant); newGrant = grantRepository.save(newGrant);
eventService.createFromGrant(newGrant); eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
grantNotificationService.sendCreateNotification(newGrant); grantNotificationService.sendCreateNotification(newGrant);
return newGrant.getId(); return newGrant.getId();
} }
@ -178,7 +178,7 @@ public class GrantService extends BaseService {
grant.getPapers().add(paper); grant.getPapers().add(paper);
grant = grantRepository.save(grant); grant = grantRepository.save(grant);
eventService.createFromGrant(grant); eventService.createFromObject(grant, Collections.emptyList(), false, "гранта");
grantNotificationService.sendCreateNotification(grant); grantNotificationService.sendCreateNotification(grant);
return grant; return grant;
@ -334,4 +334,8 @@ public class GrantService extends BaseService {
private List<Grant> findAllActive() { private List<Grant> findAllActive() {
return grantRepository.findAllActive(); return grantRepository.findAllActive();
} }
public Grant findGrantById(Integer grantId) {
return grantRepository.findOne(grantId);
}
} }

View File

@ -5,6 +5,7 @@ import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.core.model.UserContainer; import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
@ -34,7 +35,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
@Entity @Entity
public class Paper extends BaseEntity implements UserContainer { public class Paper extends BaseEntity implements UserContainer, EventSource {
public enum PaperStatus { public enum PaperStatus {
ATTENTION("Обратить внимание"), ATTENTION("Обратить внимание"),
ON_PREPARATION("На подготовке"), ON_PREPARATION("На подготовке"),
@ -196,6 +197,16 @@ public class Paper extends BaseEntity implements UserContainer {
return title; return title;
} }
@Override
public List<User> getRecipients() {
return new ArrayList(authors);
}
@Override
public void addObjectToEvent(Event event) {
event.setPaper(this);
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }

View File

@ -42,8 +42,9 @@ public class LatexService {
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
while ((bufferedReader.readLine()) != null) { String line = bufferedReader.readLine();
// while (line != null) {
line = bufferedReader.readLine();
} }
} }

View File

@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.service.ProjectService; import ru.ulstu.project.service.ProjectService;
@ -46,6 +48,8 @@ public class ProjectController {
@GetMapping("/project") @GetMapping("/project")
public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) { public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
if (id != null && id > 0) { if (id != null && id > 0) {
ProjectDto projectDto = projectService.findOneDto(id);
attachGrant(projectDto);
modelMap.put("projectDto", projectService.findOneDto(id)); modelMap.put("projectDto", projectService.findOneDto(id));
} else { } else {
modelMap.put("projectDto", new ProjectDto()); modelMap.put("projectDto", new ProjectDto());
@ -70,6 +74,12 @@ public class ProjectController {
return String.format("redirect:%s", "/projects/projects"); return String.format("redirect:%s", "/projects/projects");
} }
@PostMapping(value = "/project", params = "attachGrant")
public String attachGrant(ProjectDto projectDto) {
projectService.attachGrant(projectDto);
return "/projects/project";
}
@PostMapping(value = "/project", params = "addDeadline") @PostMapping(value = "/project", params = "addDeadline")
public String addDeadline(@Valid ProjectDto projectDto, Errors errors) { public String addDeadline(@Valid ProjectDto projectDto, Errors errors) {
filterEmptyDeadlines(projectDto); filterEmptyDeadlines(projectDto);
@ -98,6 +108,11 @@ public class ProjectController {
return projectService.getProjectExecutors(projectDto); return projectService.getProjectExecutors(projectDto);
} }
@ModelAttribute("allGrants")
public List<GrantDto> getAllGrants() {
return projectService.getAllGrants();
}
private void filterEmptyDeadlines(ProjectDto projectDto) { private void filterEmptyDeadlines(ProjectDto projectDto) {
projectDto.setDeadlines(projectDto.getDeadlines().stream() projectDto.setDeadlines(projectDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -1,30 +1,36 @@
package ru.ulstu.project.model; package ru.ulstu.project.model;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.core.model.UserContainer; import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.JoinTable;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@Entity @Entity
public class Project extends BaseEntity implements UserContainer { public class Project extends BaseEntity implements UserContainer, EventSource {
public enum ProjectStatus { public enum ProjectStatus {
TECHNICAL_TASK("Техническое задание"), TECHNICAL_TASK("Техническое задание"),
@ -65,17 +71,39 @@ public class Project extends BaseEntity implements UserContainer {
@NotNull @NotNull
private String repository; private String repository;
@ManyToOne @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "file_id") @JoinColumn(name = "project_id", unique = true)
private FileData application; @Fetch(FetchMode.SUBSELECT)
private List<FileData> files = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "project_id")
private List<Event> events = new ArrayList<>();
@ManyToMany(fetch = FetchType.LAZY) @ManyToMany(fetch = FetchType.LAZY)
private List<User> executors = new ArrayList<>(); private List<User> executors = new ArrayList<>();
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "project_grants",
joinColumns = {@JoinColumn(name = "project_id")},
inverseJoinColumns = {@JoinColumn(name = "grants_id")})
@Fetch(FetchMode.SUBSELECT)
private List<Grant> grants = new ArrayList<>();
public String getTitle() { public String getTitle() {
return title; return title;
} }
@Override
public List<User> getRecipients() {
return executors != null ? new ArrayList<>(executors) : Collections.emptyList();
}
@Override
public void addObjectToEvent(Event event) {
event.setProject(this);
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
@ -120,12 +148,20 @@ public class Project extends BaseEntity implements UserContainer {
this.deadlines = deadlines; this.deadlines = deadlines;
} }
public FileData getApplication() { public List<FileData> getFiles() {
return application; return files;
} }
public void setApplication(FileData application) { public void setFiles(List<FileData> files) {
this.application = application; this.files = files;
}
public List<Event> getEvents() {
return events;
}
public void setEvents(List<Event> events) {
this.events = events;
} }
public List<User> getExecutors() { public List<User> getExecutors() {
@ -141,4 +177,12 @@ public class Project extends BaseEntity implements UserContainer {
Set<User> users = new HashSet<User>(getExecutors()); Set<User> users = new HashSet<User>(getExecutors());
return users; return users;
} }
public List<Grant> getGrants() {
return grants;
}
public void setGrants(List<Grant> grants) {
this.grants = grants;
}
} }

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -27,10 +28,12 @@ public class ProjectDto {
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
private GrantDto grant; private GrantDto grant;
private String repository; private String repository;
private String applicationFileName; private List<FileDataDto> files = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>(); private List<Integer> removedDeadlineIds = new ArrayList<>();
private Set<Integer> executorIds; private Set<Integer> executorIds;
private List<UserDto> executors; private List<UserDto> executors;
private List<Integer> grantIds;
private List<GrantDto> grants;
private final static int MAX_EXECUTORS_LENGTH = 40; private final static int MAX_EXECUTORS_LENGTH = 40;
@ -48,9 +51,12 @@ public class ProjectDto {
@JsonProperty("description") String description, @JsonProperty("description") String description,
@JsonProperty("grant") GrantDto grant, @JsonProperty("grant") GrantDto grant,
@JsonProperty("repository") String repository, @JsonProperty("repository") String repository,
@JsonProperty("files") List<FileDataDto> files,
@JsonProperty("deadlines") List<Deadline> deadlines, @JsonProperty("deadlines") List<Deadline> deadlines,
@JsonProperty("executorIds") Set<Integer> executorIds, @JsonProperty("executorIds") Set<Integer> executorIds,
@JsonProperty("executors") List<UserDto> executors) { @JsonProperty("executors") List<UserDto> executors,
@JsonProperty("grantIds") List<Integer> grantIds,
@JsonProperty("grants") List<GrantDto> grants) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -58,9 +64,11 @@ public class ProjectDto {
this.grant = grant; this.grant = grant;
this.repository = repository; this.repository = repository;
this.deadlines = deadlines; this.deadlines = deadlines;
this.applicationFileName = null; this.files = files;
this.executorIds = executorIds; this.executorIds = executorIds;
this.executors = executors; this.executors = executors;
this.grantIds = grantIds;
this.grants = grants;
} }
@ -70,12 +78,14 @@ public class ProjectDto {
this.title = project.getTitle(); this.title = project.getTitle();
this.status = project.getStatus(); this.status = project.getStatus();
this.description = project.getDescription(); this.description = project.getDescription();
this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName(); this.files = convert(project.getFiles(), FileDataDto::new);
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
this.repository = project.getRepository(); this.repository = project.getRepository();
this.deadlines = project.getDeadlines(); this.deadlines = project.getDeadlines();
this.executorIds = convert(users, user -> user.getId()); this.executorIds = convert(users, user -> user.getId());
this.executors = convert(project.getExecutors(), UserDto::new); this.executors = convert(project.getExecutors(), UserDto::new);
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
this.grants = convert(project.getGrants(), GrantDto::new);
} }
public Integer getId() { public Integer getId() {
@ -134,12 +144,12 @@ public class ProjectDto {
this.deadlines = deadlines; this.deadlines = deadlines;
} }
public String getApplicationFileName() { public List<FileDataDto> getFiles() {
return applicationFileName; return files;
} }
public void setApplicationFileName(String applicationFileName) { public void setFiles(List<FileDataDto> files) {
this.applicationFileName = applicationFileName; this.files = files;
} }
public List<Integer> getRemovedDeadlineIds() { public List<Integer> getRemovedDeadlineIds() {
@ -172,4 +182,20 @@ public class ProjectDto {
.map(executor -> executor.getLastName()) .map(executor -> executor.getLastName())
.collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH); .collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH);
} }
public List<Integer> getGrantIds() {
return grantIds;
}
public void setGrantIds(List<Integer> grantIds) {
this.grantIds = grantIds;
}
public List<GrantDto> getGrants() {
return grants;
}
public void setGrants(List<GrantDto> grants) {
this.grants = grants;
}
} }

View File

@ -4,18 +4,23 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService; import ru.ulstu.file.service.FileService;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.repository.ProjectRepository; import ru.ulstu.project.repository.ProjectRepository;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import static java.util.stream.Collectors.toList;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK; import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
@ -28,17 +33,20 @@ public class ProjectService {
private final DeadlineService deadlineService; private final DeadlineService deadlineService;
private final GrantRepository grantRepository; private final GrantRepository grantRepository;
private final FileService fileService; private final FileService fileService;
private final EventService eventService;
private final UserService userService; private final UserService userService;
public ProjectService(ProjectRepository projectRepository, public ProjectService(ProjectRepository projectRepository,
DeadlineService deadlineService, DeadlineService deadlineService,
GrantRepository grantRepository, GrantRepository grantRepository,
FileService fileService, FileService fileService,
EventService eventService,
UserService userService) { UserService userService) {
this.projectRepository = projectRepository; this.projectRepository = projectRepository;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.grantRepository = grantRepository; this.grantRepository = grantRepository;
this.fileService = fileService; this.fileService = fileService;
this.eventService = eventService;
this.userService = userService; this.userService = userService;
} }
@ -64,26 +72,31 @@ public class ProjectService {
public Project create(ProjectDto projectDto) throws IOException { public Project create(ProjectDto projectDto) throws IOException {
Project newProject = copyFromDto(new Project(), projectDto); Project newProject = copyFromDto(new Project(), projectDto);
newProject = projectRepository.save(newProject); newProject = projectRepository.save(newProject);
eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта");
return newProject; return newProject;
} }
@Transactional @Transactional
public Project update(ProjectDto projectDto) throws IOException { public Project update(ProjectDto projectDto) throws IOException {
Project project = projectRepository.findOne(projectDto.getId()); Project project = projectRepository.findOne(projectDto.getId());
if (projectDto.getApplicationFileName() != null && project.getApplication() != null) {
fileService.deleteFile(project.getApplication());
}
projectRepository.save(copyFromDto(project, projectDto)); projectRepository.save(copyFromDto(project, projectDto));
eventService.updateProjectDeadlines(project);
for (FileDataDto file : projectDto.getFiles().stream()
.filter(f -> f.isDeleted() && f.getId() != null)
.collect(toList())) {
fileService.delete(file.getId());
}
return project; return project;
} }
@Transactional @Transactional
public void delete(Integer projectId) throws IOException { public boolean delete(Integer projectId) throws IOException {
if (projectRepository.exists(projectId)) {
Project project = projectRepository.findOne(projectId); Project project = projectRepository.findOne(projectId);
if (project.getApplication() != null) {
fileService.deleteFile(project.getApplication());
}
projectRepository.delete(project); projectRepository.delete(project);
return true;
}
return false;
} }
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
@ -95,8 +108,12 @@ public class ProjectService {
} }
project.setRepository(projectDto.getRepository()); project.setRepository(projectDto.getRepository());
project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines())); project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines()));
if (projectDto.getApplicationFileName() != null) { project.setFiles(fileService.saveOrCreate(projectDto.getFiles().stream()
project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName())); .filter(f -> !f.isDeleted())
.collect(toList())));
project.getGrants().clear();
if (projectDto.getGrantIds() != null && !projectDto.getGrantIds().isEmpty()) {
projectDto.getGrantIds().forEach(grantIds -> project.getGrants().add(grantRepository.findGrantById(grantIds)));
} }
return project; return project;
} }
@ -109,11 +126,12 @@ public class ProjectService {
} }
} }
public void removeDeadline(ProjectDto projectDto, Integer deadlineId) { public ProjectDto removeDeadline(ProjectDto projectDto, Integer deadlineId) {
if (deadlineId != null) { if (deadlineId != null) {
projectDto.getRemovedDeadlineIds().add(deadlineId); projectDto.getRemovedDeadlineIds().add(deadlineId);
} }
projectDto.getDeadlines().remove((int) deadlineId); projectDto.getDeadlines().remove((int) deadlineId);
return projectDto;
} }
public Project findById(Integer id) { public Project findById(Integer id) {
@ -125,4 +143,22 @@ public class ProjectService {
return users; return users;
} }
public List<GrantDto> getAllGrants() {
List<GrantDto> grants = convert(grantRepository.findAll(), GrantDto::new);
return grants;
}
public List<GrantDto> getProjectGrants(List<Integer> grantIds) {
return convert(grantRepository.findAll(grantIds), GrantDto::new);
}
public void attachGrant(ProjectDto projectDto) {
if (!projectDto.getGrantIds().isEmpty()) {
projectDto.getGrants().clear();
projectDto.setGrants(getProjectGrants(projectDto.getGrantIds()));
} else {
projectDto.getGrants().clear();
}
}
} }

View File

@ -4,8 +4,17 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.students.repository.SchedulerRepository;
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.timeline.model.Event;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
@ -20,12 +29,14 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@Entity @Entity
public class Task extends BaseEntity { public class Task extends BaseEntity implements EventSource {
public enum TaskStatus { public enum TaskStatus {
IN_WORK("В работе"), IN_WORK("В работе"),
@ -49,6 +60,17 @@ public class Task extends BaseEntity {
private String description; private String description;
@Transient
private UserService userService;
public Task() {
}
public Task(UserService userService) {
this.userService = userService;
}
@Enumerated(value = EnumType.STRING) @Enumerated(value = EnumType.STRING)
private TaskStatus status = TaskStatus.IN_WORK; private TaskStatus status = TaskStatus.IN_WORK;
@ -77,6 +99,16 @@ public class Task extends BaseEntity {
return title; return title;
} }
@Override
public List<User> getRecipients() {
return Collections.emptyList();
}
@Override
public void addObjectToEvent(Event event) {
event.setTask(this);
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }

View File

@ -18,14 +18,15 @@ import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.service.EventService; import ru.ulstu.timeline.service.EventService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -83,7 +84,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); eventService.createFromObject(newTask, Collections.emptyList(), true, "задачи");
return newTask.getId(); return newTask.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.project.model.Project;
import ru.ulstu.students.model.Task; import ru.ulstu.students.model.Task;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
@ -88,6 +89,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "grant_id") @JoinColumn(name = "grant_id")
private Grant grant; private Grant grant;
@ManyToOne
@JoinColumn(name = "project_id")
private Project project;
@ManyToOne @ManyToOne
@JoinColumn(name = "task_id") @JoinColumn(name = "task_id")
private Task task; private Task task;
@ -196,6 +201,14 @@ public class Event extends BaseEntity {
this.grant = grant; this.grant = grant;
} }
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public Task getTask() { public Task getTask() {
return task; return 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.project.model.ProjectDto;
import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -30,6 +31,7 @@ public class EventDto {
private PaperDto paperDto; private PaperDto paperDto;
private ConferenceDto conferenceDto; private ConferenceDto conferenceDto;
private GrantDto grantDto; private GrantDto grantDto;
private ProjectDto projectDto;
private TaskDto taskDto; private TaskDto taskDto;
@JsonCreator @JsonCreator
@ -45,6 +47,7 @@ public class EventDto {
@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("projectDto") ProjectDto projectDto,
@JsonProperty("taskDto") TaskDto taskDto) { @JsonProperty("taskDto") TaskDto taskDto) {
this.id = id; this.id = id;
this.title = title; this.title = title;
@ -58,6 +61,7 @@ public class EventDto {
this.paperDto = paperDto; this.paperDto = paperDto;
this.conferenceDto = conferenceDto; this.conferenceDto = conferenceDto;
this.grantDto = grantDto; this.grantDto = grantDto;
this.projectDto = projectDto;
this.taskDto = taskDto; this.taskDto = taskDto;
} }
@ -80,6 +84,9 @@ public class EventDto {
if (grantDto != null) { if (grantDto != null) {
this.grantDto = new GrantDto(event.getGrant()); this.grantDto = new GrantDto(event.getGrant());
} }
if (projectDto != null) {
this.projectDto = new ProjectDto(event.getProject());
}
if (taskDto != null) { if (taskDto != null) {
this.taskDto = new TaskDto(event.getTask()); this.taskDto = new TaskDto(event.getTask());
} }
@ -145,6 +152,14 @@ public class EventDto {
this.grantDto = grantDto; this.grantDto = grantDto;
} }
public ProjectDto getProjectDto() {
return projectDto;
}
public void setProjectDto(ProjectDto projectDto) {
this.projectDto = projectDto;
}
public TaskDto getTaskDto() { public TaskDto getTaskDto() {
return taskDto; return 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.project.model.Project;
import ru.ulstu.students.model.Task; import ru.ulstu.students.model.Task;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
@ -23,5 +24,7 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
List<Event> findAllByGrant(Grant grant); List<Event> findAllByGrant(Grant grant);
List<Event> findAllByProject(Project project);
List<Event> findAllByTask(Task task); List<Event> findAllByTask(Task task);
} }

View File

@ -5,9 +5,11 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.EventSource;
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.project.model.Project;
import ru.ulstu.students.model.Task; 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;
@ -17,7 +19,6 @@ import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -105,35 +106,39 @@ public class EventService {
} }
public void createFromPaper(Paper newPaper) { public void createFromPaper(Paper newPaper) {
createFromPaper(newPaper, Collections.emptyList()); createFromObject(newPaper, Collections.emptyList(), false, "статьи");
} }
public void createFromPaper(Paper newPaper, List<Event> events) { public void createFromObject(EventSource eventSource, List<Event> events, Boolean addCurrentUser, String suffix) {
List<Timeline> timelines = timelineService.findAll(); List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
timeline.getEvents().removeAll(events); timeline.getEvents().removeAll(events);
for (Deadline deadline : newPaper.getDeadlines() for (Deadline deadline : eventSource.getDeadlines()
.stream() .stream()
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
.collect(Collectors.toList())) { .collect(Collectors.toList())) {
Event newEvent = new Event(); Event newEvent = new Event();
newEvent.setTitle("Дедлайн статьи"); newEvent.setTitle("Дедлайн " + suffix);
newEvent.setStatus(Event.EventStatus.NEW); newEvent.setStatus(Event.EventStatus.NEW);
newEvent.setExecuteDate(deadline.getDate()); newEvent.setExecuteDate(deadline.getDate());
newEvent.setCreateDate(new Date()); newEvent.setCreateDate(new Date());
newEvent.setUpdateDate(new Date()); newEvent.setUpdateDate(new Date());
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' " + suffix + " '"
newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); + eventSource.getTitle() + "'");
newEvent.setPaper(newPaper); if (addCurrentUser) {
newEvent.getRecipients().add(userService.getCurrentUser());
}
newEvent.setRecipients(eventSource.getRecipients());
eventSource.addObjectToEvent(newEvent);
timeline.getEvents().add(eventRepository.save(newEvent)); timeline.getEvents().add(eventRepository.save(newEvent));
} }
timelineService.save(timeline); timelineService.save(timeline);
} }
public void updatePaperDeadlines(Paper paper) { public void updatePaperDeadlines(Paper paper) {
List<Event> foundEvents = eventRepository.findAllByPaper(paper); List<Event> foundEvents = eventRepository.findAllByPaper(paper);
eventRepository.delete(foundEvents); eventRepository.delete(foundEvents);
createFromPaper(paper, foundEvents); createFromObject(paper, foundEvents, false, "статьи");
} }
public List<Event> findByCurrentDate() { public List<Event> findByCurrentDate() {
@ -148,65 +153,19 @@ public class EventService {
return convert(findAllFuture(), EventDto::new); return convert(findAllFuture(), EventDto::new);
} }
public void createFromConference(Conference newConference) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newConference.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() + "' конференции '" + newConference.getTitle() + "'");
newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser()));
newEvent.setConference(newConference);
save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
public void updateConferenceDeadlines(Conference conference) { public void updateConferenceDeadlines(Conference conference) {
eventRepository.delete(eventRepository.findAllByConference(conference)); eventRepository.delete(eventRepository.findAllByConference(conference));
createFromConference(conference); createFromObject(conference, Collections.emptyList(), false, "конференции");
}
public void createFromGrant(Grant newGrant) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newGrant.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() + "' гранта '" + newGrant.getTitle() + "'");
if (newGrant.getAuthors() != null) {
newEvent.setRecipients(new ArrayList(newGrant.getAuthors()));
}
newEvent.getRecipients().add(newGrant.getLeader());
newEvent.setGrant(newGrant);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
} }
public void updateGrantDeadlines(Grant grant) { public void updateGrantDeadlines(Grant grant) {
eventRepository.delete(eventRepository.findAllByGrant(grant)); eventRepository.delete(eventRepository.findAllByGrant(grant));
createFromGrant(grant); createFromObject(grant, Collections.emptyList(), false, "гранта");
}
public void updateProjectDeadlines(Project project) {
eventRepository.delete(eventRepository.findAllByProject(project));
createFromObject(project, Collections.emptyList(), false, "проекта");
} }
public void removeConferencesEvent(Conference conference) { public void removeConferencesEvent(Conference conference) {
@ -214,32 +173,8 @@ public class EventService {
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) { public void updateTaskDeadlines(Task task) {
eventRepository.delete(eventRepository.findAllByTask(task)); eventRepository.delete(eventRepository.findAllByTask(task));
createFromTask(task); createFromObject(task, Collections.emptyList(), true, "задачи");
} }
} }

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="anton" id="20190507_000002-1">
<addColumn tableName="event">
<column name="project_id" type="integer"/>
</addColumn>
<addForeignKeyConstraint baseTableName="event" baseColumnNames="project_id"
constraintName="fk_event_project_id" referencedTableName="project"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -2,7 +2,7 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190528_000000-3"> <changeSet author="anton" id="20190528_000002-1">
<createTable tableName="deadline_executors"> <createTable tableName="deadline_executors">
<column name="deadline_id" type="integer"/> <column name="deadline_id" type="integer"/>
<column name="executors_id" type="integer"/> <column name="executors_id" type="integer"/>

View File

@ -0,0 +1,17 @@
<?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="anton" id="20190528_000000-3">
<createTable tableName="project_grants">
<column name="project_id" type="integer"/>
<column name="grants_id" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="project_grants" baseColumnNames="project_id"
constraintName="fk_project_project_grants" referencedTableName="project"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="project_grants" baseColumnNames="grants_id"
constraintName="fk_grant_project_grants" referencedTableName="grants"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

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="anton" id="20190529_000001-1">
<addColumn tableName="file">
<column name="project_id" type="integer"/>
</addColumn>
<addForeignKeyConstraint baseTableName="file" baseColumnNames="project_id"
constraintName="fk_file_project" referencedTableName="project"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -2,9 +2,9 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190428_000000-1"> <changeSet author="anton" id="20190601_000000-1">
<update tableName="project"> <update tableName="project">
<column name="status" value="APPLICATION"/> <column name="status" value="TECHNICAL_TASK"/>
</update> </update>
</changeSet> </changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@ -35,7 +35,6 @@
<include file="db/changelog-20190422_000000-schema.xml"/> <include file="db/changelog-20190422_000000-schema.xml"/>
<include file="db/changelog-20190424_000000-schema.xml"/> <include file="db/changelog-20190424_000000-schema.xml"/>
<include file="db/changelog-20190426_000000-schema.xml"/> <include file="db/changelog-20190426_000000-schema.xml"/>
<include file="db/changelog-20190428_000000-schema.xml"/>
<include file="db/changelog-20190430_000000-schema.xml"/> <include file="db/changelog-20190430_000000-schema.xml"/>
<include file="db/changelog-20190505_000000-schema.xml"/> <include file="db/changelog-20190505_000000-schema.xml"/>
<include file="db/changelog-20190505_000001-schema.xml"/> <include file="db/changelog-20190505_000001-schema.xml"/>
@ -43,10 +42,14 @@
<include file="db/changelog-20190506_000001-schema.xml"/> <include file="db/changelog-20190506_000001-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-20190507_000002-schema.xml"/>
<include file="db/changelog-20190511_000000-schema.xml"/> <include file="db/changelog-20190511_000000-schema.xml"/>
<include file="db/changelog-20190517_000001-schema.xml"/> <include file="db/changelog-20190517_000001-schema.xml"/>
<include file="db/changelog-20190520_000000-schema.xml"/> <include file="db/changelog-20190520_000000-schema.xml"/>
<include file="db/changelog-20190523_000000-schema.xml"/> <include file="db/changelog-20190523_000000-schema.xml"/>
<include file="db/changelog-20190528_000000-schema.xml"/> <include file="db/changelog-20190528_000000-schema.xml"/>
<include file="db/changelog-20190528_000002-schema.xml"/> <include file="db/changelog-20190528_000002-schema.xml"/>
<include file="db/changelog-20190529_000000-schema.xml"/>
<include file="db/changelog-20190529_000001-schema.xml"/>
<include file="db/changelog-20190601_000001-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -40,7 +40,7 @@
</div> </div>
</div> </div>
<div class="col-md-4 col-sm-6 portfolio-item"> <div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" href="./projects/dashboard"> <a class="portfolio-link" href="./projects/projects">
<div class="portfolio-hover"> <div class="portfolio-hover">
<div class="portfolio-hover-content"> <div class="portfolio-hover-content">
<i class="fa fa-arrow-right fa-3x"></i> <i class="fa fa-arrow-right fa-3x"></i>

View File

@ -17,6 +17,7 @@
<div th:replace="projects/fragments/projectDashboardFragment :: projectDashboard(project=${project})"/> <div th:replace="projects/fragments/projectDashboardFragment :: projectDashboard(project=${project})"/>
</th:block> </th:block>
</div> </div>
<div th:replace="fragments/noRecordsFragment :: noRecords(entities=${projects}, noRecordsMessage=' одного проекта', url='project')"/>
</div> </div>
</section> </section>
</div> </div>

View File

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
</head>
<body>
<body>
<div th:fragment="filesList">
<th:block th:each="file, rowStat : *{files}">
<div class="row" th:id="|files${rowStat.index}|"
th:style="${file.deleted} ? 'display: none;' :''">
<input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/>
<input type="hidden"
th:field="*{files[__${rowStat.index}__].deleted}"/>
<input type="hidden"
th:field="*{files[__${rowStat.index}__].name}"/>
<input type="hidden"
th:field="*{files[__${rowStat.index}__].tmpFileName}"/>
<div class="col-2">
<a class="btn btn-danger float-right"
th:onclick="|$('#files${rowStat.index}\\.deleted').val('true'); $('#files${rowStat.index}').hide(); |">
<span aria-hidden="true"><i class="fa fa-times"/></span>
</a>
</div>
<div class="col-10">
<a th:onclick="${file.id==null} ? 'downloadFile('+${file.tmpFileName}+',null,\''+${file.name}+'\')':
'downloadFile(null,'+${file.id}+',\''+${file.name}+'\')' "
href="javascript:void(0)"
th:text="*{files[__${rowStat.index}__].name}">
</a>
</div>
</div>
</th:block>
</div>
</body>
</body>
</html>

View File

@ -51,12 +51,18 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="createGrant">Добавить грант:</label> <label>Добавить грант:</label>
<div th:if="*{grant} == null"> <div class="row">
<input type="submit" id="createGrant" name="createGrant" class="btn btn-primary" <div class="col-10">
value="Добавить грант"/> <select class="selectpicker form-control" data-live-search="true"
title="-- Прикрепить грант --" id="allGrants"
th:field="*{grantIds}" data-size="5">
<option th:each="grant : ${allGrants}" th:value="${grant.id}"
th:text="${grant.title}"> Грант для прикрепления
</option>
</select>
</div>
</div> </div>
<input type="hidden" th:field="*{grant.id}"/>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -113,6 +119,13 @@
value="Добавить дедлайн"/> value="Добавить дедлайн"/>
</div> </div>
<div class="form-group files-list" id="files-list">
<label>Файлы:</label>
<div th:replace="projects/fragments/projectFilesListFragment"/>
</div>
<div class="form-group"> <div class="form-group">
<label for="loader">Загрузить файл:</label> <label for="loader">Загрузить файл:</label>
<div id="loader"> <div id="loader">
@ -148,17 +161,103 @@
new FileLoader({ new FileLoader({
div: "loader", div: "loader",
url: urlFileUpload, url: urlFileUpload,
maxSize: 2, maxSize: -1,
extensions: ["doc", "docx", "xls", "jpg", "png", "pdf", "txt"], extensions: [],
callback: function (response) { callback: function (response) {
showFeedbackMessage("Файл успешно загружен"); showFeedbackMessage("Файл успешно загружен");
console.debug(response); console.debug(response);
addNewFile(response, $("#files-list"));
} }
}); });
$('.selectpicker').selectpicker(); $('.selectpicker').selectpicker();
}); });
/*]]>*/ /*]]>*/
function addNewFile(fileDto, listElement) {
var fileNumber = $('.files-list div.row').length;
var newFileRow = $("<div/>")
.attr("id", 'files' + fileNumber)
.addClass("row");
var idInput = $("<input/>")
.attr("type", "hidden")
.attr("id", "files" + fileNumber + ".id")
.attr("value", '')
.attr("name", "files[" + fileNumber + "].id");
newFileRow.append(idInput);
var flagInput = $("<input/>")
.attr("type", "hidden")
.attr("id", "files" + fileNumber + ".deleted")
.attr("value", "false")
.attr("name", "files[" + fileNumber + "].deleted");
newFileRow.append(flagInput);
var nameInput = $("<input/>")
.attr("type", "hidden")
.attr("id", "files" + fileNumber + ".name")
.attr("value", fileDto.fileName)
.attr("name", "files[" + fileNumber + "].name");
newFileRow.append(nameInput);
var tmpFileNameInput = $("<input/>")
.attr("type", "hidden")
.attr("id", "files" + fileNumber + ".tmpFileName")
.attr("value", fileDto.tmpFileName)
.attr("name", "files[" + fileNumber + "].tmpFileName");
newFileRow.append(tmpFileNameInput);
var nextDiv = $("<div/>")
.addClass("col-2");
var nextA = $("<a/>")
.addClass("btn btn-danger float-right")
.attr("onclick", "$('#files" + fileNumber + "\\\\.deleted').val('true'); $('#files" + fileNumber + "').hide();")
.append(($("<span/>").attr("aria-hidden", "true")).append($("<i/>").addClass("fa fa-times")))
;
nextDiv.append(nextA)
newFileRow.append(nextDiv);
var nameDiv = $("<div/>")
.addClass("col-10")
.append($("<a/>").text(fileDto.fileName)
.attr("href", 'javascript:void(0)')
.attr("onclick", "downloadFile('" + fileDto.tmpFileName + "',null,'" + fileDto.fileName + "')"));
newFileRow.append(nameDiv);
listElement.append(newFileRow);
}
function downloadFile(tmpName, fileId, downloadName) {
let xhr = new XMLHttpRequest();
if (fileId != null) xhr.open('GET', urlFileDownload + fileId);
if (tmpName != null) xhr.open('GET', urlFileDownloadTmp + tmpName);
xhr.responseType = 'blob';
var formData = new FormData();
if (fileId != null) formData.append("file-id", fileId);
if (tmpName != null) formData.append("tmp-file-name", tmpName);
xhr.send(formData);
xhr.onload = function () {
if (this.status == 200) {
console.debug(this.response);
var blob = new Blob([this.response], {type: '*'});
let a = document.createElement("a");
a.style = "display: none";
document.body.appendChild(a);
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = downloadName;
a.click();
window.URL.revokeObjectURL(url);
} else {
}
}
}
</script> </script>
</div> </div>

View File

@ -24,6 +24,7 @@
</div> </div>
<div class="col-md-3 col-sm-12"> <div class="col-md-3 col-sm-12">
</div> </div>
<div th:replace="fragments/noRecordsFragment :: noRecords(entities=${projects}, noRecordsMessage=' одного проекта', url='project')"/>
</div> </div>
</div> </div>
</section> </section>

View File

@ -0,0 +1,174 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import core.PageObject;
import core.TestTemplate;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import project.ProjectDashboard;
import project.ProjectPage;
import project.ProjectsPage;
import ru.ulstu.NgTrackerApplication;
import ru.ulstu.configuration.ApplicationProperties;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RunWith(SpringRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ProjectTest extends TestTemplate {
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
new ProjectPage(), Arrays.asList("ПРОЕКТЫ", "/projects/projects"),
new ProjectsPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ПРОЕКТА", "/projects/project?id=0"),
new ProjectDashboard(), Arrays.asList("ПРОЕКТЫ", "/projects/dashboard")
);
@Autowired
private ApplicationProperties applicationProperties;
@Test
public void testACreateNewProject() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(page.getKey());
ProjectPage projectPage = (ProjectPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
String name = "Project " + (new Date()).getTime();
String date = "01.01.2019";
Integer deadNum = projectPage.getDeadlineCount();
projectPage.setName(name);
projectPage.clickAddDeadline();
projectPage.addDeadlineDate(date, deadNum);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testBChangeNameAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = "Project " + (new Date()).getTime();
projectPage.clearName();
projectPage.setName(name);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testCChangeDeadlineAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
String date = "01.01.2019";
Integer deadNum = projectPage.getDeadlineCount();
projectPage.addDeadlineDate(date, deadNum);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testDSetStatusAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
projectPage.setStatus();
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testEAddDescriptionAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
String description = "Description " + (new Date()).getTime();
projectPage.addDescription(description);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testFAddLinkAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
String link = "Link " + (new Date()).getTime();
projectPage.addLink(link);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testGAddDeadlineDescriptionAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
String deadDesc = "Description " + (new Date()).getTime();
projectPage.addDeadlineDescription(deadDesc);
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testHSetDeadlineCompletionAndSave() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
projectPage.setDeadlineCompletion();
projectPage.clickSave();
Assert.assertTrue(projectsPage.checkNameInList(name));
}
@Test
public void testIDeleteDeadline() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
projectPage.clickDeleteDeadline();
Assert.assertTrue(projectPage.getDeadlineCount() == 0);
}
@Test
public void testJDeleteProject() {
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
projectsPage.getFirstProject();
String name = projectPage.getName();
projectPage.clickSave();
projectsPage.deleteFirst();
projectsPage.clickConfirm();
Assert.assertFalse(projectsPage.checkNameInList(name));
}
}

View File

@ -0,0 +1,11 @@
package project;
import core.PageObject;
import org.openqa.selenium.By;
public class ProjectDashboard extends PageObject {
public String getSubTitle() {
return driver.findElement(By.tagName("h2")).getText();
}
}

View File

@ -0,0 +1,141 @@
package project;
import core.PageObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.List;
public class ProjectPage extends PageObject {
public String getSubTitle() {
return driver.findElement(By.tagName("h3")).getText();
}
public String getId() {
return driver.findElement(By.id("id")).getAttribute("value");
}
public void setName(String name) {
driver.findElement(By.id("title")).sendKeys(name);
}
public String getName() {
return driver.findElement(By.id("title")).getAttribute("value");
}
public void clearName() {
driver.findElement(By.id("title")).clear();
}
public void clickSave() {
driver.findElement(By.id("sendMessageButton")).click();
}
public void clickAddDeadline() {
driver.findElement(By.id("addDeadline")).click();
}
public void addDeadlineDate(String deadDate, Integer deadNum) {
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate);
}
public void addDeadlineDescription(String description) {
driver.findElement(By.id("deadlines0.description")).sendKeys(description);
}
public void setDeadlineCompletion() {
driver.findElement(By.id("deadlines0.done1")).click();
}
public void setStatus() {
driver.findElement(By.id("status")).click();
getFirstStatus();
}
public void getFirstStatus() {
driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click();
}
public void addDescription(String description) {
driver.findElement(By.id("description")).sendKeys(description);
}
public void addLink(String link) {
driver.findElement(By.id("repository")).sendKeys(link);
}
public List<WebElement> getDeadlineList() {
return driver.findElements(By.className("deadline"));
}
public Integer getDeadlineCount() {
return driver.findElements(By.className("deadline")).size();
}
public void setExecutors() {
driver.findElement(By.id("status")).click();
getFirstExecutor();
}
public void getFirstExecutor() {
driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click();
}
public void setDeadlineDescription(String description, Integer i) {
driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description);
}
public void setDeadlineDate(String date, Integer i) {
driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date);
}
public Boolean isTakePartButDisabledValueTrue() {
return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true");
}
public Integer getMemberCount() {
return driver.findElements(By.className("member")).size();
}
public void clickDeleteDeadline() {
driver.findElement(By.className("btn-danger")).click();
}
public void showAllowToAttachArticles() {
driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click();
}
public void clickAddPaperBut() {
driver.findElement(By.id("add-paper")).click();
}
public List<WebElement> getArticles() {
return driver.findElements(By.className("paper"));
}
public Integer getArticlesCount() {
return driver.findElements(By.className("paper")).size();
}
public WebElement selectArticle() {
WebElement webElement = driver.findElement(By.xpath("//*[@id=\"project-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a"));
webElement.click();
return webElement;
}
public void clickUndockArticleBut() {
driver.findElement(By.name("removePaper")).click();
}
public boolean checkDeadline(String description, String dateValue) {
return getDeadlineList()
.stream()
.anyMatch(webElement -> {
return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description)
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue);
});
}
}

View File

@ -0,0 +1,41 @@
package project;
import core.PageObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.List;
public class ProjectsPage extends PageObject {
public String getSubTitle() {
return driver.findElement(By.tagName("h2")).getText();
}
public List<WebElement> getProjectsList() {
return driver.findElements(By.cssSelector("span.h6"));
}
public void getFirstProject() {
driver.findElement(By.xpath("//*[@id=\"projects\"]/div/div[2]/div[1]/div[1]/div/a")).click();
}
public void selectMember() {
driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click();
driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click();
}
public void deleteFirst() {
js.executeScript("$('a[data-confirm]').click();");
}
public void clickConfirm() {
driver.findElement(By.id("dataConfirmOK")).click();
}
public boolean checkNameInList(String newProjectName) {
return getProjectsList()
.stream()
.anyMatch(webElement -> webElement.getText().equals(newProjectName));
}
}

View File

@ -0,0 +1,148 @@
package ru.ulstu.project.service;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileData;
import ru.ulstu.file.service.FileService;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.service.GrantService;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.repository.ProjectRepository;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.io.IOException;
import java.util.*;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ProjectServiceTest {
@Mock
ProjectRepository projectRepository;
@Mock
DeadlineService deadlineService;
@Mock
EventService eventService;
@Mock
FileService fileService;
@Mock
UserService userService;
@Mock
GrantService grantService;
@InjectMocks
ProjectService projectService;
private final static String TITLE = "title";
private final static String DESCR = "descr";
private final static Integer ID = 1;
private final static Integer INDEX = 0;
private final static String NAME = "name";
private List<Project> projects;
private Project project;
private ProjectDto projectDto;
private Deadline deadline;
private List<Deadline> deadlines;
private FileData file;
private List<FileData> files;
private User user;
private GrantDto grant;
private List<GrantDto> grants;
@Before
public void setUp() throws Exception {
projects = new ArrayList<>();
project = new Project();
projects.add(project);
projectDto = new ProjectDto(project);
deadlines = new ArrayList<>();
deadline = new Deadline(new Date(), DESCR);
deadline.setId(ID);
deadlines.add(deadline);
user = new User();
user.setFirstName(NAME);
grants = new ArrayList<>();
grant = new GrantDto();
grant.setId(ID);
grants.add(grant);
}
@Test
public void findAll() {
when(projectRepository.findAll()).thenReturn(projects);
assertEquals(projects, projectService.findAll());
}
@Test
public void create() throws IOException {
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
when(projectRepository.save(new Project())).thenReturn(project);
eventService.createFromObject(new Project(), Collections.emptyList(), false, "проекта");
projectDto.setTitle(TITLE);
projectDto.setDeadlines(deadlines);
project.setId(ID);
project.setTitle(TITLE);
project.setDescription(DESCR);
project.setDeadlines(deadlines);
project.setFiles(files);
assertEquals(project.getId(), (projectService.create(projectDto)).getId());
}
@Test
public void delete() throws IOException {
when(projectRepository.exists(ID)).thenReturn(true);
when(projectRepository.findOne(ID)).thenReturn(project);
assertTrue(projectService.delete(ID));
}
@Test
public void getProjectExecutors() {
List<User> executors = Collections.singletonList(user);
when(userService.findAll()).thenReturn(executors);
assertEquals(executors, projectService.getProjectExecutors(projectDto));
}
@Test
public void findById() {
when(projectRepository.findOne(ID)).thenReturn(project);
assertEquals(project, projectService.findById(ID));
}
@Test
public void removeDeadline() throws IOException {
ProjectDto newProjectDto = new ProjectDto();
newProjectDto.getRemovedDeadlineIds().add(INDEX);
projectDto.getDeadlines().add(deadline);
ProjectDto result = projectService.removeDeadline(projectDto, INDEX);
assertEquals(newProjectDto.getDeadlines(), result.getDeadlines());
assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
}
}

View File

@ -136,7 +136,7 @@ public class TaskServiceTest {
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
when(taskRepository.save(new Task())).thenReturn(task); when(taskRepository.save(new Task())).thenReturn(task);
eventService.createFromTask(new Task()); eventService.createFromObject(new Task(), Collections.emptyList(), true, "задачи");
taskDto.setTags(tags); taskDto.setTags(tags);
taskDto.setDeadlines(deadlines); taskDto.setDeadlines(deadlines);