#97 copy from DTO edited
This commit is contained in:
parent
ba565746f5
commit
53cc947a17
@ -89,7 +89,7 @@ public class GrantController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/grant", params = "createProject")
|
@PostMapping(value = "/grant", params = "createProject")
|
||||||
public String createProject(@Valid GrantDto grantDto, Errors errors) {
|
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class GrantService {
|
|||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createProject(GrantDto grantDto) {
|
public void createProject(GrantDto grantDto) throws IOException {
|
||||||
grantDto.setProject(
|
grantDto.setProject(
|
||||||
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.project.model;
|
|||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.file.model.FileData;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -57,6 +58,10 @@ public class Project extends BaseEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String repository;
|
private String repository;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "file_id")
|
||||||
|
private FileData application;
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -104,4 +109,12 @@ public class Project extends BaseEntity {
|
|||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileData getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(FileData application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ public class ProjectDto {
|
|||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
private GrantDto grant;
|
private GrantDto grant;
|
||||||
private String repository;
|
private String repository;
|
||||||
|
private String applicationFileName;
|
||||||
|
|
||||||
public ProjectDto() {
|
public ProjectDto() {
|
||||||
}
|
}
|
||||||
@ -42,6 +43,7 @@ public class ProjectDto {
|
|||||||
this.grant = grant;
|
this.grant = grant;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
|
this.applicationFileName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +52,7 @@ public class ProjectDto {
|
|||||||
this.title = project.getTitle();
|
this.title = project.getTitle();
|
||||||
this.status = project.getStatus();
|
this.status = project.getStatus();
|
||||||
this.description = project.getDescription();
|
this.description = project.getDescription();
|
||||||
|
this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName();
|
||||||
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
||||||
this.repository = project.getRepository();
|
this.repository = project.getRepository();
|
||||||
this.deadlines = project.getDeadlines();
|
this.deadlines = project.getDeadlines();
|
||||||
@ -110,4 +113,12 @@ public class ProjectDto {
|
|||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getApplicationFileName() {
|
||||||
|
return applicationFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationFileName(String applicationFileName) {
|
||||||
|
this.applicationFileName = applicationFileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package ru.ulstu.project.service;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.thymeleaf.util.StringUtils;
|
import org.thymeleaf.util.StringUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.repository.ProjectRepository;
|
import ru.ulstu.project.repository.ProjectRepository;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
@ -24,11 +24,17 @@ public class ProjectService {
|
|||||||
|
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
|
private final GrantRepository grantRepository;
|
||||||
|
private final FileService fileService;
|
||||||
|
|
||||||
public ProjectService(ProjectRepository projectRepository,
|
public ProjectService(ProjectRepository projectRepository,
|
||||||
DeadlineService deadlineService) {
|
DeadlineService deadlineService,
|
||||||
|
GrantRepository grantRepository,
|
||||||
|
FileService fileService) {
|
||||||
this.projectRepository = projectRepository;
|
this.projectRepository = projectRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
|
this.grantRepository = grantRepository;
|
||||||
|
this.fileService = fileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Project> findAll() {
|
public List<Project> findAll() {
|
||||||
@ -50,21 +56,28 @@ public class ProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Project create(ProjectDto projectDto) {
|
public Project create(ProjectDto projectDto) throws IOException {
|
||||||
Project newProject = copyFromDto(new Project(), projectDto);
|
Project newProject = copyFromDto(new Project(), projectDto);
|
||||||
newProject = projectRepository.save(newProject);
|
newProject = projectRepository.save(newProject);
|
||||||
return newProject;
|
return newProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Project copyFromDto(Project project, ProjectDto projectDto) {
|
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
||||||
project.setDescription(projectDto.getDescription());
|
project.setDescription(projectDto.getDescription());
|
||||||
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());
|
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());
|
||||||
project.setTitle(projectDto.getTitle());
|
project.setTitle(projectDto.getTitle());
|
||||||
|
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
|
||||||
|
project.setGrant(grantRepository.findOne(projectDto.getGrant().getId()));
|
||||||
|
}
|
||||||
project.setRepository(projectDto.getRepository());
|
project.setRepository(projectDto.getRepository());
|
||||||
|
project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines()));
|
||||||
|
if (projectDto.getApplicationFileName() != null) {
|
||||||
|
project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName()));
|
||||||
|
}
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project save(ProjectDto projectDto) {
|
public Project save(ProjectDto projectDto) throws IOException {
|
||||||
if (isEmpty(projectDto.getId())) {
|
if (isEmpty(projectDto.getId())) {
|
||||||
return create(projectDto);
|
return create(projectDto);
|
||||||
} else {
|
} else {
|
||||||
|
16
src/main/resources/db/changelog-20190422_000000-schema.xml
Normal file
16
src/main/resources/db/changelog-20190422_000000-schema.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?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="anton" id="20190418_000000-1">
|
||||||
|
<addColumn tableName="project">
|
||||||
|
<column name="file_id" type="integer"/>
|
||||||
|
</addColumn>
|
||||||
|
<addForeignKeyConstraint baseTableName="project" baseColumnNames="file_id"
|
||||||
|
constraintName="fk_project_file_id" referencedTableName="file"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addColumn tableName="project">
|
||||||
|
<column name="applicationFileName" type="varchar(255)"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -31,4 +31,5 @@
|
|||||||
<include file="db/changelog-20190402_000000-schema.xml"/>
|
<include file="db/changelog-20190402_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190404_000000-schema.xml"/>
|
<include file="db/changelog-20190404_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190421_000000-schema.xml"/>
|
<include file="db/changelog-20190421_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190422_000000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user