Implementing validators for Dmp blueprint persist models (completed)
This commit is contained in:
parent
1462b9944d
commit
3f554554fd
|
@ -6,8 +6,8 @@ import eu.eudat.data.converters.enums.DatabaseEnum;
|
|||
import java.util.Map;
|
||||
|
||||
public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
|
||||
System((short)0),
|
||||
Extra((short)1);
|
||||
System((short) 0),
|
||||
Extra((short) 1);
|
||||
|
||||
private final Short value;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.eudat.commons.validation.ValidatorFactory;
|
|||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -27,8 +28,6 @@ public class DescriptionPersist {
|
|||
|
||||
public static final String _label = "label";
|
||||
|
||||
public static final int _labelLength = 250;
|
||||
|
||||
private UUID dmpId;
|
||||
|
||||
public static final String _dmpId = "dmpId";
|
||||
|
@ -188,7 +187,7 @@ public class DescriptionPersist {
|
|||
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isEmpty(item.getLabel()))
|
||||
.must(() -> this.lessEqualLength(item.getLabel(), DescriptionPersist._labelLength))
|
||||
.must(() -> this.lessEqualLength(item.getLabel(), DescriptionEntity._labelLength))
|
||||
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> this.isValidGuid(item.getDmpId()))
|
||||
|
|
|
@ -1,37 +1,48 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.ValidatorFactory;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||
import eu.eudat.model.persist.dmpblueprintdefinition.DefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||
public class DmpBlueprintPersist {
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
|
||||
private UUID id;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
public static final String _id = "id";
|
||||
|
||||
@Size(max = DmpBlueprintEntity._labelLength, message = "{validation.largerthanmax}")
|
||||
private String label = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@Valid
|
||||
public static final String _label = "label";
|
||||
|
||||
private DefinitionPersist definition = null;
|
||||
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
public static final String _definition = "definition";
|
||||
|
||||
private DmpBlueprintStatus status;
|
||||
|
||||
public static final String _status = "status";
|
||||
|
||||
private String hash;
|
||||
|
||||
public static final String _hash = "hash";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -71,6 +82,62 @@ public class DmpBlueprintPersist {
|
|||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
@Component(DmpBlueprintPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class DmpBlueprintPersistValidator extends BaseValidator<DmpBlueprintPersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprintPersistValidator";
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
||||
protected DmpBlueprintPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
this.validatorFactory = validatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DmpBlueprintPersist> modelClass() {
|
||||
return DmpBlueprintPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(DmpBlueprintPersist item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.iff(() -> this.isValidGuid(item.getId()))
|
||||
.must(() -> this.isValidHash(item.getHash()))
|
||||
.failOn(DmpBlueprintPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._hash}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isValidGuid(item.getId()))
|
||||
.must(() -> !this.isValidHash(item.getHash()))
|
||||
.failOn(DmpBlueprintPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getLabel()))
|
||||
.failOn(DmpBlueprintPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isEmpty(item.getLabel()))
|
||||
.must(() -> this.lessEqualLength(item.getLabel(), DmpBlueprintEntity._labelLength))
|
||||
.failOn(DmpBlueprintPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DmpBlueprintPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getStatus()))
|
||||
.failOn(DmpBlueprintPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._status}, LocaleContextHolder.getLocale())),
|
||||
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getDefinition()))
|
||||
.failOn(DmpBlueprintPersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._definition}, LocaleContextHolder.getLocale())),
|
||||
this.refSpec()
|
||||
.iff(() -> !this.isNull(item.getDefinition()))
|
||||
.on(DmpBlueprintPersist._definition)
|
||||
.over(item.getDefinition())
|
||||
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,27 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.ValidatorFactory;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DefinitionPersist {
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@Valid
|
||||
private List<SectionPersist> sections = null;
|
||||
|
||||
public static final String _sections = "sections";
|
||||
|
||||
public List<SectionPersist> getSections() {
|
||||
return sections;
|
||||
}
|
||||
|
@ -18,4 +29,41 @@ public class DefinitionPersist {
|
|||
public void setSections(List<SectionPersist> sections) {
|
||||
this.sections = sections;
|
||||
}
|
||||
|
||||
@Component(DefinitionPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class DefinitionPersistValidator extends BaseValidator<DefinitionPersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprint.DefinitionPersistValidator";
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
||||
protected DefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
this.validatorFactory = validatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DefinitionPersist> modelClass() {
|
||||
return DefinitionPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(DefinitionPersist item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getSections()))
|
||||
.failOn(DefinitionPersist._sections).failWith(messageSource.getMessage("Validation_Required", new Object[]{eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist._sections}, LocaleContextHolder.getLocale())),
|
||||
this.refSpec()
|
||||
.iff(() -> !this.isNull(item.getSections()))
|
||||
.on(DefinitionPersist._sections)
|
||||
.over(item.getSections())
|
||||
.using(() -> this.validatorFactory.validator(SectionPersist.SectionPersistValidator.class))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,67 +1,115 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.FieldPersist;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DescriptionTemplatePersist {
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID id = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID descriptionTemplateId = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
private String label = null;
|
||||
private UUID id = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Integer minMultiplicity = null;
|
||||
public static final String _id = "id";
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Integer maxMultiplicity = null;
|
||||
private UUID descriptionTemplateId = null;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public static final String _descriptionTemplateId = "descriptionTemplateId";
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
private String label = null;
|
||||
|
||||
public UUID getDescriptionTemplateId() {
|
||||
return descriptionTemplateId;
|
||||
}
|
||||
public static final String _label = "label";
|
||||
|
||||
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
|
||||
this.descriptionTemplateId = descriptionTemplateId;
|
||||
}
|
||||
private Integer minMultiplicity = null;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public static final String _minMultiplicity = "minMultiplicity";
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
private Integer maxMultiplicity = null;
|
||||
|
||||
public Integer getMinMultiplicity() {
|
||||
return minMultiplicity;
|
||||
}
|
||||
public static final String _maxMultiplicity = "maxMultiplicity";
|
||||
|
||||
public void setMinMultiplicity(Integer minMultiplicity) {
|
||||
this.minMultiplicity = minMultiplicity;
|
||||
}
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Integer getMaxMultiplicity() {
|
||||
return maxMultiplicity;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UUID getDescriptionTemplateId() {
|
||||
return descriptionTemplateId;
|
||||
}
|
||||
|
||||
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
|
||||
this.descriptionTemplateId = descriptionTemplateId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Integer getMinMultiplicity() {
|
||||
return minMultiplicity;
|
||||
}
|
||||
|
||||
public void setMinMultiplicity(Integer minMultiplicity) {
|
||||
this.minMultiplicity = minMultiplicity;
|
||||
}
|
||||
|
||||
public Integer getMaxMultiplicity() {
|
||||
return maxMultiplicity;
|
||||
}
|
||||
|
||||
public void setMaxMultiplicity(Integer maxMultiplicity) {
|
||||
this.maxMultiplicity = maxMultiplicity;
|
||||
}
|
||||
|
||||
public static class DescriptionTemplatePersistValidator extends BaseValidator<DescriptionTemplatePersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprint.DescriptionTemplatePersistValidator";
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
protected DescriptionTemplatePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DescriptionTemplatePersist> modelClass() {
|
||||
return DescriptionTemplatePersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(DescriptionTemplatePersist item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> this.isValidGuid(item.getId()))
|
||||
.failOn(DescriptionTemplatePersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._id}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> this.isValidGuid(item.getDescriptionTemplateId()))
|
||||
.failOn(DescriptionTemplatePersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._descriptionTemplateId}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getLabel()))
|
||||
.failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getMinMultiplicity()))
|
||||
.failOn(DescriptionTemplatePersist._minMultiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._minMultiplicity}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getMaxMultiplicity()))
|
||||
.failOn(DescriptionTemplatePersist._maxMultiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._maxMultiplicity}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxMultiplicity(Integer maxMultiplicity) {
|
||||
this.maxMultiplicity = maxMultiplicity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,56 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExtraFieldPersist extends FieldPersist {
|
||||
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
private DmpBlueprintExtraFieldDataType dataType;
|
||||
private DmpBlueprintExtraFieldDataType dataType;
|
||||
|
||||
public DmpBlueprintExtraFieldDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
public static final String _dataType = "dataType";
|
||||
|
||||
public DmpBlueprintExtraFieldDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(DmpBlueprintExtraFieldDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
@Component(ExtraFieldPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class ExtraFieldPersistValidator extends BaseFieldPersistValidator<ExtraFieldPersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprint.ExtraFieldPersistValidator";
|
||||
|
||||
protected ExtraFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
||||
super(conventionService, errors, messageSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ExtraFieldPersist> modelClass() {
|
||||
return ExtraFieldPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(ExtraFieldPersist item) {
|
||||
List<Specification> specifications = getBaseSpecifications(item);
|
||||
specifications.add(
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getDataType()))
|
||||
.failOn(ExtraFieldPersist._dataType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExtraFieldPersist._dataType}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
return specifications;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDataType(DmpBlueprintExtraFieldDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,100 +3,142 @@ package eu.eudat.model.persist.dmpblueprintdefinition;
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
property = "category",
|
||||
visible = true)
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
property = "category",
|
||||
visible = true)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = SystemFieldPersist.class, name = "0"),
|
||||
@JsonSubTypes.Type(value = ExtraFieldPersist.class, name = "1")
|
||||
@JsonSubTypes.Type(value = SystemFieldPersist.class, name = "0"),
|
||||
@JsonSubTypes.Type(value = ExtraFieldPersist.class, name = "1")
|
||||
})
|
||||
public abstract class FieldPersist {
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID id = null;
|
||||
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
private DmpBlueprintFieldCategory category;
|
||||
private UUID id = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
private String label = null;
|
||||
public static final String _id = "id";
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
private String placeholder = null;
|
||||
private DmpBlueprintFieldCategory category;
|
||||
|
||||
private String description;
|
||||
public static final String _category = "category";
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Integer ordinal = null;
|
||||
private String label = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Boolean required = null;
|
||||
public static final String _label = "label";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
private String placeholder = null;
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
public static final String _placeholder = "placeholder";
|
||||
|
||||
public DmpBlueprintFieldCategory getCategory() {
|
||||
return category;
|
||||
}
|
||||
private String description;
|
||||
|
||||
public void setCategory(DmpBlueprintFieldCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
private Integer ordinal = null;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public static final String _ordinal = "ordinal";
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
private Boolean required = null;
|
||||
|
||||
public String getPlaceholder() {
|
||||
return placeholder;
|
||||
}
|
||||
public static final String _required = "required";
|
||||
|
||||
public void setPlaceholder(String placeholder) {
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public DmpBlueprintFieldCategory getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
public void setCategory(DmpBlueprintFieldCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return required;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getPlaceholder() {
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
public void setPlaceholder(String placeholder) {
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public abstract static class BaseFieldPersistValidator<T extends FieldPersist> extends BaseValidator<T> {
|
||||
|
||||
protected final MessageSource messageSource;
|
||||
|
||||
protected BaseFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
protected List<Specification> getBaseSpecifications(T item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> this.isValidGuid(item.getId()))
|
||||
.failOn(FieldPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._id}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getCategory()))
|
||||
.failOn(FieldPersist._category).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._category}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getLabel()))
|
||||
.failOn(FieldPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getPlaceholder()))
|
||||
.failOn(FieldPersist._placeholder).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._placeholder}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getOrdinal()))
|
||||
.failOn(FieldPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._ordinal}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getRequired()))
|
||||
.failOn(FieldPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._required}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +1,168 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.ValidatorFactory;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SectionPersist {
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID id = null;
|
||||
private UUID id = null;
|
||||
|
||||
private String description;
|
||||
public static final String _id = "id";
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
private String label = null;
|
||||
private String description;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Integer ordinal = null;
|
||||
private String label = null;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private Boolean hasTemplates = null;
|
||||
public static final String _label = "label";
|
||||
|
||||
@Valid
|
||||
@NotNull(message = "{validation.empty}")
|
||||
private List<FieldPersist> fields = null;
|
||||
private Integer ordinal = null;
|
||||
|
||||
@Valid
|
||||
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
||||
public static final String _ordinal = "ordinal";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
private Boolean hasTemplates = null;
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
public static final String _hasTemplates = "hasTemplates";
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
private List<FieldPersist> fields = null;
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
public static final String _fields = "fields";
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public static final String _descriptionTemplates = "descriptionTemplates";
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Boolean getHasTemplates() {
|
||||
return hasTemplates;
|
||||
}
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setHasTemplates(Boolean hasTemplates) {
|
||||
this.hasTemplates = hasTemplates;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public List<FieldPersist> getFields() {
|
||||
return fields;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setFields(List<FieldPersist> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<DescriptionTemplatePersist> getDescriptionTemplates() {
|
||||
return descriptionTemplates;
|
||||
}
|
||||
public Integer getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
public Boolean getHasTemplates() {
|
||||
return hasTemplates;
|
||||
}
|
||||
|
||||
public void setHasTemplates(Boolean hasTemplates) {
|
||||
this.hasTemplates = hasTemplates;
|
||||
}
|
||||
|
||||
public List<FieldPersist> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<FieldPersist> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<DescriptionTemplatePersist> getDescriptionTemplates() {
|
||||
return descriptionTemplates;
|
||||
}
|
||||
|
||||
public void setDescriptionTemplates(List<DescriptionTemplatePersist> descriptionTemplates) {
|
||||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
|
||||
@Component(SectionPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class SectionPersistValidator extends BaseValidator<SectionPersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprint.SectionPersistValidator";
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
||||
protected SectionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
this.validatorFactory = validatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<SectionPersist> modelClass() {
|
||||
return SectionPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(SectionPersist item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> this.isValidGuid(item.getId()))
|
||||
.failOn(SectionPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._id}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getLabel()))
|
||||
.failOn(SectionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getOrdinal()))
|
||||
.failOn(SectionPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._ordinal}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getHasTemplates()))
|
||||
.failOn(SectionPersist._hasTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._hasTemplates}, LocaleContextHolder.getLocale())),
|
||||
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getFields()))
|
||||
.failOn(SectionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{eu.eudat.model.persist.descriptiontemplatedefinition.SectionPersist._fieldSets}, LocaleContextHolder.getLocale())),
|
||||
this.navSpec()
|
||||
.iff(() -> !this.isNull(item.getFields()))
|
||||
.on(SectionPersist._fields)
|
||||
.over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.System).toList())
|
||||
.using(() -> this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class)),
|
||||
this.navSpec()
|
||||
.iff(() -> !this.isNull(item.getFields()))
|
||||
.on(SectionPersist._fields)
|
||||
.over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).toList())
|
||||
.using(() -> this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class)),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getDescriptionTemplates()))
|
||||
.failOn(SectionPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
|
||||
this.navSpec()
|
||||
.iff(() -> !this.isNull(item.getDescriptionTemplates()))
|
||||
.on(SectionPersist._descriptionTemplates)
|
||||
.over(item.getDescriptionTemplates())
|
||||
.using(() -> this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class))
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDescriptionTemplates(List<DescriptionTemplatePersist> descriptionTemplates) {
|
||||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,56 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SystemFieldPersist extends FieldPersist {
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
private DmpBlueprintSystemFieldType systemFieldType;
|
||||
|
||||
public DmpBlueprintSystemFieldType getSystemFieldType() {
|
||||
return systemFieldType;
|
||||
}
|
||||
private DmpBlueprintSystemFieldType systemFieldType;
|
||||
|
||||
public static final String _systemFieldType = "systemFieldType";
|
||||
|
||||
public DmpBlueprintSystemFieldType getSystemFieldType() {
|
||||
return systemFieldType;
|
||||
}
|
||||
|
||||
public void setSystemFieldType(DmpBlueprintSystemFieldType systemFieldType) {
|
||||
this.systemFieldType = systemFieldType;
|
||||
}
|
||||
|
||||
@Component(SystemFieldPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class SystemFieldPersistValidator extends BaseFieldPersistValidator<SystemFieldPersist> {
|
||||
|
||||
public static final String ValidatorName = "DmpBlueprint.SystemFieldPersistValidator";
|
||||
|
||||
protected SystemFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
||||
super(conventionService, errors, messageSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<SystemFieldPersist> modelClass() {
|
||||
return SystemFieldPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(SystemFieldPersist item) {
|
||||
List<Specification> specifications = getBaseSpecifications(item);
|
||||
specifications.add(
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getSystemFieldType()))
|
||||
.failOn(SystemFieldPersist._systemFieldType).failWith(messageSource.getMessage("Validation_Required", new Object[]{SystemFieldPersist._systemFieldType}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
return specifications;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSystemFieldType(DmpBlueprintSystemFieldType systemFieldType) {
|
||||
this.systemFieldType = systemFieldType;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue