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
|
@ResponseBody
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
@GetMapping(value = LEGAL_BASIS_PATH + DOSSIER_TEMPLATE_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
@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")})
|
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
|
||||||
List<LegalBasis> getLegalBasisMapping(@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId);
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
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 jakarta.transaction.Transactional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class LegalBasisMappingPersistenceService {
|
public class LegalBasisMappingPersistenceService {
|
||||||
|
|
||||||
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
||||||
@ -58,7 +61,6 @@ public class LegalBasisMappingPersistenceService {
|
|||||||
|
|
||||||
return legalBasisMappingRepository.findById(dossierTemplateId)
|
return legalBasisMappingRepository.findById(dossierTemplateId)
|
||||||
.orElseGet(() -> {
|
.orElseGet(() -> {
|
||||||
// create on get if not present
|
|
||||||
var lbm = new LegalBasisMappingEntity();
|
var lbm = new LegalBasisMappingEntity();
|
||||||
lbm.setDossierTemplateId(dossierTemplateId);
|
lbm.setDossierTemplateId(dossierTemplateId);
|
||||||
lbm.setLegalBasis(new ArrayList<>());
|
lbm.setLegalBasis(new ArrayList<>());
|
||||||
@ -72,27 +74,42 @@ public class LegalBasisMappingPersistenceService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void addOrUpdateLegalBasis(String dossierTemplateId, LegalBasis legalBasis) {
|
public void addOrUpdateLegalBasis(String dossierTemplateId, LegalBasis legalBasis) {
|
||||||
|
|
||||||
validateLegalBasis(legalBasis);
|
|
||||||
var mapping = getLegalBasisMappingOrCreate(dossierTemplateId);
|
var mapping = getLegalBasisMappingOrCreate(dossierTemplateId);
|
||||||
|
|
||||||
mapping.getLegalBasis()
|
Optional<LegalBasisEntity> existingBasisByTechnicalName = mapping.getLegalBasis()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(l -> l.getTechnicalName().equals(legalBasis.getTechnicalName()))
|
.filter(l -> l.getTechnicalName().equals(legalBasis.getTechnicalName()))
|
||||||
.findAny().ifPresentOrElse(existingBasis -> {
|
.findAny();
|
||||||
existingBasis.setReason(legalBasis.getReason());
|
|
||||||
existingBasis.setDescription(legalBasis.getDescription());
|
|
||||||
existingBasis.setName(legalBasis.getName());
|
|
||||||
},
|
|
||||||
() -> mapping.getLegalBasis()
|
|
||||||
.add(LegalBasisEntity.builder()
|
|
||||||
.name(legalBasis.getName())
|
|
||||||
.description(legalBasis.getDescription())
|
|
||||||
.reason(legalBasis.getReason())
|
|
||||||
.technicalName(legalBasis.getTechnicalName())
|
|
||||||
.build()));
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
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());
|
||||||
|
}
|
||||||
mapping.setVersion(mapping.getVersion() + 1);
|
mapping.setVersion(mapping.getVersion() + 1);
|
||||||
legalBasisMappingRepository.save(mapping);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +120,10 @@ public class LegalBasisMappingPersistenceService {
|
|||||||
throw new BadRequestException("The technical name cannot be empty!");
|
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) {
|
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));
|
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