Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions application.log
Original file line number Diff line number Diff line change
Expand Up @@ -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!
6 changes: 6 additions & 0 deletions hibernate.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Document, Long> {
boolean existsByDocumentConstructorType(DocumentConstructorType documentConstructorType);

boolean existsByIdAndRecordState(Long id, RecordState recordState);

List<Document> findAllByCreator_id(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ public List<DocumentResponseDto> 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);
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +46,10 @@ public List<FileResponseDto> 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);
Expand Down Expand Up @@ -79,6 +84,10 @@ public List<FileResponseDto> addFile(String username, MultipartFile multipartFil
@Override
public List<FileResponseDto> getFiles(Long documentId, Pageable pageable) {

if (documentChecker(documentId)) {
throw new DocumentDoesNotExistException(documentId);
}

Page<File> files = fileRepository.findAllByDocument_Id(documentId, pageable);

if (files.isEmpty()) {
Expand All @@ -91,7 +100,7 @@ public List<FileResponseDto> 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);
}

Expand All @@ -116,6 +125,10 @@ public List<FileResponseDto> 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)
);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
}
}