@@ -94,58 +94,6 @@ public class ViolationService {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Violation> violationsByFileId(FileEntity file) {
|
|
||||||
return violationRepository.findByFileEntity(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeStatusViolation(Long violationId, String status) {
|
|
||||||
Violation violation = violationRepository.findById(violationId)
|
|
||||||
.orElseThrow(() -> new ViolationNotFoundException("Violation not found with id: " + violationId));
|
|
||||||
violation.setStatus(status);
|
|
||||||
violationRepository.save(violation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Violation> getViolationsByFile(FileEntity file, 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.findByFileEntity(file, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Violation> getViolationsByFileAndStatus(FileEntity file, 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.findByFileEntityAndStatus(file, status, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Violation> getViolationsByFileAndDateRange(FileEntity file, 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.findByFileEntityAndCreatedDateBetween(file, startDate, endDate, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Long> getGroupedViolations(FileEntity file, String groupBy, String status,
|
|
||||||
LocalDateTime startDate, LocalDateTime endDate) {
|
|
||||||
|
|
||||||
List<Violation> violations;
|
|
||||||
|
|
||||||
if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
|
||||||
violations = violationRepository.findByFileEntityAndStatusAndCreatedDateBetween(file, status, startDate, endDate);
|
|
||||||
} else if (status != null && !status.isEmpty()) {
|
|
||||||
violations = violationRepository.findByFileEntityAndStatus(file, status);
|
|
||||||
} else if (startDate != null && endDate != null) {
|
|
||||||
violations = violationRepository.findByFileEntityAndCreatedDateBetween(file, startDate, endDate);
|
|
||||||
} else {
|
|
||||||
violations = violationRepository.findByFileEntity(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return violations.stream()
|
|
||||||
.collect(Collectors.groupingBy(
|
|
||||||
v -> extractGroupKey(v.getPageUrl(), groupBy),
|
|
||||||
Collectors.counting()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Violation> getViolationsByFiles(List<FileEntity> files, int page, int size, String sortDirection) {
|
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");
|
Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, "createdDate");
|
||||||
Pageable pageable = PageRequest.of(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
@@ -165,50 +113,6 @@ public class ViolationService {
|
|||||||
return violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate, pageable);
|
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 Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
|
||||||
// LocalDateTime startDate, LocalDateTime endDate,
|
|
||||||
// String sortDirection) {
|
|
||||||
// List<Violation> violations;
|
|
||||||
//
|
|
||||||
// Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC,
|
|
||||||
// "createdDate");
|
|
||||||
//
|
|
||||||
// if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
|
||||||
// violations = violationRepository.findByFileEntityInAndStatusAndCreatedDateBetween(files, status, startDate, endDate, sort);
|
|
||||||
// } else if (status != null && !status.isEmpty()) {
|
|
||||||
// violations = violationRepository.findByFileEntityInAndStatus(files, status, sort);
|
|
||||||
// } else if (startDate != null && endDate != null) {
|
|
||||||
// violations = violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate, sort);
|
|
||||||
// } else {
|
|
||||||
// violations = violationRepository.findByFileEntityIn(files, sort);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return violations.stream()
|
|
||||||
// .collect(Collectors.groupingBy(
|
|
||||||
// v -> extractGroupKey(v.getPageUrl(), groupBy),
|
|
||||||
// Collectors.counting()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
||||||
LocalDateTime startDate, LocalDateTime endDate,
|
LocalDateTime startDate, LocalDateTime endDate,
|
||||||
String sortDirection) {
|
String sortDirection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user