Create model for grant, deadline and project
This commit is contained in:
parent
724dd6a78a
commit
590cd16abe
21
src/main/java/ru/ulstu/grant/model/Deadline.java
Normal file
21
src/main/java/ru/ulstu/grant/model/Deadline.java
Normal file
@ -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; }
|
||||
|
||||
}
|
33
src/main/java/ru/ulstu/grant/model/DeadlineDto.java
Normal file
33
src/main/java/ru/ulstu/grant/model/DeadlineDto.java
Normal file
@ -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; }
|
||||
}
|
98
src/main/java/ru/ulstu/grant/model/Grant.java
Normal file
98
src/main/java/ru/ulstu/grant/model/Grant.java
Normal file
@ -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; }
|
||||
|
||||
}
|
80
src/main/java/ru/ulstu/grant/model/GrantDto.java
Normal file
80
src/main/java/ru/ulstu/grant/model/GrantDto.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
19
src/main/java/ru/ulstu/grant/model/GrantStatusDto.java
Normal file
19
src/main/java/ru/ulstu/grant/model/GrantStatusDto.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
22
src/main/java/ru/ulstu/grant/model/Project.java
Normal file
22
src/main/java/ru/ulstu/grant/model/Project.java
Normal file
@ -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; }
|
||||
}
|
34
src/main/java/ru/ulstu/grant/model/ProjectDto.java
Normal file
34
src/main/java/ru/ulstu/grant/model/ProjectDto.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
45
src/main/resources/db/changelog-20181208_000000-schema.xml
Normal file
45
src/main/resources/db/changelog-20181208_000000-schema.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?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="tanya" id="20181208_000000-1">
|
||||
<createTable tableName="grant">
|
||||
<column name="id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="title" type="varchar(255)"/>
|
||||
<column name="status" type="varchar(255)"/>
|
||||
<column name="deadline_date" type="timestamp"/>
|
||||
<column name="comment" type="varchar(255)"/>
|
||||
<column name="project_id" type="integer"/>
|
||||
<column name="applicationFileName" type="varchar(255)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addPrimaryKey columnNames="id" constraintName="pk_grant" tableName="grant"/>
|
||||
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="project_id"
|
||||
constraintName="fk_project_project_id" referencedTableName="project"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
<changeSet author="tanya" id="20181208_000000-2">
|
||||
<createTable tableName="project">
|
||||
<column name="id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="title" type="varchar(255)"/>
|
||||
</createTable>
|
||||
<addPrimaryKey columnNames="id" constraintName="pk_project" tableName="project"/>
|
||||
</changeSet>
|
||||
<changeSet author="tanya" id="20181208_000000-3">
|
||||
<createTable tableName="deadline">
|
||||
<column name="id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="grant_id" type="integer"/>
|
||||
</createTable>
|
||||
<addPrimaryKey columnNames="id" constraintName="pk_deadline" tableName="deadline"/>
|
||||
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="grant_id"
|
||||
constraintName="fk_grant_grant_id" referencedTableName="grant"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user