@@ -110,37 +110,36 @@ public class GlobalSearchController {
|
|||||||
return ResponseEntity.ok(taskOptional.get());
|
return ResponseEntity.ok(taskOptional.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @GetMapping("/violation-summary")
|
@GetMapping("/violation-summary")
|
||||||
// public ResponseEntity<?> getSummary(@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
public ResponseEntity<?> getSummary(@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
||||||
//
|
|
||||||
// if (tokenHeader == null || tokenHeader.isBlank()) {
|
if (tokenHeader == null || tokenHeader.isBlank()) {
|
||||||
// Map<String, Object> errorData = new HashMap<>();
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
// errorData.put("token", tokenHeader);
|
errorData.put("token", tokenHeader);
|
||||||
//
|
|
||||||
// return ResponseEntity.ok().body(Map.of("error", errorData));
|
return ResponseEntity.ok().body(Map.of("error", errorData));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// List<FileViolationSummaryDTO> fileViolationsSummary;
|
List<FileViolationSummaryDTO> fileViolationsSummary;
|
||||||
//
|
|
||||||
// try {
|
try {
|
||||||
// Long userId = authService.useUserAuthToken(tokenHeader);
|
Long userId = authService.useUserAuthToken(tokenHeader);
|
||||||
//
|
|
||||||
// fileViolationsSummary =
|
fileViolationsSummary = violationService.getFileViolationsSummary(userId);
|
||||||
// violationService.getFileViolationsSummary(userId);
|
|
||||||
//
|
if (fileViolationsSummary.isEmpty()) return ResponseEntity.ok().body("Violations summary not found");
|
||||||
// if (fileViolationsSummary.isEmpty()) return ResponseEntity.ok().body("Violations summary not found");
|
} catch (NotFoundAuthToken e) {
|
||||||
// } catch (NotFoundAuthToken e) {
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
// Map<String, Object> errorData = new HashMap<>();
|
errorData.put("token", tokenHeader);
|
||||||
// errorData.put("token", tokenHeader);
|
|
||||||
//
|
return ResponseEntity.ok().body(Map.of("error", errorData));
|
||||||
// return ResponseEntity.ok().body(Map.of("error", errorData));
|
}
|
||||||
// }
|
|
||||||
//
|
return ResponseEntity.ok(fileViolationsSummary);
|
||||||
// return ResponseEntity.ok(fileViolationsSummary);
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/violation-summary")
|
@PostMapping("v2/violation-summary")
|
||||||
public ResponseEntity<?> getViolations(@RequestBody ViolationRequest request) {
|
public ResponseEntity<?> getViolations(@RequestBody ViolationRequest request) {
|
||||||
if (request.getToken() == null || request.getToken().isBlank()) {
|
if (request.getToken() == null || request.getToken().isBlank()) {
|
||||||
Map<String, Object> errorData = new HashMap<>();
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
|
|||||||
@@ -118,6 +118,42 @@ public class ViolationService {
|
|||||||
return new PageImpl<>(dtoList, pageable, violations.getTotalElements());
|
return new PageImpl<>(dtoList, pageable, violations.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileViolationSummaryDTO> getFileViolationsSummary(Long userId) {
|
||||||
|
List<FileEntity> userFiles = fileEntityService.getAllUserFiles(userId);
|
||||||
|
|
||||||
|
List<Violation> violations = violationRepository.findByFileEntityInAndStatusNot( userFiles,
|
||||||
|
ViolationStatus.NOT_OWNER_FILE.name());
|
||||||
|
|
||||||
|
Map<String, List<Violation>> violationsByFileId = violations.stream()
|
||||||
|
.collect(Collectors.groupingBy(v -> v.getFileEntity().getId()));
|
||||||
|
|
||||||
|
List<FileViolationSummaryDTO> dtoList = violationsByFileId.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
List<Violation> fileViolations = entry.getValue();
|
||||||
|
FileEntity file = fileViolations.get(0).getFileEntity();
|
||||||
|
|
||||||
|
LocalDateTime latestDate = fileViolations.stream()
|
||||||
|
.map(Violation::getCreatedDate)
|
||||||
|
.max(LocalDateTime::compareTo)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
return FileViolationSummaryDTO.builder()
|
||||||
|
.fileId(file.getId())
|
||||||
|
.supportId(file.getSupportId())
|
||||||
|
.fileName(file.getOriginalFileName())
|
||||||
|
.fileSize(file.getFileSize())
|
||||||
|
.mimeType(file.getMimeType())
|
||||||
|
.status(file.getStatus())
|
||||||
|
.createdAt(file.getCreatedAt())
|
||||||
|
.violationCount(fileViolations.size())
|
||||||
|
.latestViolationDate(latestDate)
|
||||||
|
.build();
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return dtoList;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void changeStatus(ViolationStatus status, Long violationId) {
|
public void changeStatus(ViolationStatus status, Long violationId) {
|
||||||
Violation violation = violationRepository.findById(violationId).orElseThrow();
|
Violation violation = violationRepository.findById(violationId).orElseThrow();
|
||||||
|
|||||||
Reference in New Issue
Block a user