Merge branch 'RED-9958-fix' into 'master'
RED-9958:Several problems after technical_name refactoring Closes RED-9958 See merge request redactmanager/persistence-service!717
This commit is contained in:
commit
60371fb34b
@ -50,7 +50,7 @@ public interface LegalBasisMappingResource {
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@GetMapping(value = LEGAL_BASIS_PATH + DOSSIER_TEMPLATE_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "Set the mapping between legal basis and redaction reason.", description = "None")
|
||||
@Operation(summary = "Get all legal basis mapping in dossier template.", description = "None")
|
||||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
|
||||
List<LegalBasis> getLegalBasisMapping(@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId);
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import static com.knecon.fforesight.databasetenantcommons.providers.utils.MagicC
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -17,9 +18,11 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemp
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LegalBasisMappingPersistenceService {
|
||||
|
||||
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
||||
@ -58,7 +61,6 @@ public class LegalBasisMappingPersistenceService {
|
||||
|
||||
return legalBasisMappingRepository.findById(dossierTemplateId)
|
||||
.orElseGet(() -> {
|
||||
// create on get if not present
|
||||
var lbm = new LegalBasisMappingEntity();
|
||||
lbm.setDossierTemplateId(dossierTemplateId);
|
||||
lbm.setLegalBasis(new ArrayList<>());
|
||||
@ -72,27 +74,42 @@ public class LegalBasisMappingPersistenceService {
|
||||
@Transactional
|
||||
public void addOrUpdateLegalBasis(String dossierTemplateId, LegalBasis legalBasis) {
|
||||
|
||||
validateLegalBasis(legalBasis);
|
||||
var mapping = getLegalBasisMappingOrCreate(dossierTemplateId);
|
||||
|
||||
mapping.getLegalBasis()
|
||||
Optional<LegalBasisEntity> existingBasisByTechnicalName = mapping.getLegalBasis()
|
||||
.stream()
|
||||
.filter(l -> l.getTechnicalName().equals(legalBasis.getTechnicalName()))
|
||||
.findAny().ifPresentOrElse(existingBasis -> {
|
||||
existingBasis.setReason(legalBasis.getReason());
|
||||
.findAny();
|
||||
|
||||
Optional<LegalBasisEntity> existingBasisByName = mapping.getLegalBasis()
|
||||
.stream()
|
||||
.filter(l -> l.getName().equals(legalBasis.getName()))
|
||||
.findAny();
|
||||
|
||||
if (existingBasisByTechnicalName.isPresent() && existingBasisByName.isPresent()) {
|
||||
LegalBasisEntity existingBasis = existingBasisByTechnicalName.get();
|
||||
existingBasis.setDescription(legalBasis.getDescription());
|
||||
existingBasis.setReason(legalBasis.getReason());
|
||||
} else if (existingBasisByTechnicalName.isPresent()) {
|
||||
LegalBasisEntity existingBasis = existingBasisByTechnicalName.get();
|
||||
existingBasis.setName(legalBasis.getName());
|
||||
},
|
||||
() -> mapping.getLegalBasis()
|
||||
existingBasis.setDescription(legalBasis.getDescription());
|
||||
existingBasis.setReason(legalBasis.getReason());
|
||||
} else if (existingBasisByName.isPresent()) {
|
||||
LegalBasisEntity existingBasis = existingBasisByName.get();
|
||||
existingBasis.setTechnicalName(legalBasis.getTechnicalName());
|
||||
existingBasis.setDescription(legalBasis.getDescription());
|
||||
existingBasis.setReason(legalBasis.getReason());
|
||||
} else {
|
||||
mapping.getLegalBasis()
|
||||
.add(LegalBasisEntity.builder()
|
||||
.name(legalBasis.getName())
|
||||
.description(legalBasis.getDescription())
|
||||
.reason(legalBasis.getReason())
|
||||
.technicalName(legalBasis.getTechnicalName())
|
||||
.build()));
|
||||
|
||||
.build());
|
||||
}
|
||||
mapping.setVersion(mapping.getVersion() + 1);
|
||||
legalBasisMappingRepository.save(mapping);
|
||||
|
||||
}
|
||||
|
||||
@ -103,6 +120,10 @@ public class LegalBasisMappingPersistenceService {
|
||||
throw new BadRequestException("The technical name cannot be empty!");
|
||||
}
|
||||
|
||||
if (legalBasis.getName() == null || legalBasis.getName().isEmpty()) {
|
||||
throw new BadRequestException("The name cannot be empty!");
|
||||
}
|
||||
|
||||
if (legalBasis.getName().length() > MAX_NAME_LENGTH) {
|
||||
throw new BadRequestException(String.format("The name is too long (%s), max length %s", legalBasis.getName().length(), MAX_NAME_LENGTH));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user