#98 executors list added

This commit is contained in:
a.vasin 2019-05-28 11:12:27 +04:00
parent 8d1e410e83
commit 3b0a2dd964
9 changed files with 67 additions and 32 deletions

View File

@ -4,11 +4,11 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
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.user.model.User;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@ -20,7 +20,9 @@ public class Deadline extends BaseEntity {
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date; private Date date;
private Integer executor; @OneToMany(targetEntity=User.class, fetch=FetchType.EAGER)
private List<User> executors;
private Boolean done; private Boolean done;
public Deadline() { public Deadline() {
@ -31,10 +33,10 @@ public class Deadline extends BaseEntity {
this.description = description; this.description = description;
} }
public Deadline(Date deadlineDate, String description, Integer executor, Boolean done) { public Deadline(Date deadlineDate, String description, List<User> executors, Boolean done) {
this.date = deadlineDate; this.date = deadlineDate;
this.description = description; this.description = description;
this.executor = executor; this.executors = executors;
this.done = done; this.done = done;
} }
@ -42,12 +44,12 @@ public class Deadline extends BaseEntity {
public Deadline(@JsonProperty("id") Integer id, public Deadline(@JsonProperty("id") Integer id,
@JsonProperty("description") String description, @JsonProperty("description") String description,
@JsonProperty("date") Date date, @JsonProperty("date") Date date,
@JsonProperty("executor") Integer executor, @JsonProperty("executors") List<User> executors,
@JsonProperty("done") Boolean done) { @JsonProperty("done") Boolean done) {
this.setId(id); this.setId(id);
this.description = description; this.description = description;
this.date = date; this.date = date;
this.executor = executor; this.executors = executors;
this.done = done; this.done = done;
} }
@ -67,12 +69,12 @@ public class Deadline extends BaseEntity {
this.date = date; this.date = date;
} }
public Integer getExecutor() { public List<User> getExecutors() {
return executor; return executors;
} }
public void setExecutor(Integer executor) { public void setExecutors(List<User> executors) {
this.executor = executor; this.executors = executors;
} }
public Boolean getDone() { public Boolean getDone() {
@ -103,12 +105,12 @@ public class Deadline extends BaseEntity {
return getId().equals(deadline.getId()) && return getId().equals(deadline.getId()) &&
description.equals(deadline.description) && description.equals(deadline.description) &&
date.equals(deadline.date) && date.equals(deadline.date) &&
executor.equals(deadline.executor) && executors.equals(deadline.executors) &&
done.equals(deadline.done); done.equals(deadline.done);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(super.hashCode(), description, date, executor, done); return Objects.hash(super.hashCode(), description, date, executors, done);
} }
} }

View File

@ -30,7 +30,7 @@ public class DeadlineService {
Deadline updateDeadline = deadlineRepository.findOne(deadline.getId()); Deadline updateDeadline = deadlineRepository.findOne(deadline.getId());
updateDeadline.setDate(deadline.getDate()); updateDeadline.setDate(deadline.getDate());
updateDeadline.setDescription(deadline.getDescription()); updateDeadline.setDescription(deadline.getDescription());
updateDeadline.setExecutor(deadline.getExecutor()); updateDeadline.setExecutors(deadline.getExecutors());
updateDeadline.setDone(deadline.getDone()); updateDeadline.setDone(deadline.getDone());
deadlineRepository.save(updateDeadline); deadlineRepository.save(updateDeadline);
return updateDeadline; return updateDeadline;
@ -41,7 +41,7 @@ public class DeadlineService {
Deadline newDeadline = new Deadline(); Deadline newDeadline = new Deadline();
newDeadline.setDate(deadline.getDate()); newDeadline.setDate(deadline.getDate());
newDeadline.setDescription(deadline.getDescription()); newDeadline.setDescription(deadline.getDescription());
newDeadline.setExecutor(deadline.getExecutor()); newDeadline.setExecutors(deadline.getExecutors());
newDeadline.setDone(deadline.getDone()); newDeadline.setDone(deadline.getDone());
newDeadline = deadlineRepository.save(newDeadline); newDeadline = deadlineRepository.save(newDeadline);
return newDeadline; return newDeadline;

View File

@ -27,7 +27,7 @@ import java.util.Set;
public class Project extends BaseEntity implements UserContainer { public class Project extends BaseEntity implements UserContainer {
public enum ProjectStatus { public enum ProjectStatus {
TT("ТЗ"), TECHNICAL_TASK("Техническое задание"),
OPEN("Открыт"), OPEN("Открыт"),
IN_WORK("В работе"), IN_WORK("В работе"),
CERTIFICATE_ISSUED("Оформление свидетельства"), CERTIFICATE_ISSUED("Оформление свидетельства"),
@ -49,7 +49,7 @@ public class Project extends BaseEntity implements UserContainer {
private String title; private String title;
@Enumerated(value = EnumType.STRING) @Enumerated(value = EnumType.STRING)
private ProjectStatus status = ProjectStatus.TT; private ProjectStatus status = ProjectStatus.TECHNICAL_TASK;
@NotNull @NotNull
private String description; private String description;
@ -69,8 +69,8 @@ public class Project extends BaseEntity implements UserContainer {
@JoinColumn(name = "file_id") @JoinColumn(name = "file_id")
private FileData application; private FileData application;
@ManyToMany(fetch = FetchType.EAGER) @ManyToMany(fetch = FetchType.LAZY)
private Set<User> executors = new HashSet<>(); private List<User> executors = new ArrayList<>();
public String getTitle() { public String getTitle() {
return title; return title;
@ -128,16 +128,17 @@ public class Project extends BaseEntity implements UserContainer {
this.application = application; this.application = application;
} }
public Set<User> getExecutors() { public List<User> getExecutors() {
return executors; return executors;
} }
public void setExecutors(Set<User> executors) { public void setExecutors(List<User> executors) {
this.executors = executors; this.executors = executors;
} }
@Override @Override
public Set<User> getUsers() { public Set<User> getUsers() {
return getExecutors(); Set<User> users = new HashSet<User>(getExecutors());
return users;
} }
} }

View File

@ -6,9 +6,11 @@ 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.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -28,7 +30,7 @@ public class ProjectDto {
private String applicationFileName; private String applicationFileName;
private List<Integer> removedDeadlineIds = new ArrayList<>(); private List<Integer> removedDeadlineIds = new ArrayList<>();
private Set<Integer> executorIds; private Set<Integer> executorIds;
private Set<UserDto> executors; private List<UserDto> executors;
private boolean hasAge; private boolean hasAge;
private boolean hasDegree; private boolean hasDegree;
@ -50,7 +52,7 @@ public class ProjectDto {
@JsonProperty("repository") String repository, @JsonProperty("repository") String repository,
@JsonProperty("deadlines") List<Deadline> deadlines, @JsonProperty("deadlines") List<Deadline> deadlines,
@JsonProperty("executorIds") Set<Integer> executorIds, @JsonProperty("executorIds") Set<Integer> executorIds,
@JsonProperty("executors") Set<UserDto> executors, @JsonProperty("executors") List<UserDto> executors,
@JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree) { @JsonProperty("hasDegree") boolean hasDegree) {
this.id = id; this.id = id;
@ -69,6 +71,7 @@ public class ProjectDto {
public ProjectDto(Project project) { public ProjectDto(Project project) {
Set<User> users = new HashSet<User>(project.getExecutors());
this.id = project.getId(); this.id = project.getId();
this.title = project.getTitle(); this.title = project.getTitle();
this.status = project.getStatus(); this.status = project.getStatus();
@ -77,7 +80,7 @@ public class ProjectDto {
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(project.getExecutors(), user -> user.getId()); this.executorIds = convert(users, user -> user.getId());
this.executors = convert(project.getExecutors(), UserDto::new); this.executors = convert(project.getExecutors(), UserDto::new);
} }
@ -161,11 +164,11 @@ public class ProjectDto {
this.executorIds = executorIds; this.executorIds = executorIds;
} }
public Set<UserDto> getExecutors() { public List<UserDto> getExecutors() {
return executors; return executors;
} }
public void setExecutors(Set<UserDto> executors) { public void setExecutors(List<UserDto> executors) {
this.executors = executors; this.executors = executors;
} }

View File

@ -5,7 +5,6 @@ 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.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;
@ -19,7 +18,7 @@ import java.util.List;
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.TT; import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
@Service @Service
public class ProjectService { public class ProjectService {
@ -89,7 +88,7 @@ public class ProjectService {
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
project.setDescription(projectDto.getDescription()); project.setDescription(projectDto.getDescription());
project.setStatus(projectDto.getStatus() == null ? TT : projectDto.getStatus()); project.setStatus(projectDto.getStatus() == null ? TECHNICAL_TASK : projectDto.getStatus());
project.setTitle(projectDto.getTitle()); project.setTitle(projectDto.getTitle());
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) { if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
project.setGrant(grantRepository.findOne(projectDto.getGrant().getId())); project.setGrant(grantRepository.findOne(projectDto.getGrant().getId()));

View File

@ -0,0 +1,11 @@
<?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-1">
<renameColumn tableName="deadline"
columnDataType="integer"
newColumnName="executors"
oldColumnName="executor"/>
</changeSet>
</databaseChangeLog>

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-1">
<createTable tableName="deadline_executors">
<column name="deadline_id" type="integer"/>
<column name="executors" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="deadline_id"
constraintName="fk_deadline_deadline_executors" referencedTableName="deadline"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="executors"
constraintName="fk_user_deadline_executors" referencedTableName="users"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -47,4 +47,6 @@
<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_000001-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -6,7 +6,7 @@
<body> <body>
<span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x"> <span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x">
<th:block th:switch="${projectStatus.name()}"> <th:block th:switch="${projectStatus.name()}">
<div th:case="'TT'"> <div th:case="'TECHNICAL_TASK'">
<i class="fa fa-circle fa-stack-2x text-draft"></i> <i class="fa fa-circle fa-stack-2x text-draft"></i>
</div> </div>
<div th:case="'OPEN'"> <div th:case="'OPEN'">