diff --git a/src/main/java/ru/ulstu/grant/model/Deadline.java b/src/main/java/ru/ulstu/grant/model/Deadline.java new file mode 100644 index 0000000..07ee7c5 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/Deadline.java @@ -0,0 +1,21 @@ +package ru.ulstu.grant.model; + +import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.file.model.FileData; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.Date; + +@Entity +public class Deadline extends BaseEntity { + + @ManyToOne + @JoinColumn(name = "grant_id") + private Integer grantId; + + public Integer getGrantId() { return grantId;} + public void setGrantId(Integer grantId) { this.grantId = grantId; } + +} diff --git a/src/main/java/ru/ulstu/grant/model/DeadlineDto.java b/src/main/java/ru/ulstu/grant/model/DeadlineDto.java new file mode 100644 index 0000000..f2ad56c --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/DeadlineDto.java @@ -0,0 +1,33 @@ +package ru.ulstu.grant.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; + +import javax.validation.constraints.NotNull; +import java.util.Date; + +public class DeadlineDto { + private final Integer id; + + @NotNull + private final Integer grantId; + + @JsonCreator + public DeadlineDto(@JsonProperty("id") Integer id, + @JsonProperty("grantId") Integer grantId){ + this.id = id; + this.grantId = grantId; + } + + public DeadlineDto(Deadline deadline) { + this.id = deadline.getId(); + this.grantId = deadline.getGrantId(); + } + + public Integer getId() { + return id; + } + + public Integer getGrantId() { return grantId; } +} diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java new file mode 100644 index 0000000..4d4361e --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -0,0 +1,98 @@ +package ru.ulstu.grant.model; + +import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.UserContainer; +import ru.ulstu.file.model.FileData; +import ru.ulstu.user.model.User; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +@Entity +public class Grant extends BaseEntity { + public enum GrantStatus { + APPLICATION("Заявка"), + ON_COMPETITION("Отправлен на конкурс"), + SUCCESSFUL_PASSAGE("Успешное прохождение"), + IN_WORK("В работе"), + COMPLETED("Завершен"), + FAILED("Провалены сроки"); + + private String name; + + GrantStatus(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + @NotBlank + private String title; + + @Enumerated(value = EnumType.STRING) + private GrantStatus status = GrantStatus.APPLICATION; + + @Column(name = "deadline_date") + @NotNull + private Date deadlineDate; + + //Описание гранта + @NotNull + private String comment; + + //Заявка на грант + @NotNull + private FileData application; + + @OneToOne + @JoinColumn(name = "project_id") + private Integer projectId; + + public GrantStatus getStatus() { + return status; + } + + public void setStatus(GrantStatus status) { + this.status = status; + } + + public Date getDeadlineDate() { + return deadlineDate; + } + + public void setDeadlineDate(Date deadlineDate) { + this.deadlineDate = deadlineDate; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public FileData getApplication() { + return application; + } + + public void setApplication(FileData application) { this.application = application; } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { this.title = title; } + + public Integer getProjectId() { return projectId;} + + public void setProjectId(Integer project_id) { this.projectId = projectId; } + +} diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java new file mode 100644 index 0000000..25a7875 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -0,0 +1,80 @@ +package ru.ulstu.grant.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; +import ru.ulstu.file.model.FileData; +import ru.ulstu.user.model.UserDto; + +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.Set; +import java.util.stream.Collectors; + +import static ru.ulstu.core.util.StreamApiUtils.convert; + +public class GrantDto { + private final Integer id; + @NotEmpty + private final String title; + private final Grant.GrantStatus status; + @NotNull + private final Date deadlineDate; + private final String comment; + private final String applicationFileName; + private final Integer projectId; + + @JsonCreator + public GrantDto(@JsonProperty("id") Integer id, + @JsonProperty("title") String title, + @JsonProperty("status") Grant.GrantStatus status, + @JsonProperty("deadlineDate") Date deadlineDate, + @JsonProperty("comment") String comment, + @JsonProperty("projectId") Integer projectId){ + this.id = id; + this.title = title; + this.status = status; + this.deadlineDate = deadlineDate; + this.comment = comment; + this.applicationFileName = null; + this.projectId = projectId; + } + + public GrantDto(Grant grant) { + this.id = grant.getId(); + this.title = grant.getTitle(); + this.status = grant.getStatus(); + this.deadlineDate = grant.getDeadlineDate(); + this.comment = grant.getComment(); + this.projectId = grant.getProjectId(); + this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName(); + } + + public Integer getId() { + return id; + } + + public String getTitle() { + return title; + } + + public Grant.GrantStatus getStatus() { + return status; + } + + public Date getDeadlineDate() { + return deadlineDate; + } + + public String getComment() { + return comment; + } + + public Integer getProjectId() { + return projectId; + } + + public String getApplicationFileName() { + return applicationFileName; + } +} diff --git a/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java b/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java new file mode 100644 index 0000000..dae40e2 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java @@ -0,0 +1,19 @@ +package ru.ulstu.grant.model; + +public class GrantStatusDto { + private final String id; + private final String name; + + public GrantStatusDto(Grant.GrantStatus status) { + this.id = status.name(); + this.name = status.getName(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/ru/ulstu/grant/model/Project.java b/src/main/java/ru/ulstu/grant/model/Project.java new file mode 100644 index 0000000..6c31839 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/Project.java @@ -0,0 +1,22 @@ +package ru.ulstu.grant.model; + +import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.file.model.FileData; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.Date; + +@Entity +public class Project extends BaseEntity { + + @NotBlank + private String title; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { this.title = title; } +} diff --git a/src/main/java/ru/ulstu/grant/model/ProjectDto.java b/src/main/java/ru/ulstu/grant/model/ProjectDto.java new file mode 100644 index 0000000..2a22d8a --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/ProjectDto.java @@ -0,0 +1,34 @@ +package ru.ulstu.grant.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; + +import javax.validation.constraints.NotNull; +import java.util.Date; + +public class ProjectDto { + private final Integer id; + @NotEmpty + private final String title; + + @JsonCreator + public ProjectDto(@JsonProperty("id") Integer id, + @JsonProperty("title") String title){ + this.id = id; + this.title = title; + } + + public ProjectDto(Project project) { + this.id = project.getId(); + this.title = project.getTitle(); + } + + public Integer getId() { + return id; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/resources/db/changelog-20181208_000000-schema.xml b/src/main/resources/db/changelog-20181208_000000-schema.xml new file mode 100644 index 0000000..e88b73e --- /dev/null +++ b/src/main/resources/db/changelog-20181208_000000-schema.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +