206 lines
5.2 KiB
Java
206 lines
5.2 KiB
Java
package ru.ulstu.project.model;
|
||
|
||
import org.hibernate.annotations.Fetch;
|
||
import org.hibernate.annotations.FetchMode;
|
||
import org.hibernate.validator.constraints.NotBlank;
|
||
import ru.ulstu.core.model.BaseEntity;
|
||
import ru.ulstu.core.model.EventSource;
|
||
import ru.ulstu.core.model.UserActivity;
|
||
import ru.ulstu.deadline.model.Deadline;
|
||
import ru.ulstu.file.model.FileData;
|
||
import ru.ulstu.grant.model.Grant;
|
||
import ru.ulstu.timeline.model.Event;
|
||
import ru.ulstu.activity.model.Activity;
|
||
import ru.ulstu.user.model.User;
|
||
|
||
import javax.persistence.CascadeType;
|
||
import javax.persistence.DiscriminatorValue;
|
||
import javax.persistence.Entity;
|
||
import javax.persistence.EnumType;
|
||
import javax.persistence.Enumerated;
|
||
import javax.persistence.FetchType;
|
||
import javax.persistence.JoinColumn;
|
||
import javax.persistence.JoinTable;
|
||
import javax.persistence.ManyToMany;
|
||
import javax.persistence.ManyToOne;
|
||
import javax.persistence.OneToMany;
|
||
import javax.validation.constraints.NotNull;
|
||
import java.util.ArrayList;
|
||
import java.util.Collections;
|
||
import java.util.HashSet;
|
||
import java.util.List;
|
||
import java.util.Set;
|
||
|
||
@Entity
|
||
@DiscriminatorValue("PROJECT")
|
||
public class Project extends BaseEntity implements UserActivity, EventSource {
|
||
|
||
public enum ProjectStatus {
|
||
TECHNICAL_TASK("Техническое задание"),
|
||
OPEN("Открыт"),
|
||
IN_WORK("В работе"),
|
||
CERTIFICATE_ISSUED("Оформление свидетельства"),
|
||
CLOSED("Закрыт"),
|
||
FAILED("Провалены сроки");
|
||
|
||
private String statusName;
|
||
|
||
ProjectStatus(String statusName) {
|
||
this.statusName = statusName;
|
||
}
|
||
|
||
public String getStatusName() {
|
||
return statusName;
|
||
}
|
||
}
|
||
|
||
@NotBlank
|
||
private String title;
|
||
|
||
@Enumerated(value = EnumType.STRING)
|
||
private ProjectStatus status = ProjectStatus.TECHNICAL_TASK;
|
||
|
||
@NotNull
|
||
private String description;
|
||
|
||
@OneToMany(cascade = CascadeType.ALL)
|
||
@JoinColumn(name = "project_id")
|
||
private List<Deadline> deadlines = new ArrayList<>();
|
||
|
||
@ManyToOne(cascade = CascadeType.ALL)
|
||
@JoinColumn(name = "grant_id")
|
||
private Grant grant;
|
||
|
||
@NotNull
|
||
private String repository;
|
||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||
@JoinColumn(name = "project_id", unique = true)
|
||
@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)
|
||
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() {
|
||
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 Activity.ActivityState getCommonActivityState() {
|
||
switch (this.status) {
|
||
case IN_WORK:
|
||
return Activity.ActivityState.TOOK_IN_WORK;
|
||
case CLOSED:
|
||
return Activity.ActivityState.COMPLETED;
|
||
default:
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public void setTitle(String title) {
|
||
this.title = title;
|
||
}
|
||
|
||
public ProjectStatus getStatus() {
|
||
return status;
|
||
}
|
||
|
||
public void setStatus(ProjectStatus status) {
|
||
this.status = status;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
|
||
public void setDescription(String description) {
|
||
this.description = description;
|
||
}
|
||
|
||
public Grant getGrant() {
|
||
return grant;
|
||
}
|
||
|
||
public void setGrant(Grant grant) {
|
||
this.grant = grant;
|
||
}
|
||
|
||
public String getRepository() {
|
||
return repository;
|
||
}
|
||
|
||
public void setRepository(String repository) {
|
||
this.repository = repository;
|
||
}
|
||
|
||
public List<Deadline> getDeadlines() {
|
||
return deadlines;
|
||
}
|
||
|
||
public void setDeadlines(List<Deadline> deadlines) {
|
||
this.deadlines = deadlines;
|
||
}
|
||
|
||
public List<FileData> getFiles() {
|
||
return files;
|
||
}
|
||
|
||
public void setFiles(List<FileData> files) {
|
||
this.files = files;
|
||
}
|
||
|
||
public List<Event> getEvents() {
|
||
return events;
|
||
}
|
||
|
||
public void setEvents(List<Event> events) {
|
||
this.events = events;
|
||
}
|
||
|
||
public List<User> getExecutors() {
|
||
return executors;
|
||
}
|
||
|
||
public void setExecutors(List<User> executors) {
|
||
this.executors = executors;
|
||
}
|
||
|
||
public Set<User> getUsers() {
|
||
return new HashSet<>(getExecutors());
|
||
}
|
||
|
||
@Override
|
||
public Set<User> getActivityUsers() {
|
||
return new HashSet<>();
|
||
}
|
||
|
||
public List<Grant> getGrants() {
|
||
return grants;
|
||
}
|
||
|
||
public void setGrants(List<Grant> grants) {
|
||
this.grants = grants;
|
||
}
|
||
}
|