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;
|
import java.util.Map;
|
||||||
|
|
||||||
public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
|
public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
|
||||||
System((short)0),
|
System((short) 0),
|
||||||
Extra((short)1);
|
Extra((short) 1);
|
||||||
|
|
||||||
private final Short value;
|
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.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.specification.Specification;
|
import eu.eudat.commons.validation.specification.Specification;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
@ -27,8 +28,6 @@ public class DescriptionPersist {
|
||||||
|
|
||||||
public static final String _label = "label";
|
public static final String _label = "label";
|
||||||
|
|
||||||
public static final int _labelLength = 250;
|
|
||||||
|
|
||||||
private UUID dmpId;
|
private UUID dmpId;
|
||||||
|
|
||||||
public static final String _dmpId = "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())),
|
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> !this.isEmpty(item.getLabel()))
|
.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())),
|
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.must(() -> this.isValidGuid(item.getDmpId()))
|
.must(() -> this.isValidGuid(item.getDmpId()))
|
||||||
|
|
|
@ -1,37 +1,48 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import eu.eudat.commons.validation.old.ValidEnum;
|
import eu.eudat.commons.validation.ValidatorFactory;
|
||||||
import eu.eudat.commons.validation.old.ValidId;
|
import eu.eudat.commons.validation.specification.Specification;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.data.DmpBlueprintEntity;
|
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 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 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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
|
||||||
public class DmpBlueprintPersist {
|
public class DmpBlueprintPersist {
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _id = "id";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
@Size(max = DmpBlueprintEntity._labelLength, message = "{validation.largerthanmax}")
|
@Size(max = DmpBlueprintEntity._labelLength, message = "{validation.largerthanmax}")
|
||||||
private String label = null;
|
private String label = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
@Valid
|
|
||||||
private DefinitionPersist definition = null;
|
private DefinitionPersist definition = null;
|
||||||
|
|
||||||
@ValidEnum(message = "{validation.empty}")
|
public static final String _definition = "definition";
|
||||||
|
|
||||||
private DmpBlueprintStatus status;
|
private DmpBlueprintStatus status;
|
||||||
|
|
||||||
|
public static final String _status = "status";
|
||||||
|
|
||||||
private String hash;
|
private String hash;
|
||||||
|
|
||||||
|
public static final String _hash = "hash";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +82,62 @@ public class DmpBlueprintPersist {
|
||||||
public void setHash(String hash) {
|
public void setHash(String hash) {
|
||||||
this.hash = 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;
|
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.Valid;
|
||||||
import jakarta.validation.constraints.NotNull;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
public class DefinitionPersist {
|
public class DefinitionPersist {
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@Valid
|
|
||||||
private List<SectionPersist> sections = null;
|
private List<SectionPersist> sections = null;
|
||||||
|
|
||||||
|
public static final String _sections = "sections";
|
||||||
|
|
||||||
public List<SectionPersist> getSections() {
|
public List<SectionPersist> getSections() {
|
||||||
return sections;
|
return sections;
|
||||||
}
|
}
|
||||||
|
@ -18,4 +29,41 @@ public class DefinitionPersist {
|
||||||
public void setSections(List<SectionPersist> sections) {
|
public void setSections(List<SectionPersist> sections) {
|
||||||
this.sections = 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,30 +1,39 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.old.ValidId;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import eu.eudat.commons.validation.specification.Specification;
|
||||||
import jakarta.validation.constraints.NotNull;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DescriptionTemplatePersist {
|
public class DescriptionTemplatePersist {
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id = null;
|
private UUID id = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _id = "id";
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID descriptionTemplateId = null;
|
private UUID descriptionTemplateId = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _descriptionTemplateId = "descriptionTemplateId";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
private String label = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
|
|
||||||
private Integer minMultiplicity = null;
|
private Integer minMultiplicity = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _minMultiplicity = "minMultiplicity";
|
||||||
|
|
||||||
private Integer maxMultiplicity = null;
|
private Integer maxMultiplicity = null;
|
||||||
|
|
||||||
|
public static final String _maxMultiplicity = "maxMultiplicity";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -64,4 +73,43 @@ public class DescriptionTemplatePersist {
|
||||||
public void setMaxMultiplicity(Integer maxMultiplicity) {
|
public void setMaxMultiplicity(Integer maxMultiplicity) {
|
||||||
this.maxMultiplicity = 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()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
|
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 {
|
public class ExtraFieldPersist extends FieldPersist {
|
||||||
|
|
||||||
@ValidEnum(message = "{validation.empty}")
|
|
||||||
private DmpBlueprintExtraFieldDataType dataType;
|
private DmpBlueprintExtraFieldDataType dataType;
|
||||||
|
|
||||||
|
public static final String _dataType = "dataType";
|
||||||
|
|
||||||
public DmpBlueprintExtraFieldDataType getDataType() {
|
public DmpBlueprintExtraFieldDataType getDataType() {
|
||||||
return dataType;
|
return dataType;
|
||||||
}
|
}
|
||||||
|
@ -16,4 +25,32 @@ public class ExtraFieldPersist extends FieldPersist {
|
||||||
public void setDataType(DmpBlueprintExtraFieldDataType dataType) {
|
public void setDataType(DmpBlueprintExtraFieldDataType dataType) {
|
||||||
this.dataType = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,17 @@ package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||||
import eu.eudat.commons.validation.old.ValidEnum;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import eu.eudat.commons.validation.old.ValidId;
|
import eu.eudat.commons.validation.specification.Specification;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import eu.eudat.convention.ConventionService;
|
||||||
import jakarta.validation.constraints.NotNull;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
@JsonTypeInfo(
|
@JsonTypeInfo(
|
||||||
use = JsonTypeInfo.Id.NAME,
|
use = JsonTypeInfo.Id.NAME,
|
||||||
include = JsonTypeInfo.As.PROPERTY,
|
include = JsonTypeInfo.As.PROPERTY,
|
||||||
|
@ -21,29 +24,33 @@ import java.util.UUID;
|
||||||
@JsonSubTypes.Type(value = ExtraFieldPersist.class, name = "1")
|
@JsonSubTypes.Type(value = ExtraFieldPersist.class, name = "1")
|
||||||
})
|
})
|
||||||
public abstract class FieldPersist {
|
public abstract class FieldPersist {
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id = null;
|
private UUID id = null;
|
||||||
|
|
||||||
@ValidEnum(message = "{validation.empty}")
|
public static final String _id = "id";
|
||||||
|
|
||||||
private DmpBlueprintFieldCategory category;
|
private DmpBlueprintFieldCategory category;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _category = "category";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
private String label = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String placeholder = null;
|
private String placeholder = null;
|
||||||
|
|
||||||
|
public static final String _placeholder = "placeholder";
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
private Integer ordinal = null;
|
private Integer ordinal = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _ordinal = "ordinal";
|
||||||
|
|
||||||
private Boolean required = null;
|
private Boolean required = null;
|
||||||
|
|
||||||
|
public static final String _required = "required";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -99,4 +106,39 @@ public abstract class FieldPersist {
|
||||||
public void setRequired(Boolean required) {
|
public void setRequired(Boolean required) {
|
||||||
this.required = 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()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,49 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
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 java.util.Arrays;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SectionPersist {
|
public class SectionPersist {
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id = null;
|
private UUID id = null;
|
||||||
|
|
||||||
|
public static final String _id = "id";
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
private String label = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
|
|
||||||
private Integer ordinal = null;
|
private Integer ordinal = null;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _ordinal = "ordinal";
|
||||||
|
|
||||||
private Boolean hasTemplates = null;
|
private Boolean hasTemplates = null;
|
||||||
|
|
||||||
@Valid
|
public static final String _hasTemplates = "hasTemplates";
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
private List<FieldPersist> fields = null;
|
private List<FieldPersist> fields = null;
|
||||||
|
|
||||||
@Valid
|
public static final String _fields = "fields";
|
||||||
|
|
||||||
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
||||||
|
|
||||||
|
public static final String _descriptionTemplates = "descriptionTemplates";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +99,70 @@ public class SectionPersist {
|
||||||
public void setDescriptionTemplates(List<DescriptionTemplatePersist> descriptionTemplates) {
|
public void setDescriptionTemplates(List<DescriptionTemplatePersist> descriptionTemplates) {
|
||||||
this.descriptionTemplates = 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))
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,23 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
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 {
|
public class SystemFieldPersist extends FieldPersist {
|
||||||
@ValidEnum(message = "{validation.empty}")
|
|
||||||
private DmpBlueprintSystemFieldType systemFieldType;
|
private DmpBlueprintSystemFieldType systemFieldType;
|
||||||
|
|
||||||
|
public static final String _systemFieldType = "systemFieldType";
|
||||||
|
|
||||||
public DmpBlueprintSystemFieldType getSystemFieldType() {
|
public DmpBlueprintSystemFieldType getSystemFieldType() {
|
||||||
return systemFieldType;
|
return systemFieldType;
|
||||||
}
|
}
|
||||||
|
@ -14,4 +25,32 @@ public class SystemFieldPersist extends FieldPersist {
|
||||||
public void setSystemFieldType(DmpBlueprintSystemFieldType systemFieldType) {
|
public void setSystemFieldType(DmpBlueprintSystemFieldType systemFieldType) {
|
||||||
this.systemFieldType = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue