diff --git a/application.log b/application.log index bf6cdfb2..9840c383 100644 --- a/application.log +++ b/application.log @@ -878,3 +878,25 @@ org.hibernate.hql.internal.ast.DetailedSemanticException: Unable to locate appro 2023-11-12 19:58:19 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead 2023-11-12 19:58:37 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead 2023-11-12 19:59:25 WARN [http-nio-8082-exec-6] c.e.c.configs.JwtRequestFilter - Token timeout +2023-11-13 17:22:54 WARN [http-nio-8082-exec-1] c.e.c.e.DocumentAccessException - User Farid does not have access to this document! +2023-11-13 17:23:25 WARN [http-nio-8082-exec-2] c.e.c.configs.JwtRequestFilter - Token timeout +2023-11-13 17:23:25 WARN [http-nio-8082-exec-2] c.e.c.e.DocumentDoesNotExistException - Document with id:2 does not exist! +2023-11-13 17:32:13 WARN [http-nio-8082-exec-4] c.e.c.e.DocumentDoesNotExistException - Document with id:2 does not exist! +2023-11-13 17:32:28 WARN [http-nio-8082-exec-6] c.e.c.configs.JwtRequestFilter - Token timeout +2023-11-13 17:33:02 WARN [http-nio-8082-exec-8] c.e.c.configs.JwtRequestFilter - Token timeout +2023-11-13 17:33:24 WARN [http-nio-8082-exec-1] c.e.c.configs.JwtRequestFilter - Token timeout +2023-11-13 17:34:03 WARN [http-nio-8082-exec-6] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:34:38 WARN [http-nio-8082-exec-9] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:34:48 WARN [http-nio-8082-exec-1] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:34:52 WARN [http-nio-8082-exec-2] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:34:57 WARN [http-nio-8082-exec-3] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:41:59 WARN [http-nio-8082-exec-5] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:42:14 WARN [http-nio-8082-exec-3] c.e.c.e.DocumentDoesNotExistException - Document with id:3 does not exist! +2023-11-13 17:43:49 WARN [http-nio-8082-exec-2] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:43:53 WARN [http-nio-8082-exec-3] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:00 WARN [http-nio-8082-exec-7] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:09 WARN [http-nio-8082-exec-8] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:12 WARN [http-nio-8082-exec-9] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:16 WARN [http-nio-8082-exec-6] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:20 WARN [http-nio-8082-exec-1] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! +2023-11-13 17:44:24 WARN [http-nio-8082-exec-4] c.e.c.e.DocumentDoesNotExistException - Document with id:4 does not exist! diff --git a/hibernate.log b/hibernate.log index 8a7d6e1c..a6120395 100644 --- a/hibernate.log +++ b/hibernate.log @@ -64,3 +64,9 @@ 2023-11-07 15:49:03 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead 2023-11-07 15:51:17 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead 2023-11-07 15:51:24 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:07:48 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:09:44 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:11:04 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:21:36 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:31:46 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead +2023-11-13 17:41:19 WARN [main] org.hibernate.orm.deprecation - HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead diff --git a/src/main/java/com/example/caselabproject/repositories/DocumentRepository.java b/src/main/java/com/example/caselabproject/repositories/DocumentRepository.java index 38b43f6e..4a49d150 100644 --- a/src/main/java/com/example/caselabproject/repositories/DocumentRepository.java +++ b/src/main/java/com/example/caselabproject/repositories/DocumentRepository.java @@ -2,11 +2,14 @@ import com.example.caselabproject.models.entities.Document; import com.example.caselabproject.models.entities.DocumentConstructorType; +import com.example.caselabproject.models.enums.RecordState; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface DocumentRepository extends JpaRepository { boolean existsByDocumentConstructorType(DocumentConstructorType documentConstructorType); + boolean existsByIdAndRecordState(Long id, RecordState recordState); + List findAllByCreator_id(Long id); } diff --git a/src/main/java/com/example/caselabproject/services/implementations/DocumentServiceImpl.java b/src/main/java/com/example/caselabproject/services/implementations/DocumentServiceImpl.java index bc588dc2..aae778aa 100644 --- a/src/main/java/com/example/caselabproject/services/implementations/DocumentServiceImpl.java +++ b/src/main/java/com/example/caselabproject/services/implementations/DocumentServiceImpl.java @@ -99,10 +99,6 @@ public List filteredDocument(Pageable pageable, @Override public DocumentResponseDto updateDocument(String username, DocumentRequestDto request, Long documentId) { - if (!documentRepository.existsById(documentId)) { - throw new DocumentDoesNotExistException(documentId); - } - if (!userRepository.existsByUsernameAndDocuments_id(username, documentId)) { throw new DocumentAccessException(username); } @@ -110,6 +106,10 @@ public DocumentResponseDto updateDocument(String username, DocumentRequestDto re Document updateDocument = documentRepository.findById(documentId) .orElseThrow(() -> new DocumentDoesNotExistException(documentId)); + if (updateDocument.getRecordState().equals(RecordState.DELETED)) { + throw new DocumentDoesNotExistException(documentId); + } + updateDocument.setUpdateDate(request.mapToEntity().getUpdateDate()); updateDocument.setName(request.getName()); updateDocument.setDocumentConstructorType(documentConstructorTypeRepository diff --git a/src/main/java/com/example/caselabproject/services/implementations/FileServiceImpl.java b/src/main/java/com/example/caselabproject/services/implementations/FileServiceImpl.java index 05b1701c..f8ca7d97 100644 --- a/src/main/java/com/example/caselabproject/services/implementations/FileServiceImpl.java +++ b/src/main/java/com/example/caselabproject/services/implementations/FileServiceImpl.java @@ -5,6 +5,7 @@ import com.example.caselabproject.models.DTOs.response.FileResponseDto; import com.example.caselabproject.models.entities.Document; import com.example.caselabproject.models.entities.File; +import com.example.caselabproject.models.enums.RecordState; import com.example.caselabproject.repositories.DocumentRepository; import com.example.caselabproject.repositories.FileRepository; import com.example.caselabproject.repositories.UserRepository; @@ -45,6 +46,10 @@ public List addFile(String username, MultipartFile multipartFil Document document = documentRepository.findById(documentId) .orElseThrow(() -> new DocumentDoesNotExistException(documentId)); + if (document.getRecordState().equals(RecordState.DELETED)) { + throw new DocumentDoesNotExistException(documentId); + } + File file = new File(); file.setDocument(document); @@ -79,6 +84,10 @@ public List addFile(String username, MultipartFile multipartFil @Override public List getFiles(Long documentId, Pageable pageable) { + if (documentChecker(documentId)) { + throw new DocumentDoesNotExistException(documentId); + } + Page files = fileRepository.findAllByDocument_Id(documentId, pageable); if (files.isEmpty()) { @@ -91,7 +100,7 @@ public List getFiles(Long documentId, Pageable pageable) { @Override public FileDownloadResponseDto downloadFile(Long documentId, Long fileId) throws IOException { - if (!documentRepository.existsById(documentId)) { + if (!documentRepository.existsByIdAndRecordState(documentId, RecordState.ACTIVE)) { throw new DocumentDoesNotExistException(documentId); } @@ -116,6 +125,10 @@ public List updateFile(String username, MultipartFile file, throw new DocumentAccessException(username); } + if (documentChecker(documentId)) { + throw new DocumentDoesNotExistException(documentId); + } + File updateFile = fileRepository.findById(fileId).orElseThrow( () -> new FileNotExistException(fileId) ); @@ -153,6 +166,10 @@ public boolean deleteFile(String username, Long documentId, Long fileId) { Document document = documentRepository.findById(documentId) .orElseThrow(() -> new DocumentDoesNotExistException(documentId)); + if (document.getRecordState().equals(RecordState.DELETED)) { + throw new DocumentDoesNotExistException(documentId); + } + File file = fileRepository.findById(fileId) .orElseThrow(() -> new FileNotExistException(fileId)); @@ -184,4 +201,11 @@ private void multipartFileToFile(MultipartFile multipartFile, File file) throws + "docId_" + file.getDocument().getId() + "_" + multipartFile.getOriginalFilename()); } + + private boolean documentChecker(Long documentId) { + Document document = documentRepository.findById(documentId) + .orElseThrow(() -> new DocumentDoesNotExistException(documentId)); + + return (document.getRecordState().equals(RecordState.DELETED)); + } }