Return empty reports list if package was found, but folder is empty

This commit is contained in:
Mikhail Trofimov 2025-07-03 17:49:29 +03:00
parent 7c4e81b18f
commit da024aaa3e

View file

@ -240,7 +240,7 @@ public class SignalFacade {
public ResponseEntity<MonitoringReportListResponse> getReportList(String username, String packageName) {
try {
if (!signalService.isPackageExists(username, packageName)) {
throw clientExcp(SignalError.ERROR_016, XmlErrorFormat.MonitoringReportListError, packageName);
throw clientExcp(SignalError.ERROR_012, XmlErrorFormat.MonitoringReportListError, packageName);
}
String memberCode = username.substring(0, 6);
@ -248,30 +248,21 @@ public class SignalFacade {
String dirPath = config.getLoadDir() + File.separator + memberCode;
File folder = new File(dirPath);
MonitoringReportListResponse.Reports reports = new MonitoringReportListResponse.Reports();
if (folder.exists() && folder.isDirectory()) {
MonitoringReportListResponse.Reports reports = new MonitoringReportListResponse.Reports();
File[] files = folder.listFiles();
if (files == null) {
throw clientExcp(SignalError.ERROR_012, XmlErrorFormat.MonitoringReportListError, packageName);
}
for (File file : files) {
if (file.isFile() && file.getName().startsWith(filePrefix)) {
reports.getReports().add(file.getName());
if (files != null) {
for (File file : files) {
if (file.isFile() && file.getName().startsWith(filePrefix)) {
reports.getReports().add(file.getName());
}
}
}
if (reports.getReports().isEmpty()) {
throw clientExcp(SignalError.ERROR_012, XmlErrorFormat.MonitoringReportListError, packageName);
} else {
MonitoringReportListResponse response = new MonitoringReportListResponse();
response.setPackageName(packageName);
response.setReports(reports);
return ResponseEntity.ok(response);
}
} else {
log.error("Пакет {} был найден в бд для memberCode {}, но ни одного архива не было найдено в папке {}", packageName, username, dirPath);
throw clientExcp(SignalError.ERROR_013, XmlErrorFormat.MonitoringReportListError, packageName);
}
MonitoringReportListResponse response = new MonitoringReportListResponse();
response.setPackageName(packageName);
response.setReports(reports);
return ResponseEntity.ok(response);
} catch (Exception e) {
if (e instanceof SignalClientException) {
throw (SignalClientException) e;