From 7b601c744fb7b9802c3e053c7b0f5de124a117b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Mon, 18 Mar 2019 11:07:30 +0400 Subject: [PATCH] #13 change model, schema --- src/main/java/ru/ulstu/paper/model/Paper.java | 38 ++++++------------- .../java/ru/ulstu/paper/model/PaperDto.java | 6 +-- .../ru/ulstu/paper/service/PaperService.java | 30 ++++++--------- .../db/changelog-20190318_000000-schema.xml | 23 +++++++++++ src/main/resources/db/changelog-master.xml | 1 + 5 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 src/main/resources/db/changelog-20190318_000000-schema.xml diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index c09fd28..f98b54b 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -9,26 +9,8 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.user.model.User; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import javax.persistence.*; +import java.util.*; @Entity public class Paper extends BaseEntity implements UserContainer { @@ -77,9 +59,11 @@ public class Paper extends BaseEntity implements UserContainer { private Boolean locked = false; - @ManyToOne - @JoinColumn(name = "file_id") - private FileData fileData; + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "paper_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List files = new ArrayList<>(); @ManyToMany(fetch = FetchType.EAGER) private Set authors = new HashSet<>(); @@ -132,12 +116,12 @@ public class Paper extends BaseEntity implements UserContainer { this.locked = locked; } - public FileData getFileData() { - return fileData; + public List getFiles() { + return files; } - public void setFileData(FileData fileData) { - this.fileData = fileData; + public void setFiles(List files) { + this.files = files; } public String getTitle() { diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 545b432..f870dc3 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -79,9 +79,9 @@ public class PaperDto { this.comment = paper.getComment(); this.locked = paper.getLocked(); this.tmpFileName = null; - this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); - this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); - this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); +// this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); +// this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); +// this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); this.authorIds = convert(paper.getAuthors(), user -> user.getId()); this.authors = convert(paper.getAuthors(), UserDto::new); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 9df8be2..39c2ace 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -14,20 +14,12 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; -import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION; -import static ru.ulstu.paper.model.Paper.PaperStatus.COMPLETED; -import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; -import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED; -import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; +import static ru.ulstu.paper.model.Paper.PaperStatus.*; @Service public class PaperService { @@ -88,9 +80,9 @@ public class PaperService { paper.setTitle(paperDto.getTitle()); paper.setUpdateDate(new Date()); paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines())); - if (paperDto.getTmpFileName() != null) { - paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); - } +// if (paperDto.getTmpFileName() != null) { +// paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); +// } paper.getAuthors().clear(); if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); @@ -103,9 +95,9 @@ public class PaperService { Paper paper = paperRepository.findOne(paperDto.getId()); Paper.PaperStatus oldStatus = paper.getStatus(); Set oldAuthors = new HashSet<>(paper.getAuthors()); - if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { - fileService.deleteFile(paper.getFileData()); - } +// if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { +// fileService.deleteFile(paper.getFileData()); +// } paperRepository.save(copyFromDto(paper, paperDto)); paper.getAuthors().forEach(author -> { @@ -124,9 +116,9 @@ public class PaperService { @Transactional public void delete(Integer paperId) throws IOException { Paper paper = paperRepository.findOne(paperId); - if (paper.getFileData() != null) { - fileService.deleteFile(paper.getFileData()); - } +// if (paper.getFileData() != null) { +// fileService.deleteFile(paper.getFileData()); +// } paperRepository.delete(paper); } diff --git a/src/main/resources/db/changelog-20190318_000000-schema.xml b/src/main/resources/db/changelog-20190318_000000-schema.xml new file mode 100644 index 0000000..d1966b4 --- /dev/null +++ b/src/main/resources/db/changelog-20190318_000000-schema.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index b8654ae..dcba122 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -18,5 +18,6 @@ + \ No newline at end of file