RED-8339: Fixes

This commit is contained in:
Ali Oezyetimoglu 2024-05-23 09:24:59 +02:00
parent f3a7d40ff9
commit 1fda16b6ca
3 changed files with 30 additions and 21 deletions

View File

@ -1,10 +1,8 @@
package com.iqser.red.service.persistence.v1.internal.api.controller; package com.iqser.red.service.persistence.v1.internal.api.controller;
import com.iqser.red.commons.spring.ErrorMessage; import java.sql.SQLException;
import com.iqser.red.service.persistence.management.v1.processor.exception.*; import java.time.OffsetDateTime;
import java.util.stream.Collectors;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -14,9 +12,17 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLException; import com.iqser.red.commons.spring.ErrorMessage;
import java.time.OffsetDateTime; import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import java.util.stream.Collectors; import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
import com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.exception.InvalidRulesException;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.exception.RulesTimeoutDetectedException;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.exception.ComponentLogDocumentNotFoundException;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestControllerAdvice @RestControllerAdvice
@ -129,4 +135,14 @@ public class InternalControllerAdvice {
return new ErrorMessage(OffsetDateTime.now(), e.getMessage()); return new ErrorMessage(OffsetDateTime.now(), e.getMessage());
} }
@Hidden
@ResponseBody
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(ComponentLogDocumentNotFoundException.class)
public ErrorMessage handleCustomException(ComponentLogDocumentNotFoundException e) {
return new ErrorMessage(OffsetDateTime.now(), e.getMessage());
}
} }

View File

@ -72,16 +72,7 @@ public class ComponentLogService {
public ComponentLog getComponentLog(String dossierId, String fileId, boolean includeOverrides) { public ComponentLog getComponentLog(String dossierId, String fileId, boolean includeOverrides) {
ComponentLog componentLog; ComponentLog componentLog = fileManagementStorageService.getComponentLog(dossierId, fileId);
try {
componentLog = fileManagementStorageService.getComponentLog(dossierId, fileId);
} catch (NotFoundException e) {
var componentLogOptional = componentLogMongoService.findComponentLogByDossierIdAndFileId(dossierId, fileId);
if (componentLogOptional.isEmpty()) {
throw new NotFoundException(e.getMessage());
}
componentLog = componentLogOptional.get();
}
if (!includeOverrides) { if (!includeOverrides) {
componentLog = sortComponentLogEntriesByOrderList(componentLog, ORDER); componentLog = sortComponentLogEntriesByOrderList(componentLog, ORDER);
@ -153,7 +144,9 @@ public class ComponentLogService {
private void insertOverride(String dossierId, String fileId, ComponentLogEntry componentToAdd) { private void insertOverride(String dossierId, String fileId, ComponentLogEntry componentToAdd) {
componentLogMongoService.insertComponentLogEntries(dossierId, fileId, List.of(componentToAdd)); ComponentLog componentLog = fileManagementStorageService.getComponentLog(dossierId, fileId);
componentLogMongoService.insertComponentLogEntries(dossierId, fileId, componentLog, List.of(componentToAdd));
} }

View File

@ -97,11 +97,11 @@ public class ComponentLogMongoService {
} }
public void insertComponentLogEntries(String dossierId, String fileId, List<ComponentLogEntry> componentLogEntries) { public void insertComponentLogEntries(String dossierId, String fileId, ComponentLog componentLog, List<ComponentLogEntry> componentLogEntries) {
String componentLogId = mapper.getComponentLogId(dossierId, fileId); String componentLogId = mapper.getComponentLogId(dossierId, fileId);
ComponentLogDocument componentLogDocument = getComponentLogDocument(componentLogId); ComponentLogDocument componentLogDocument = mapper.toComponentLogDocument(dossierId, fileId, componentLog);
List<ComponentDocument> componentDocuments = componentLogEntries.stream() List<ComponentDocument> componentDocuments = componentLogEntries.stream()
.map(componentLogEntry -> mapper.toComponentDocument(componentLogId, componentLogEntry)) .map(componentLogEntry -> mapper.toComponentDocument(componentLogId, componentLogEntry))