DescriptionTemplateTypePersist remove old validators

This commit is contained in:
Efstratios Giannopoulos 2023-12-19 15:11:22 +02:00
parent 68c56d70a4
commit 4fa4cdc671
1 changed files with 19 additions and 48 deletions

View File

@ -8,7 +8,6 @@ import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.Description;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
@ -17,25 +16,16 @@ import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DescriptionTemplateTypePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
public final static String _id = "id";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = DescriptionTemplateTypeEntity._nameLength, message = "{validation.largerthanmax}")
private String name = null;
public final static String _name = "name";
@ -44,16 +34,15 @@ public class DescriptionTemplateTypePersist {
public final static String _hash = "hash";
@ValidEnum(message = "{validation.empty}")
private DescriptionTemplateTypeStatus status;
private List<DescriptionTemplateTypePersist> nested;
public final static String _nested = "nested";
private DescriptionTemplateTypePersist obj;
public final static String _obj = "obj";
// private List<DescriptionTemplateTypePersist> nested;
//
// public final static String _nested = "nested";
//
// private DescriptionTemplateTypePersist obj;
//
// public final static String _obj = "obj";
public UUID getId() {
return id;
@ -87,34 +76,16 @@ public class DescriptionTemplateTypePersist {
this.status = status;
}
public List<DescriptionTemplateTypePersist> getNested() {
return nested;
}
public void setNested(List<DescriptionTemplateTypePersist> nested) {
this.nested = nested;
}
public DescriptionTemplateTypePersist getObj() {
return obj;
}
public void setObj(DescriptionTemplateTypePersist obj) {
this.obj = obj;
}
@Component(DescriptionTemplateTypePersistValidator.ValidatorName)
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionTemplateTypePersistValidator extends BaseValidator<DescriptionTemplateTypePersist> {
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator";
private final ValidatorFactory validatorFactory;
private final MessageSource messageSource;
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ValidatorFactory validatorFactory, ConventionService conventionService, ErrorThesaurusProperties errors) {
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ConventionService conventionService, ErrorThesaurusProperties errors) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
@ -139,17 +110,17 @@ public class DescriptionTemplateTypePersist {
this.spec()
.iff(() -> !this.isEmpty(item.getName()))
.must(() -> this.lessEqual(item.getName(), DescriptionTemplateTypeEntity._nameLength))
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> item.getObj() != null)
.on(DescriptionTemplateTypePersist._obj)
.over(item.getObj())
.using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class)),
this.navSpec()
.iff(() -> item.getNested() != null)
.on(DescriptionTemplateTypePersist._nested)
.over(item.getNested())
.using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class))
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale()))
// this.refSpec()
// .iff(() -> item.getObj() != null)
// .on(DescriptionTemplateTypePersist._obj)
// .over(item.getObj())
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class)),
// this.navSpec()
// .iff(() -> item.getNested() != null)
// .on(DescriptionTemplateTypePersist._nested)
// .over(item.getNested())
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class))
);
}
}