From cb394edf907e66f35d70ce2103faae2e09b0f7ca 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 16:02:55 +0400 Subject: [PATCH] #13 file list on paper page --- .../java/ru/ulstu/file/model/FileDataDto.java | 11 +++++++++- .../ru/ulstu/file/service/FileService.java | 6 +++++ .../ru/ulstu/paper/service/PaperService.java | 8 ++++++- .../db/changelog-20190318_000000-schema.xml | 11 ---------- .../resources/templates/papers/paper.html | 22 +++++++++++++++++++ 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/file/model/FileDataDto.java b/src/main/java/ru/ulstu/file/model/FileDataDto.java index d59f75b..fda3e81 100644 --- a/src/main/java/ru/ulstu/file/model/FileDataDto.java +++ b/src/main/java/ru/ulstu/file/model/FileDataDto.java @@ -9,12 +9,13 @@ public class FileDataDto { private Integer id; private String name; private long size; - private Date createDate; private byte[] data; private String fileName; private String tmpFileName; + private boolean deleteFlag; + public FileDataDto() { } @@ -99,4 +100,12 @@ public class FileDataDto { this.tmpFileName = tmpFileName; } + public boolean isDeleteFlag() { + return deleteFlag; + } + + public void setDeleteFlag(boolean deleteFlag) { + this.deleteFlag = deleteFlag; + } + } diff --git a/src/main/java/ru/ulstu/file/service/FileService.java b/src/main/java/ru/ulstu/file/service/FileService.java index b15c342..3f3dbca 100644 --- a/src/main/java/ru/ulstu/file/service/FileService.java +++ b/src/main/java/ru/ulstu/file/service/FileService.java @@ -110,4 +110,10 @@ public class FileService { fileData.setSize(fileDataDto.getSize()); return fileData; } + + @Transactional + public void delete(Integer fileId) throws IOException { + FileData file = fileRepository.findOne(fileId); + fileRepository.delete(file); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 3f4028d..851a21b 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; @@ -80,7 +81,7 @@ public class PaperService { paper.setTitle(paperDto.getTitle()); paper.setUpdateDate(new Date()); paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines())); - paper.setFiles(fileService.saveOrCreate(paperDto.getFiles())); + paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == false).collect(Collectors.toList()))); paper.getAuthors().clear(); if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); @@ -93,6 +94,11 @@ public class PaperService { Paper paper = paperRepository.findOne(paperDto.getId()); Paper.PaperStatus oldStatus = paper.getStatus(); Set oldAuthors = new HashSet<>(paper.getAuthors()); + + for (FileDataDto file : paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == true && f.getId() != null).collect(Collectors.toList())) { + fileService.delete(file.getId()); + } + paperRepository.save(copyFromDto(paper, paperDto)); paper.getAuthors().forEach(author -> { diff --git a/src/main/resources/db/changelog-20190318_000000-schema.xml b/src/main/resources/db/changelog-20190318_000000-schema.xml index d1966b4..a4f7ec1 100644 --- a/src/main/resources/db/changelog-20190318_000000-schema.xml +++ b/src/main/resources/db/changelog-20190318_000000-schema.xml @@ -8,16 +8,5 @@ - - - - - - - diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index a5ff6b5..0f1a467 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -91,6 +91,28 @@

Incorrect title

+ +
+ + +
+ + + +
+ + + +
+
+
+
+
+
+
+