diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 3a54bec..97b6441 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -4,11 +4,11 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; -import javax.persistence.Entity; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; +import javax.persistence.*; import java.util.Date; +import java.util.List; import java.util.Objects; @Entity @@ -20,7 +20,9 @@ public class Deadline extends BaseEntity { @DateTimeFormat(pattern = "yyyy-MM-dd") private Date date; - private Integer executor; + @OneToMany(targetEntity=User.class, fetch=FetchType.EAGER) + private List executors; + private Boolean done; public Deadline() { @@ -31,10 +33,10 @@ public class Deadline extends BaseEntity { this.description = description; } - public Deadline(Date deadlineDate, String description, Integer executor, Boolean done) { + public Deadline(Date deadlineDate, String description, List executors, Boolean done) { this.date = deadlineDate; this.description = description; - this.executor = executor; + this.executors = executors; this.done = done; } @@ -42,12 +44,12 @@ public class Deadline extends BaseEntity { public Deadline(@JsonProperty("id") Integer id, @JsonProperty("description") String description, @JsonProperty("date") Date date, - @JsonProperty("executor") Integer executor, + @JsonProperty("executors") List executors, @JsonProperty("done") Boolean done) { this.setId(id); this.description = description; this.date = date; - this.executor = executor; + this.executors = executors; this.done = done; } @@ -67,12 +69,12 @@ public class Deadline extends BaseEntity { this.date = date; } - public Integer getExecutor() { - return executor; + public List getExecutors() { + return executors; } - public void setExecutor(Integer executor) { - this.executor = executor; + public void setExecutors(List executors) { + this.executors = executors; } public Boolean getDone() { @@ -103,12 +105,12 @@ public class Deadline extends BaseEntity { return getId().equals(deadline.getId()) && description.equals(deadline.description) && date.equals(deadline.date) && - executor.equals(deadline.executor) && + executors.equals(deadline.executors) && done.equals(deadline.done); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), description, date, executor, done); + return Objects.hash(super.hashCode(), description, date, executors, done); } } diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 83f1afb..9c45537 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -30,7 +30,7 @@ public class DeadlineService { Deadline updateDeadline = deadlineRepository.findOne(deadline.getId()); updateDeadline.setDate(deadline.getDate()); updateDeadline.setDescription(deadline.getDescription()); - updateDeadline.setExecutor(deadline.getExecutor()); + updateDeadline.setExecutors(deadline.getExecutors()); updateDeadline.setDone(deadline.getDone()); deadlineRepository.save(updateDeadline); return updateDeadline; @@ -41,7 +41,7 @@ public class DeadlineService { Deadline newDeadline = new Deadline(); newDeadline.setDate(deadline.getDate()); newDeadline.setDescription(deadline.getDescription()); - newDeadline.setExecutor(deadline.getExecutor()); + newDeadline.setExecutors(deadline.getExecutors()); newDeadline.setDone(deadline.getDone()); newDeadline = deadlineRepository.save(newDeadline); return newDeadline; diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index cf0de14..3d11583 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -27,7 +27,7 @@ import java.util.Set; public class Project extends BaseEntity implements UserContainer { public enum ProjectStatus { - TT("ТЗ"), + TECHNICAL_TASK("Техническое задание"), OPEN("Открыт"), IN_WORK("В работе"), CERTIFICATE_ISSUED("Оформление свидетельства"), @@ -49,7 +49,7 @@ public class Project extends BaseEntity implements UserContainer { private String title; @Enumerated(value = EnumType.STRING) - private ProjectStatus status = ProjectStatus.TT; + private ProjectStatus status = ProjectStatus.TECHNICAL_TASK; @NotNull private String description; @@ -69,8 +69,8 @@ public class Project extends BaseEntity implements UserContainer { @JoinColumn(name = "file_id") private FileData application; - @ManyToMany(fetch = FetchType.EAGER) - private Set executors = new HashSet<>(); + @ManyToMany(fetch = FetchType.LAZY) + private List executors = new ArrayList<>(); public String getTitle() { return title; @@ -128,16 +128,17 @@ public class Project extends BaseEntity implements UserContainer { this.application = application; } - public Set getExecutors() { + public List getExecutors() { return executors; } - public void setExecutors(Set executors) { + public void setExecutors(List executors) { this.executors = executors; } @Override public Set getUsers() { - return getExecutors(); + Set users = new HashSet(getExecutors()); + return users; } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 0292f1f..f6ee831 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -6,9 +6,11 @@ import org.hibernate.validator.constraints.NotEmpty; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -28,7 +30,7 @@ public class ProjectDto { private String applicationFileName; private List removedDeadlineIds = new ArrayList<>(); private Set executorIds; - private Set executors; + private List executors; private boolean hasAge; private boolean hasDegree; @@ -50,7 +52,7 @@ public class ProjectDto { @JsonProperty("repository") String repository, @JsonProperty("deadlines") List deadlines, @JsonProperty("executorIds") Set executorIds, - @JsonProperty("executors") Set executors, + @JsonProperty("executors") List executors, @JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasDegree") boolean hasDegree) { this.id = id; @@ -69,6 +71,7 @@ public class ProjectDto { public ProjectDto(Project project) { + Set users = new HashSet(project.getExecutors()); this.id = project.getId(); this.title = project.getTitle(); this.status = project.getStatus(); @@ -77,7 +80,7 @@ public class ProjectDto { this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.repository = project.getRepository(); 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); } @@ -161,11 +164,11 @@ public class ProjectDto { this.executorIds = executorIds; } - public Set getExecutors() { + public List getExecutors() { return executors; } - public void setExecutors(Set executors) { + public void setExecutors(List executors) { this.executors = executors; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 2b9e82b..ab2fa91 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -5,7 +5,6 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; -import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -19,7 +18,7 @@ import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; 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 public class ProjectService { @@ -89,7 +88,7 @@ public class ProjectService { private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { 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()); if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) { project.setGrant(grantRepository.findOne(projectDto.getGrant().getId())); diff --git a/src/main/resources/db/changelog-20190528_000000-schema.xml b/src/main/resources/db/changelog-20190528_000000-schema.xml new file mode 100644 index 0000000..02ba642 --- /dev/null +++ b/src/main/resources/db/changelog-20190528_000000-schema.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/src/main/resources/db/changelog-20190528_000001-schema.xml b/src/main/resources/db/changelog-20190528_000001-schema.xml new file mode 100644 index 0000000..0605b48 --- /dev/null +++ b/src/main/resources/db/changelog-20190528_000001-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index b4ce865..fbc1ec3 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -47,4 +47,6 @@ + + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectStatusFragment.html b/src/main/resources/templates/projects/fragments/projectStatusFragment.html index c56958e..bf0d3f6 100644 --- a/src/main/resources/templates/projects/fragments/projectStatusFragment.html +++ b/src/main/resources/templates/projects/fragments/projectStatusFragment.html @@ -6,7 +6,7 @@ -
+