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,67 +1,115 @@
|
||||||
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;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private UUID id = null;
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID descriptionTemplateId = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _id = "id";
|
||||||
private Integer minMultiplicity = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private UUID descriptionTemplateId = null;
|
||||||
private Integer maxMultiplicity = null;
|
|
||||||
|
|
||||||
public UUID getId() {
|
public static final String _descriptionTemplateId = "descriptionTemplateId";
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(UUID id) {
|
private String label = null;
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getDescriptionTemplateId() {
|
public static final String _label = "label";
|
||||||
return descriptionTemplateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
|
private Integer minMultiplicity = null;
|
||||||
this.descriptionTemplateId = descriptionTemplateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public static final String _minMultiplicity = "minMultiplicity";
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
private Integer maxMultiplicity = null;
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMinMultiplicity() {
|
public static final String _maxMultiplicity = "maxMultiplicity";
|
||||||
return minMultiplicity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinMultiplicity(Integer minMultiplicity) {
|
public UUID getId() {
|
||||||
this.minMultiplicity = minMultiplicity;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getMaxMultiplicity() {
|
public void setId(UUID id) {
|
||||||
return maxMultiplicity;
|
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;
|
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 DmpBlueprintExtraFieldDataType getDataType() {
|
public static final String _dataType = "dataType";
|
||||||
return 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.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,
|
||||||
property = "category",
|
property = "category",
|
||||||
visible = true)
|
visible = true)
|
||||||
@JsonSubTypes({
|
@JsonSubTypes({
|
||||||
@JsonSubTypes.Type(value = SystemFieldPersist.class, name = "0"),
|
@JsonSubTypes.Type(value = SystemFieldPersist.class, name = "0"),
|
||||||
@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;
|
|
||||||
|
|
||||||
@ValidEnum(message = "{validation.empty}")
|
private UUID id = null;
|
||||||
private DmpBlueprintFieldCategory category;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _id = "id";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private DmpBlueprintFieldCategory category;
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String placeholder = null;
|
|
||||||
|
|
||||||
private String description;
|
public static final String _category = "category";
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private String label = null;
|
||||||
private Integer ordinal = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
private Boolean required = null;
|
|
||||||
|
|
||||||
public UUID getId() {
|
private String placeholder = null;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public static final String _placeholder = "placeholder";
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DmpBlueprintFieldCategory getCategory() {
|
private String description;
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCategory(DmpBlueprintFieldCategory category) {
|
private Integer ordinal = null;
|
||||||
this.category = category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public static final String _ordinal = "ordinal";
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
private Boolean required = null;
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlaceholder() {
|
public static final String _required = "required";
|
||||||
return placeholder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlaceholder(String placeholder) {
|
public UUID getId() {
|
||||||
this.placeholder = placeholder;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public void setId(UUID id) {
|
||||||
return description;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public DmpBlueprintFieldCategory getCategory() {
|
||||||
this.description = description;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getOrdinal() {
|
public void setCategory(DmpBlueprintFieldCategory category) {
|
||||||
return ordinal;
|
this.category = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrdinal(Integer ordinal) {
|
public String getLabel() {
|
||||||
this.ordinal = ordinal;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getRequired() {
|
public void setLabel(String label) {
|
||||||
return required;
|
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;
|
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}")
|
private UUID id = null;
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id = null;
|
|
||||||
|
|
||||||
private String description;
|
public static final String _id = "id";
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private String description;
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
private String label = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
private String label = null;
|
||||||
private Integer ordinal = null;
|
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public static final String _label = "label";
|
||||||
private Boolean hasTemplates = null;
|
|
||||||
|
|
||||||
@Valid
|
private Integer ordinal = null;
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
private List<FieldPersist> fields = null;
|
|
||||||
|
|
||||||
@Valid
|
public static final String _ordinal = "ordinal";
|
||||||
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
|
||||||
|
|
||||||
public UUID getId() {
|
private Boolean hasTemplates = null;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public static final String _hasTemplates = "hasTemplates";
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
private List<FieldPersist> fields = null;
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public static final String _fields = "fields";
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
private List<DescriptionTemplatePersist> descriptionTemplates = null;
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public static final String _descriptionTemplates = "descriptionTemplates";
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getOrdinal() {
|
public UUID getId() {
|
||||||
return ordinal;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrdinal(Integer ordinal) {
|
public void setId(UUID id) {
|
||||||
this.ordinal = ordinal;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getHasTemplates() {
|
public String getLabel() {
|
||||||
return hasTemplates;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHasTemplates(Boolean hasTemplates) {
|
public void setLabel(String label) {
|
||||||
this.hasTemplates = hasTemplates;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FieldPersist> getFields() {
|
public String getDescription() {
|
||||||
return fields;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFields(List<FieldPersist> fields) {
|
public void setDescription(String description) {
|
||||||
this.fields = fields;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DescriptionTemplatePersist> getDescriptionTemplates() {
|
public Integer getOrdinal() {
|
||||||
return descriptionTemplates;
|
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;
|
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;
|
|
||||||
|
|
||||||
public DmpBlueprintSystemFieldType getSystemFieldType() {
|
private DmpBlueprintSystemFieldType systemFieldType;
|
||||||
return 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