Fix empty records list from arango
This commit is contained in:
parent
e5442fbbfa
commit
5346f94e57
3 changed files with 29 additions and 5 deletions
|
|
@ -109,6 +109,15 @@ public class GlobalExceptionHandler {
|
|||
));
|
||||
}
|
||||
|
||||
@ExceptionHandler(NoDownloadReportRecordsException.class)
|
||||
public ResponseEntity<?> handleNoDownloadReportRecordsException(NoDownloadReportRecordsException e) {
|
||||
logger.error("Unexpected error occurred: {}", e.getMessage(), e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(Map.of(
|
||||
"message", e.getMessage(),
|
||||
"details", e.getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package org.micord.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class NoDownloadReportRecordsException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NoDownloadReportRecordsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import com.arangodb.ArangoDatabase;
|
|||
import com.arangodb.model.AqlQueryOptions;
|
||||
import org.micord.config.ArangoDBConnection;
|
||||
import org.micord.config.DatabaseConnection;
|
||||
import org.micord.exceptions.NoDownloadReportRecordsException;
|
||||
import org.micord.models.requests.RequestParameters;
|
||||
import org.micord.models.requests.downloads.AQLDownloadRequest;
|
||||
import org.micord.models.requests.downloads.BaseDownloadRequest;
|
||||
|
|
@ -44,15 +45,15 @@ public class DownloadService {
|
|||
private File processAqlDownloadRequest(AQLDownloadRequest request, List<String> ids, LocalDate startDate, LocalDate endDate, Map<String, Boolean> validationResults) {
|
||||
ArangoDatabase arangoDb = ArangoDBConnection.getConnection(request.getAqlConnectionParams());
|
||||
|
||||
Boolean emptyIdsAllowed = validationResults.getOrDefault(ValidationService.IS_EMPTY_IDS_ALLOWED, false);
|
||||
Boolean emptyDatesAllowed = validationResults.getOrDefault(ValidationService.IS_EMPTY_DATES_ALLOWED, false);
|
||||
Boolean emptyIdsAllowed = validationResults.get(ValidationService.IS_EMPTY_IDS_ALLOWED);
|
||||
Boolean emptyDatesAllowed = validationResults.get(ValidationService.IS_EMPTY_DATES_ALLOWED);
|
||||
|
||||
|
||||
Map<String, Object> entities = executeSelectAqlRequest(arangoDb, request.getDownloadRequestEntitySelectorQuery(), ids, emptyIdsAllowed);
|
||||
|
||||
if (entities.isEmpty()) {
|
||||
logger.warn("No entities found for main AQL request.");
|
||||
return null;
|
||||
throw new NoDownloadReportRecordsException("Отчет не может быть сгенерирован. Нет записей в базе для успешной генерации.");
|
||||
}
|
||||
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
|
|
@ -265,8 +266,8 @@ public class DownloadService {
|
|||
}
|
||||
|
||||
private Map<String, Object> buildSqlQuery(SQLDownloadRequest request, List<String> ids, LocalDate startDate, LocalDate endDate, Map<String, Boolean> validationResults) {
|
||||
Boolean emptyIdsAllowed = validationResults.getOrDefault(ValidationService.IS_EMPTY_IDS_ALLOWED, false);
|
||||
Boolean emptyDatesAllowed = validationResults.getOrDefault(ValidationService.IS_EMPTY_DATES_ALLOWED, false);
|
||||
Boolean emptyIdsAllowed = validationResults.get(ValidationService.IS_EMPTY_IDS_ALLOWED);
|
||||
Boolean emptyDatesAllowed = validationResults.get(ValidationService.IS_EMPTY_DATES_ALLOWED);
|
||||
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue