Merge branch 'master' into 46-mvc
# Conflicts: # src/main/java/ru/ulstu/paper/controller/PaperController.java # src/main/java/ru/ulstu/paper/model/Paper.java # src/main/java/ru/ulstu/paper/model/PaperDto.java # src/main/resources/public/js/papers.js # src/main/resources/templates/papers/paper.html # src/main/resources/templates/papers/papers.htmlpull/149/head
commit
ac569ed9a9
Binary file not shown.
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Deadline extends BaseEntity {
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Deadline() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Deadline(Date deadlineDate, String description) {
|
||||||
|
this.date = deadlineDate;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DeadlineDto {
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private final Date date;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public DeadlineDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("description") String description,
|
||||||
|
@JsonProperty("date") Date date) {
|
||||||
|
this.id = id;
|
||||||
|
this.description = description;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Deadline deadline) {
|
||||||
|
this.id = deadline.getId();
|
||||||
|
this.description = deadline.getDescription();
|
||||||
|
this.date = deadline.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ru.ulstu.deadline.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package ru.ulstu.deadline.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeadlineService {
|
||||||
|
private final DeadlineRepository deadlineRepository;
|
||||||
|
|
||||||
|
public DeadlineService(DeadlineRepository deadlineRepository) {
|
||||||
|
this.deadlineRepository = deadlineRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> saveOrCreate(List<DeadlineDto> deadlines) {
|
||||||
|
return deadlines.stream().map(deadlineDto -> {
|
||||||
|
return deadlineDto.getId() != null ? update(deadlineDto) : create(deadlineDto);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline update(DeadlineDto deadlineDto) {
|
||||||
|
Deadline deadline = deadlineRepository.findOne(deadlineDto.getId());
|
||||||
|
deadlineRepository.save(copyFromDto(deadline, deadlineDto));
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(DeadlineDto deadlineDto) {
|
||||||
|
Deadline newDeadline = copyFromDto(new Deadline(), deadlineDto);
|
||||||
|
newDeadline = deadlineRepository.save(newDeadline);
|
||||||
|
return newDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||||
|
deadline.setDate(deadlineDto.getDate());
|
||||||
|
deadline.setDescription(deadlineDto.getDescription());
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
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.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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;
|
||||||
|
private final List<DeadlineDto> deadlines;
|
||||||
|
private final String comment;
|
||||||
|
private final String applicationFileName;
|
||||||
|
private final ProjectDto project;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public GrantDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("title") String title,
|
||||||
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("project") ProjectDto project) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
this.status = status;
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
this.comment = comment;
|
||||||
|
this.applicationFileName = null;
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(Grant grant) {
|
||||||
|
this.id = grant.getId();
|
||||||
|
this.title = grant.getTitle();
|
||||||
|
this.status = grant.getStatus();
|
||||||
|
this.deadlines = convert(grant.getDeadlines(), DeadlineDto::new);
|
||||||
|
this.comment = grant.getComment();
|
||||||
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||||
|
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 List<DeadlineDto> getDeadlines() {
|
||||||
|
return deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectDto getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplicationFileName() {
|
||||||
|
return applicationFileName;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Project extends BaseEntity {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "project_id")
|
||||||
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> getDeadlines() {
|
||||||
|
return deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class ProjectDto {
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
private final List<DeadlineDto> deadlines;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public ProjectDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("title") String title,
|
||||||
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectDto(Project project) {
|
||||||
|
this.id = project.getId();
|
||||||
|
this.title = project.getTitle();
|
||||||
|
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
<?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="project">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="title" type="varchar(255)"/>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_project" tableName="project"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
|
||||||
|
<changeSet author="tanya" id="20181208_000000-2">
|
||||||
|
<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="file_id" type="integer"/>
|
||||||
|
<column name="applicationFileName" type="varchar(255)">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_grant" tableName="grant"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="project_id"
|
||||||
|
constraintName="fk_grant_project_id" referencedTableName="project"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="file_id"
|
||||||
|
constraintName="fk_grant_file_id" referencedTableName="file"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet author="orion" id="20181211_000000-3">
|
||||||
|
<createTable tableName="deadline">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="date" type="timestamp"/>
|
||||||
|
<column name="description" type="varchar(255)"/>
|
||||||
|
<column name="project_id" type="integer"/>
|
||||||
|
<column name="grant_id" type="integer"/>
|
||||||
|
<column name="paper_id" type="integer"/>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_deadline" tableName="deadline"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="project_id"
|
||||||
|
constraintName="fk_deadline_project_id" referencedTableName="project"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="grant_id"
|
||||||
|
constraintName="fk_deadline_grant_id" referencedTableName="grant"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="paper_id"
|
||||||
|
constraintName="fk_deadline_paper_id" referencedTableName="paper"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
Loading…
Reference in New Issue