RED-7185 - Error message when adjusting the Justification
This commit is contained in:
parent
82a5023554
commit
f0caa836d4
@ -32,11 +32,14 @@ public class DossierTemplatePersistenceService {
|
||||
private final LegalBasisMappingPersistenceService legalBasisMappingPersistenceService;
|
||||
private final RulesPersistenceService rulesPersistenceService;
|
||||
|
||||
private final int MAX_NAME_LENGTH = 255;
|
||||
private final int MAX_DESCRIPTION_LENGTH = 4000;
|
||||
|
||||
@Transactional
|
||||
public DossierTemplateEntity createOrUpdateDossierTemplate(CreateOrUpdateDossierTemplateRequest createOrUpdateDossierRequest) {
|
||||
|
||||
if (createOrUpdateDossierRequest.getDossierTemplateId() != null) {
|
||||
validateDossierTemplate(createOrUpdateDossierRequest.getName(), createOrUpdateDossierRequest.getDescription());
|
||||
Optional<DossierTemplateEntity> dossierTemplate = dossierTemplateRepository.findById(createOrUpdateDossierRequest.getDossierTemplateId());
|
||||
if (dossierTemplate.isPresent()) {
|
||||
|
||||
@ -58,6 +61,7 @@ public class DossierTemplatePersistenceService {
|
||||
throw new ConflictException("DossierTemplate name must be set");
|
||||
}
|
||||
validateDossierTemplateNameIsUnique(createOrUpdateDossierRequest.getName());
|
||||
validateDossierTemplate(createOrUpdateDossierRequest.getName(), createOrUpdateDossierRequest.getDescription());
|
||||
DossierTemplateEntity dossierTemplate = new DossierTemplateEntity();
|
||||
dossierTemplate.setId(UUID.randomUUID().toString());
|
||||
// order is important
|
||||
@ -73,6 +77,16 @@ public class DossierTemplatePersistenceService {
|
||||
|
||||
}
|
||||
|
||||
private void validateDossierTemplate(String name, String description) {
|
||||
|
||||
if (name.length() > MAX_NAME_LENGTH) {
|
||||
throw new BadRequestException(String.format("The name is too long (%s), max length %s", name.length(), MAX_NAME_LENGTH));
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(description) && description.length() > MAX_DESCRIPTION_LENGTH) {
|
||||
throw new BadRequestException(String.format("The description is too long (%s), max length %s", description.length(), MAX_DESCRIPTION_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
public DossierTemplateStatus computeDossierTemplateStatus(DossierTemplateEntity dossierTemplate) {
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.LegalBasisEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.LegalBasisMappingEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.LegalBasisMappingRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.legalbasis.LegalBasis;
|
||||
|
||||
@ -23,6 +24,8 @@ public class LegalBasisMappingPersistenceService {
|
||||
|
||||
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
||||
|
||||
private final int MAX_NAME_LENGTH = 255;
|
||||
private final int MAX_LEGAL_BASIS_LENGTH = 4000;
|
||||
|
||||
@Transactional
|
||||
public void deleteLegalBasis(String dossierTemplateId, List<String> legalBasisNames) {
|
||||
@ -36,10 +39,10 @@ public class LegalBasisMappingPersistenceService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void addOrUpdateLegalBasis(String dossierTemplateId, LegalBasis legalBasis) {
|
||||
|
||||
validateLegalBasis(legalBasis);
|
||||
var mapping = getLegalBasisMappingOrCreate(dossierTemplateId);
|
||||
|
||||
mapping.getLegalBasis().stream().filter(l -> l.getName().equals(legalBasis.getName())).findAny().ifPresentOrElse(existingBasis -> {
|
||||
@ -54,6 +57,20 @@ public class LegalBasisMappingPersistenceService {
|
||||
|
||||
}
|
||||
|
||||
private void validateLegalBasis(LegalBasis legalBasis) {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (legalBasis.getDescription().length() > MAX_LEGAL_BASIS_LENGTH) {
|
||||
throw new BadRequestException(String.format("The description is too long (%s), max length %s", legalBasis.getDescription().length(), MAX_LEGAL_BASIS_LENGTH));
|
||||
}
|
||||
|
||||
if (legalBasis.getReason().length() > MAX_LEGAL_BASIS_LENGTH) {
|
||||
throw new BadRequestException(String.format("The legal basis is too long (%s), max length %s", legalBasis.getReason().length(), MAX_LEGAL_BASIS_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setLegalBasisMapping(String dossierTemplateId, List<LegalBasis> legalBasisMapping) {
|
||||
|
||||
@ -7,11 +7,13 @@ import java.util.stream.Collectors;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualLegalBasisChangeEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.LegalBasisChangeRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
@ -24,12 +26,13 @@ import lombok.RequiredArgsConstructor;
|
||||
public class LegalBasisChangePersistenceService {
|
||||
|
||||
private final LegalBasisChangeRepository legalBasisChangeRepository;
|
||||
|
||||
private final int SECTION_MAX_LENGTH = 1024;
|
||||
|
||||
public ManualLegalBasisChangeEntity insert(String fileId, LegalBasisChangeRequest legalBasisChangeRequest) {
|
||||
|
||||
ManualLegalBasisChangeEntity manualLegalBasisChange = new ManualLegalBasisChangeEntity();
|
||||
manualLegalBasisChange.setId(new AnnotationEntityId(legalBasisChangeRequest.getAnnotationId(), fileId));
|
||||
checkSection(legalBasisChangeRequest.getSection());
|
||||
BeanUtils.copyProperties(legalBasisChangeRequest, manualLegalBasisChange);
|
||||
manualLegalBasisChange.setRequestDate(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
|
||||
|
||||
@ -41,6 +44,12 @@ public class LegalBasisChangePersistenceService {
|
||||
|
||||
}
|
||||
|
||||
private void checkSection(String section) {
|
||||
|
||||
if (!StringUtils.isEmpty(section) && section.length() > SECTION_MAX_LENGTH) {
|
||||
throw new BadRequestException(String.format("The section is too long (%s), max length %s", section.length(), SECTION_MAX_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void hardDelete(String fileId, String annotationId) {
|
||||
|
||||
@ -113,3 +113,5 @@ databaseChangeLog:
|
||||
file: db/changelog/tenant/sql/43-add-applied-redaction-color.sql
|
||||
- include:
|
||||
file: db/changelog/tenant/sql/45-unique-dossier-name.sql
|
||||
- include:
|
||||
file: db/changelog/tenant/45-modify-section-length.yaml
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: modify-section-length
|
||||
author: aisvoran
|
||||
changes:
|
||||
- modifyDataType:
|
||||
columnName: section
|
||||
newDataType: VARCHAR(1024)
|
||||
tableName: manual_legal_basis_change
|
||||
Loading…
x
Reference in New Issue
Block a user