RED-6543: Fixed QA findings in license report #21

Merged
dominique.eiflaender1 merged 1 commits from RED-6543 into master 2023-06-23 10:36:49 +02:00

View File

@ -35,6 +35,11 @@ public class LicenseReportService {
public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest) { public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest) {
var files = fileStatusService.getStatusesAddedBefore(OffsetDateTime.ofInstant(licenseReportRequest.getEndDate(), UTC_ZONE_ID)); var files = fileStatusService.getStatusesAddedBefore(OffsetDateTime.ofInstant(licenseReportRequest.getEndDate(), UTC_ZONE_ID));
if (files == null || files.isEmpty()) {
return LicenseReport.builder().startDate(licenseReportRequest.getStartDate()).endDate(licenseReportRequest.getEndDate()).build();
}
files.sort(Comparator.comparing(FileModel::getAdded)); files.sort(Comparator.comparing(FileModel::getAdded));
var addDossiers = dossierService.getAllDossiers(); var addDossiers = dossierService.getAllDossiers();
@ -56,7 +61,10 @@ public class LicenseReportService {
if (file.getHardDeletedTime() != null && file.getHardDeletedTime().toInstant().isBefore(licenseReportRequest.getEndDate())) { if (file.getHardDeletedTime() != null && file.getHardDeletedTime().toInstant().isBefore(licenseReportRequest.getEndDate())) {
hardDeletes.computeIfAbsent(YearMonth.from(file.getHardDeletedTime()), entry -> new ArrayList<>()).add(file); hardDeletes.computeIfAbsent(YearMonth.from(file.getHardDeletedTime()), entry -> new ArrayList<>()).add(file);
} }
if (dossiersById.get(file.getDossierId()).getArchivedTime() != null && dossiersById.get(file.getDossierId()).getArchivedTime().toInstant().isBefore(licenseReportRequest.getEndDate())) { if (dossiersById.get(file.getDossierId()).getArchivedTime() != null && dossiersById.get(file.getDossierId())
.getArchivedTime()
.toInstant()
.isBefore(licenseReportRequest.getEndDate())) {
archives.computeIfAbsent(YearMonth.from(dossiersById.get(file.getDossierId()).getArchivedTime()), entry -> new ArrayList<>()).add(file); archives.computeIfAbsent(YearMonth.from(dossiersById.get(file.getDossierId()).getArchivedTime()), entry -> new ArrayList<>()).add(file);
} }
if (file.getOcrStartTime() != null && file.getOcrStartTime().toInstant().isBefore(licenseReportRequest.getEndDate())) { if (file.getOcrStartTime() != null && file.getOcrStartTime().toInstant().isBefore(licenseReportRequest.getEndDate())) {
@ -81,19 +89,17 @@ public class LicenseReportService {
int numberOfAnalyzedFiles = 0; int numberOfAnalyzedFiles = 0;
int numberOfOcrFiles = 0; int numberOfOcrFiles = 0;
while (!currentMonth.isAfter(endMonth)) { while (!currentMonth.isAfter(endMonth)) {
int currentMonthNumberOfAnalyzedPages = 0; int currentMonthNumberOfAnalyzedPages = 0;
int currentMonthNumberOfOcrPages = 0; int currentMonthNumberOfOcrPages = 0;
var addedFilesInMonth = adds.get(currentMonth); var addedFilesInMonth = adds.get(currentMonth);
if (addedFilesInMonth != null) { if (addedFilesInMonth != null) {
for (var add : addedFilesInMonth) { for (var add : addedFilesInMonth) {
activeFilesUploadedBytes += add.getFileSize(); activeFilesUploadedBytes += add.getFileSize();
if(add.getAdded().toInstant().isAfter(licenseReportRequest.getStartDate())) { if (add.getAdded().toInstant().isAfter(licenseReportRequest.getStartDate())) {
numberOfAnalyzedPages += add.getNumberOfPages(); numberOfAnalyzedPages += add.getNumberOfPages();
currentMonthNumberOfAnalyzedPages += add.getNumberOfPages(); currentMonthNumberOfAnalyzedPages += add.getNumberOfPages();
@ -105,8 +111,13 @@ public class LicenseReportService {
var softDeletedFilesInMonth = softDeletes.get(currentMonth); var softDeletedFilesInMonth = softDeletes.get(currentMonth);
if (softDeletedFilesInMonth != null) { if (softDeletedFilesInMonth != null) {
for (var softDeleted : softDeletedFilesInMonth) { for (var softDeleted : softDeletedFilesInMonth) {
activeFilesUploadedBytes -= softDeleted.getFileSize(); if (dossiersById.get(softDeleted.getDossierId()).getArchivedTime() != null) {
trashFilesUploadedBytes += softDeleted.getFileSize(); archivedFilesUploadedBytes -= softDeleted.getFileSize();
trashFilesUploadedBytes += softDeleted.getFileSize();
} else {
activeFilesUploadedBytes -= softDeleted.getFileSize();
trashFilesUploadedBytes += softDeleted.getFileSize();
}
} }
} }
@ -133,7 +144,7 @@ public class LicenseReportService {
if (ocrFilesInMonth != null) { if (ocrFilesInMonth != null) {
for (var ocrFile : ocrFilesInMonth) { for (var ocrFile : ocrFilesInMonth) {
if(ocrFile.getOcrStartTime().toInstant().isAfter(licenseReportRequest.getStartDate())) { if (ocrFile.getOcrStartTime().toInstant().isAfter(licenseReportRequest.getStartDate())) {
numberOfOcrPages += ocrFile.getNumberOfPages(); // We count the entire document if ocr is performed. numberOfOcrPages += ocrFile.getNumberOfPages(); // We count the entire document if ocr is performed.
currentMonthNumberOfOcrPages += ocrFile.getNumberOfPages(); currentMonthNumberOfOcrPages += ocrFile.getNumberOfPages();
numberOfOcrFiles++; numberOfOcrFiles++;
@ -146,8 +157,8 @@ public class LicenseReportService {
var monthEndDate = currentMonth.atEndOfMonth().atTime(23, 59).atZone(UTC_ZONE_ID).toInstant(); var monthEndDate = currentMonth.atEndOfMonth().atTime(23, 59).atZone(UTC_ZONE_ID).toInstant();
monthlyData.add(MonthlyReportData.builder() monthlyData.add(MonthlyReportData.builder()
.startDate(currentMonth.atDay(1).atStartOfDay(UTC_ZONE_ID).toInstant()) .startDate(currentMonth.atDay(1).atStartOfDay(UTC_ZONE_ID).toInstant())
.endDate(monthEndDate.isBefore(licenseReportRequest.getEndDate()) ? monthEndDate : licenseReportRequest.getEndDate()) .endDate(monthEndDate.isBefore(licenseReportRequest.getEndDate()) ? monthEndDate : licenseReportRequest.getEndDate())
.activeFilesUploadedBytes(activeFilesUploadedBytes) .activeFilesUploadedBytes(activeFilesUploadedBytes)
.trashFilesUploadedBytes(trashFilesUploadedBytes) .trashFilesUploadedBytes(trashFilesUploadedBytes)
.archivedFilesUploadedBytes(archivedFilesUploadedBytes) .archivedFilesUploadedBytes(archivedFilesUploadedBytes)
@ -180,5 +191,4 @@ public class LicenseReportService {
.build(); .build();
} }
} }