@@ -146,6 +146,46 @@ public class ViolationService {
|
||||
));
|
||||
}
|
||||
|
||||
public Page<Violation> getViolationsByFiles(List<FileEntity> files, int page, int size, String sortDirection) {
|
||||
Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, "createdDate");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
return violationRepository.findByFileEntityIn(files, pageable);
|
||||
}
|
||||
|
||||
public Page<Violation> getViolationsByFilesAndStatus(List<FileEntity> files, String status, int page, int size, String sortDirection) {
|
||||
Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, "createdDate");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
return violationRepository.findByFileEntityInAndStatus(files, status, pageable);
|
||||
}
|
||||
|
||||
public Page<Violation> getViolationsByFilesAndDateRange(List<FileEntity> files, LocalDateTime startDate, LocalDateTime endDate,
|
||||
int page, int size, String sortDirection) {
|
||||
Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, "createdDate");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
return violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate, pageable);
|
||||
}
|
||||
|
||||
public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
||||
LocalDateTime startDate, LocalDateTime endDate) {
|
||||
List<Violation> violations;
|
||||
|
||||
if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
||||
violations = violationRepository.findByFileEntityInAndStatusAndCreatedDateBetween(files, status, startDate, endDate);
|
||||
} else if (status != null && !status.isEmpty()) {
|
||||
violations = violationRepository.findByFileEntityInAndStatus(files, status);
|
||||
} else if (startDate != null && endDate != null) {
|
||||
violations = violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate);
|
||||
} else {
|
||||
violations = violationRepository.findByFileEntityIn(files);
|
||||
}
|
||||
|
||||
return violations.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
v -> extractGroupKey(v.getPageUrl(), groupBy),
|
||||
Collectors.counting()
|
||||
));
|
||||
}
|
||||
|
||||
public ViolationStatisticsResponse getViolationStatistics(Long userId, String fileId,
|
||||
LocalDateTime startDate, LocalDateTime endDate) {
|
||||
|
||||
@@ -207,7 +247,6 @@ public class ViolationService {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private String extractGroupKey(String url, String groupBy) {
|
||||
try {
|
||||
String domain = url.replaceAll("https?://(www\\.)?", "").split("/")[0];
|
||||
|
||||
Reference in New Issue
Block a user