Implementing validators for Description template related persist models (not completed)

This commit is contained in:
Thomas Georgios Giannos 2023-12-22 19:00:53 +02:00
parent 63ffeabe62
commit 2a6b047327
30 changed files with 1970 additions and 674 deletions

View File

@ -8,8 +8,6 @@ import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
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 jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;

View File

@ -1,28 +1,34 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.DescriptionStatus;
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.specification.Specification;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.convention.ConventionService;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.errorcode.ErrorThesaurusProperties;
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.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DescriptionStatusPersist { public class DescriptionStatusPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@ValidEnum(message = "{validation.empty}") public static final String _id = "id";
private DescriptionStatus status; private DescriptionStatus status;
@NotNull(message = "{validation.empty}") public static final String _status = "status";
@NotEmpty(message = "{validation.empty}")
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -46,4 +52,40 @@ public class DescriptionStatusPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(DescriptionStatusPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionStatusPersistValidator extends BaseValidator<DescriptionStatusPersist> {
public static final String ValidatorName = "DescriptionStatusPersistValidator";
private final MessageSource messageSource;
protected DescriptionStatusPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DescriptionStatusPersist> modelClass() {
return DescriptionStatusPersist.class;
}
@Override
protected List<Specification> specifications(DescriptionStatusPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isValidGuid(item.getId()))
.failOn(DescriptionStatusPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionStatusPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStatus()))
.failOn(DescriptionStatusPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._status}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,55 +1,65 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.DescriptionTemplateStatus; import eu.eudat.commons.enums.DescriptionTemplateStatus;
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.data.DescriptionTemplateEntity; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist; import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; 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.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DescriptionTemplatePersist { public class DescriptionTemplatePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = DescriptionTemplateEntity._labelLength, message = "{validation.largerthanmax}")
private String label = null; private String label = null;
@NotNull(message = "{validation.empty}") public static final String _label = "label";
@NotEmpty(message = "{validation.empty}")
public static final int _labelLength = 250;
private String description = null; private String description = null;
@NotNull(message = "{validation.empty}") public static final String _description = "description";
@NotEmpty(message = "{validation.empty}")
private String language = null; private String language = null;
@NotNull(message = "{validation.empty}") public static final String _language = "language";
@ValidId(message = "{validation.invalidid}")
private UUID type = null; private UUID type = null;
@ValidEnum(message = "{validation.empty}") public static final String _type = "type";
private DescriptionTemplateStatus status; private DescriptionTemplateStatus status;
public static final String _status = "status";
@NotNull(message = "{validation.empty}") @NotNull(message = "{validation.empty}")
@Valid @Valid
private DefinitionPersist definition = null; private DefinitionPersist definition = null;
public static final String _definition = "definition";
@Valid @Valid
private List<UserDescriptionTemplatePersist> users = null; private List<UserDescriptionTemplatePersist> users = null;
public static final String _users = "users";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -121,6 +131,79 @@ public class DescriptionTemplatePersist {
public void setUsers(List<UserDescriptionTemplatePersist> users) { public void setUsers(List<UserDescriptionTemplatePersist> users) {
this.users = users; this.users = users;
} }
@Component(DescriptionTemplatePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionTemplatePersistValidator extends BaseValidator<DescriptionTemplatePersist> {
public static final String ValidatorName = "DescriptionTemplatePersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DescriptionTemplatePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DescriptionTemplatePersist> modelClass() {
return DescriptionTemplatePersist.class;
}
@Override
protected List<Specification> specifications(DescriptionTemplatePersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, 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()
.iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqual(item.getLabel(), DescriptionTemplatePersist._labelLength))
.failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getDescription()))
.failOn(DescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLanguage()))
.failOn(DescriptionTemplatePersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getType()))
.failOn(DescriptionTemplatePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStatus()))
.failOn(DescriptionTemplatePersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._status}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDefinition()))
.failOn(DescriptionTemplatePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._definition}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getDefinition()))
.on(DescriptionTemplatePersist._definition)
.over(item.getDefinition())
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getUsers()))
.failOn(DescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getUsers()))
.on(DescriptionTemplatePersist._users)
.over(item.getUsers())
.using(() -> null) //TODO (thgiannos)
);
}
}
} }

View File

@ -1,20 +1,29 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
import jakarta.validation.Valid; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; 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 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;
@NotNull(message = "{validation.empty}") public static final String _sections = "sections";
@Valid
private List<PagePersist> pages = null; private List<PagePersist> pages = null;
public static final String _pages = "pages";
public List<SectionPersist> getSections() { public List<SectionPersist> getSections() {
return sections; return sections;
} }
@ -30,4 +39,49 @@ public class DefinitionPersist {
public void setPages(List<PagePersist> pages) { public void setPages(List<PagePersist> pages) {
this.pages = pages; this.pages = pages;
} }
@Component(DefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DefinitionPersistValidator extends BaseValidator<DefinitionPersist> {
public static final String ValidatorName = "DescriptionTemplate.DefinitionPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
public 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[]{DefinitionPersist._sections}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getSections()))
.on(DefinitionPersist._sections)
.over(item.getSections())
.using(() -> this.validatorFactory.validator(SectionPersist.SectionPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getPages()))
.failOn(DefinitionPersist._pages).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefinitionPersist._pages}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getPages()))
.on(DefinitionPersist._pages)
.over(item.getPages())
.using(() -> this.validatorFactory.validator(PagePersist.PagePersistValidator.class))
);
}
}
} }

View File

@ -1,38 +1,50 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.enums.FieldValidationType; import eu.eudat.commons.enums.FieldValidationType;
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.Valid; import eu.eudat.commons.validation.ValidatorFactory;
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.fielddata.*;
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 FieldPersist { public class FieldPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String id = null; private String id = null;
@NotNull(message = "{validation.empty}") public static final String _id = "id";
private Integer ordinal = null; private Integer ordinal = null;
public static final String _ordinal = "ordinal";
private List<String> schematics; private List<String> schematics;
private String defaultValue; private String defaultValue;
@Valid
private List<RulePersist> visibilityRules; private List<RulePersist> visibilityRules;
public static final String _visibilityRules = "visibilityRules";
private List<FieldValidationType> validations; private List<FieldValidationType> validations;
@NotNull(message = "{validation.empty}")
private Boolean includeInExport = null; private Boolean includeInExport = null;
@NotNull(message = "{validation.empty}") public static final String _includeInExport = "includeInExport";
@Valid
private BaseFieldDataPersist data = null; private BaseFieldDataPersist data = null;
public static final String _data = "data";
public String getId() { public String getId() {
return id; return id;
} }
@ -96,4 +108,108 @@ public class FieldPersist {
public void setData(BaseFieldDataPersist data) { public void setData(BaseFieldDataPersist data) {
this.data = data; this.data = data;
} }
@Component(FieldPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FieldPersistValidator extends BaseValidator<FieldPersist> {
public static final String ValidatorName = "DescriptionTemplate.FieldPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<FieldPersist> modelClass() {
return FieldPersist.class;
}
@Override
protected List<Specification> specifications(FieldPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getId()))
.failOn(FieldPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._id}, 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.getIncludeInExport()))
.failOn(FieldPersist._includeInExport).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._includeInExport}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getVisibilityRules()))
.on(FieldPersist._visibilityRules)
.over(item.getVisibilityRules())
.using(() -> this.validatorFactory.validator(RulePersist.RulePersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.AUTO_COMPLETE)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(AutoCompleteDataPersist.AutoCompleteDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.BOOLEAN_DECISION)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(BooleanDecisionDataPersist.BooleanDecisionPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.INTERNAL_DMP_ENTRIES_DATASETS)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(DatasetAutoCompleteDataPersist.DatasetAutoCompleteDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.INTERNAL_DMP_ENTRIES_DMPS)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(DmpAutoCompleteDataPersist.DmpAutoCompleteDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.CHECK_BOX)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(CheckBoxDataPersist.CheckBoxDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.DATE_PICKER)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(DatePickerDataPersist.DatePickerDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.EXTERNAL_DATASETS)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(ExternalDatasetDataPersist.ExternalDatasetDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.FREE_TEXT)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(FreeTextDataPersist.FreeTextDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.LICENSES)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(LicenseDataPersist.LicenseDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.ORGANIZATIONS)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(OrganizationDataPersist.OrganizationDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.PUBLICATIONS)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(PublicationDataPersist.PublicationDataPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.RADIO_BOX)
.on(FieldPersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(RadioBoxDataPersist.RadioBoxDataPersistValidator.class))
);
}
}
} }

View File

@ -1,50 +1,55 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
import jakarta.validation.Valid; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.ValidatorFactory;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List; import java.util.List;
public class FieldSetPersist { public class FieldSetPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String id = null; private String id = null;
@NotNull(message = "{validation.empty}") public static final String _id = "id";
private Integer ordinal = null; private Integer ordinal = null;
@NotNull(message = "{validation.empty}") public static final String _ordinal = "ordinal";
@NotEmpty(message = "{validation.empty}")
private String numbering = null; private String numbering = null;
@NotNull(message = "{validation.empty}") public static final String _numbering = "numbering";
@NotEmpty(message = "{validation.empty}")
private String title = null; private String title = null;
@NotNull(message = "{validation.empty}") public static final String _title = "title";
@NotEmpty(message = "{validation.empty}")
private String description = null; private String description = null;
// @NotNull(message = "{validation.empty}") public static final String _description = "description";
// @NotEmpty(message = "{validation.empty}")
private String extendedDescription = null; private String extendedDescription = null;
// @NotNull(message = "{validation.empty}")
// @NotEmpty(message = "{validation.empty}")
private String additionalInformation = null; private String additionalInformation = null;
@Valid
private MultiplicityPersist multiplicity = null; private MultiplicityPersist multiplicity = null;
public static final String _multiplicity = "multiplicity";
private Boolean hasCommentField = null; private Boolean hasCommentField = null;
@NotNull(message = "{validation.empty}")
@Valid
private List<FieldPersist> fields = null; private List<FieldPersist> fields = null;
public static final String _fields = "fields";
public String getId() { public String getId() {
return id; return id;
} }
@ -124,4 +129,59 @@ public class FieldSetPersist {
public void setFields(List<FieldPersist> fields) { public void setFields(List<FieldPersist> fields) {
this.fields = fields; this.fields = fields;
} }
@Component(FieldSetPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FieldSetPersistValidator extends BaseValidator<FieldSetPersist> {
public static final String ValidatorName = "DescriptionTemplate.FieldSetPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected FieldSetPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<FieldSetPersist> modelClass() {
return FieldSetPersist.class;
}
@Override
protected List<Specification> specifications(FieldSetPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getId()))
.failOn(FieldSetPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getOrdinal()))
.failOn(FieldSetPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._ordinal}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getNumbering()))
.failOn(FieldSetPersist._numbering).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._numbering}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getTitle()))
.failOn(FieldSetPersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._title}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getDescription()))
.failOn(FieldSetPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._description}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getMultiplicity()))
.on(FieldSetPersist._multiplicity)
.over(item.getMultiplicity())
.using(() -> this.validatorFactory.validator(MultiplicityPersist.MultiplicityValidator.class)),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.on(FieldSetPersist._fields)
.over(item.getFields())
.using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))
);
}
}
} }

View File

@ -1,7 +1,15 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
public class MultiplicityPersist { public class MultiplicityPersist {
@ -44,4 +52,26 @@ public class MultiplicityPersist {
public void setTableView(Boolean tableView) { public void setTableView(Boolean tableView) {
this.tableView = tableView; this.tableView = tableView;
} }
@Component(MultiplicityValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class MultiplicityValidator extends BaseValidator<MultiplicityPersist> {
public static final String ValidatorName = "DescriptionTemplate.MultiplicityValidator";
protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
super(conventionService, errors);
}
@Override
protected Class<MultiplicityPersist> modelClass() {
return MultiplicityPersist.class;
}
@Override
protected List<Specification> specifications(MultiplicityPersist item) {
return Lists.newArrayList();
}
}
} }

View File

@ -1,21 +1,32 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
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.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 jakarta.validation.constraints.NotEmpty; import java.util.Arrays;
import jakarta.validation.constraints.NotNull; import java.util.List;
public class PagePersist { public class PagePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String id = null; private String id = null;
@NotNull(message = "{validation.empty}") public static final String _id = "id";
private Integer ordinal = null; private Integer ordinal = null;
@NotNull(message = "{validation.empty}") public static final String _ordinal = "ordinal";
@NotEmpty(message = "{validation.empty}")
private String title = null; private String title = null;
public static final String _title = "title";
public String getId() { public String getId() {
return id; return id;
} }
@ -39,6 +50,41 @@ public class PagePersist {
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
@Component(PagePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class PagePersistValidator extends BaseValidator<PagePersist> {
public static final String ValidatorName = "DescriptionTemplate.PagePersistValidator";
private final MessageSource messageSource;
protected PagePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<PagePersist> modelClass() {
return PagePersist.class;
}
@Override
protected List<Specification> specifications(PagePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getId()))
.failOn(PagePersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getOrdinal()))
.failOn(PagePersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._ordinal}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getTitle()))
.failOn(PagePersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._title}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,18 +1,27 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List;
public class RulePersist { public class RulePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String target = null; private String target = null;
@NotNull(message = "{validation.empty}") public static final String _target = "target";
@NotEmpty(message = "{validation.empty}")
private String value = null; private String value = null;
public static final String _value = "value";
public String getTarget() { public String getTarget() {
return target; return target;
@ -30,4 +39,35 @@ public class RulePersist {
this.value = value; this.value = value;
} }
@Component(RulePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class RulePersistValidator extends BaseValidator<RulePersist> {
public static final String ValidatorName = "DescriptionTemplate.RulePersistValidator";
private final MessageSource messageSource;
protected RulePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<RulePersist> modelClass() {
return RulePersist.class;
}
@Override
protected List<Specification> specifications(RulePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getTarget()))
.failOn(RulePersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(RulePersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{RulePersist._value}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,47 +1,59 @@
package eu.eudat.model.persist.descriptiontemplatedefinition; package eu.eudat.model.persist.descriptiontemplatedefinition;
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 eu.eudat.model.persist.ActionConfirmationPersist;
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
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 jakarta.validation.Valid; import java.util.Arrays;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List; import java.util.List;
public class SectionPersist { public class SectionPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String id = null; private String id = null;
@NotNull(message = "{validation.empty}") public static final String _id = "id";
private Integer ordinal = null; private Integer ordinal = null;
@NotNull(message = "{validation.empty}") public static final String _ordinal = "ordinal";
private Boolean defaultVisibility = null; private Boolean defaultVisibility = null;
@NotNull(message = "{validation.empty}") public static final String _defaultVisibility = "defaultVisibility";
private Boolean multiplicity = null; private Boolean multiplicity = null;
@NotNull(message = "{validation.empty}") public static final String _multiplicity = "multiplicity";
@NotEmpty(message = "{validation.empty}")
private String page = null; private String page = null;
@NotNull(message = "{validation.empty}") public static final String _page = "page";
@NotEmpty(message = "{validation.empty}")
private String title = null; private String title = null;
@NotNull(message = "{validation.empty}") public static final String _title = "title";
@NotEmpty(message = "{validation.empty}")
private String description = null; private String description = null;
@NotNull(message = "{validation.empty}") public static final String _description = "description";
@Valid
private List<SectionPersist> sections = null; private List<SectionPersist> sections = null;
@NotNull(message = "{validation.empty}") public static final String _sections = "sections";
@Valid
private List<FieldSetPersist> fieldSets = null; private List<FieldSetPersist> fieldSets = null;
public static final String _fieldSets = "fieldSets";
public String getId() { public String getId() {
return id; return id;
} }
@ -113,6 +125,70 @@ public class SectionPersist {
public void setFieldSets(List<FieldSetPersist> fieldSets) { public void setFieldSets(List<FieldSetPersist> fieldSets) {
this.fieldSets = fieldSets; this.fieldSets = fieldSets;
} }
@Component(SectionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class SectionPersistValidator extends BaseValidator<SectionPersist> {
public static final String ValidatorName = "DescriptionTemplate.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.isEmpty(item.getId()))
.failOn(SectionPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._id}, 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.getDefaultVisibility()))
.failOn(SectionPersist._defaultVisibility).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._defaultVisibility}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getMultiplicity()))
.failOn(SectionPersist._multiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._multiplicity}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPage()))
.failOn(SectionPersist._page).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._page}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getTitle()))
.failOn(SectionPersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._title}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getDescription()))
.failOn(SectionPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._description}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getSections()))
.on(SectionPersist._sections)
.over(item.getSections())
.using(() -> this.validatorFactory.validator(SectionPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getFieldSets()))
.failOn(SectionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._fieldSets}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFieldSets()))
.on(SectionPersist._fieldSets)
.over(item.getFieldSets())
.using(() -> this.validatorFactory.validator(FieldSetPersist.FieldSetPersistValidator.class))
);
}
}
} }

View File

@ -1,29 +1,37 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; 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;
public class AuthAutoCompleteDataPersist { public class AuthAutoCompleteDataPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String url = null; private String url = null;
@NotNull(message = "{validation.empty}") public static final String _uri = "uri";
@NotEmpty(message = "{validation.empty}")
private String method = null; private String method = null;
@NotNull(message = "{validation.empty}") public static final String _method = "method";
@NotEmpty(message = "{validation.empty}")
private String body = null; private String body = null;
@NotNull(message = "{validation.empty}") public static final String _body = "body";
@NotEmpty(message = "{validation.empty}")
private String path = null; private String path = null;
@NotNull(message = "{validation.empty}") public static final String _path = "path";
@NotEmpty(message = "{validation.empty}")
private String type = null; private String type = null;
public static final String _type = "type";
public String getUrl() { public String getUrl() {
return url; return url;
} }
@ -63,4 +71,43 @@ public class AuthAutoCompleteDataPersist {
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public static class AuthAutoCompleteDataPersistValidator extends BaseValidator<AuthAutoCompleteDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.AuthAutoCompleteDataPersistValidator";
private final MessageSource messageSource;
protected AuthAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<AuthAutoCompleteDataPersist> modelClass() {
return AuthAutoCompleteDataPersist.class;
}
@Override
protected List<Specification> specifications(AuthAutoCompleteDataPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(AuthAutoCompleteDataPersist._uri).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._uri}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getMethod()))
.failOn(AuthAutoCompleteDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._method}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getBody()))
.failOn(AuthAutoCompleteDataPersist._body).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._body}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPath()))
.failOn(AuthAutoCompleteDataPersist._path).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._path}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getType()))
.failOn(AuthAutoCompleteDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._type}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,20 +1,35 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.Valid; import eu.eudat.commons.validation.ValidatorFactory;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List; import java.util.List;
public class AutoCompleteDataPersist extends BaseFieldDataPersist { public class AutoCompleteDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
@NotNull(message = "{validation.empty}") public static final String _multiAutoComplete = "multiAutoComplete";
@Valid
private List<AutoCompleteSingleDataPersist> autoCompleteSingleDataList = null; private List<AutoCompleteSingleDataPersist> autoCompleteSingleDataList = null;
public Boolean getMultiAutoComplete() { return multiAutoComplete; } public static final String _autoCompleteSingleDataList = "autoCompleteSingleDataList";
public void setMultiAutoComplete(Boolean multiAutoComplete) { this.multiAutoComplete = multiAutoComplete; }
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
public List<AutoCompleteSingleDataPersist> getAutoCompleteSingleDataList() { public List<AutoCompleteSingleDataPersist> getAutoCompleteSingleDataList() {
return autoCompleteSingleDataList; return autoCompleteSingleDataList;
@ -23,5 +38,40 @@ public class AutoCompleteDataPersist extends BaseFieldDataPersist {
public void setAutoCompleteSingleDataList(List<AutoCompleteSingleDataPersist> autoCompleteSingleDataList) { public void setAutoCompleteSingleDataList(List<AutoCompleteSingleDataPersist> autoCompleteSingleDataList) {
this.autoCompleteSingleDataList = autoCompleteSingleDataList; this.autoCompleteSingleDataList = autoCompleteSingleDataList;
} }
@Component(AutoCompleteDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class AutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator<AutoCompleteDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.AutoCompleteDataPersistValidator";
private final ValidatorFactory validatorFactory;
protected AutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<AutoCompleteDataPersist> modelClass() {
return AutoCompleteDataPersist.class;
}
@Override
protected List<Specification> specifications(AutoCompleteDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(AutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getAutoCompleteSingleDataList()))
.on(AutoCompleteDataPersist._autoCompleteSingleDataList)
.over(item.getAutoCompleteSingleDataList())
.using(() -> this.validatorFactory.validator(AutoCompleteSingleDataPersist.AutoCompleteSingleDataPersistValidator.class))
));
return specifications;
}
}
} }

View File

@ -1,35 +1,48 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.Valid; import eu.eudat.commons.validation.ValidatorFactory;
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 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 AutoCompleteSingleDataPersist { public class AutoCompleteSingleDataPersist {
@ValidEnum(message = "{validation.empty}")
private AutoCompleteDataEntity.AutocompleteType autocompleteType; private AutoCompleteDataEntity.AutocompleteType autocompleteType;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}") public static final String _autocompleteType = "autocompleteType";
private String url = null; private String url = null;
@Valid public static final String _url = "url";
private ComboBoxOptionPersist autoCompleteOptions; private ComboBoxOptionPersist autoCompleteOptions;
public static final String _autoCompleteOptions = "autoCompleteOptions";
private String optionsRoot; private String optionsRoot;
@NotNull(message = "{validation.empty}")
private Boolean hasAuth = null; private Boolean hasAuth = null;
@Valid public static final String _hasAuth = "hasAuth";
private AuthAutoCompleteDataPersist auth; private AuthAutoCompleteDataPersist auth;
@NotNull(message = "{validation.empty}") public static final String _auth = "auth";
@NotEmpty(message = "{validation.empty}")
private String method = null; private String method = null;
public static final String _method = "method";
public AutoCompleteDataEntity.AutocompleteType getAutocompleteType() { public AutoCompleteDataEntity.AutocompleteType getAutocompleteType() {
return autocompleteType; return autocompleteType;
} }
@ -85,4 +98,60 @@ public class AutoCompleteSingleDataPersist {
public void setMethod(String method) { public void setMethod(String method) {
this.method = method; this.method = method;
} }
@Component(AutoCompleteSingleDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class AutoCompleteSingleDataPersistValidator extends BaseValidator<AutoCompleteSingleDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.AutoCompleteSingleDataPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected AutoCompleteSingleDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<AutoCompleteSingleDataPersist> modelClass() {
return AutoCompleteSingleDataPersist.class;
}
@Override
protected List<Specification> specifications(AutoCompleteSingleDataPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getAutocompleteType()))
.failOn(AutoCompleteSingleDataPersist._autocompleteType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._autocompleteType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(AutoCompleteSingleDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getHasAuth()))
.failOn(AutoCompleteSingleDataPersist._hasAuth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._hasAuth}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getMethod()))
.failOn(AutoCompleteSingleDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._method}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getAutoCompleteOptions()))
.on(AutoCompleteSingleDataPersist._autoCompleteOptions)
.over(item.getAutoCompleteOptions())
.using(() -> this.validatorFactory.validator(ComboBoxOptionPersist.ComboBoxOptionPersistValidator.class)),
this.spec()
.iff(() -> !this.isNull(item.getHasAuth()) && item.getHasAuth())
.must(() -> !this.isNull(item.getAuth()))
.failOn(AutoCompleteSingleDataPersist._auth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._auth}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getAuth()))
.on(AutoCompleteSingleDataPersist._auth)
.over(item.getAuth())
.using(() -> this.validatorFactory.validator(AuthAutoCompleteDataPersist.AuthAutoCompleteDataPersistValidator.class))
);
}
}
} }

View File

@ -3,9 +3,15 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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.FieldType; import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.validation.old.ValidEnum; 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 org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.Arrays;
import java.util.List;
@JsonTypeInfo( @JsonTypeInfo(
use = JsonTypeInfo.Id.NAME, use = JsonTypeInfo.Id.NAME,
@ -44,13 +50,14 @@ import jakarta.validation.constraints.NotNull;
}) })
public abstract class BaseFieldDataPersist { public abstract class BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String label = null; private String label = null;
@ValidEnum(message = "{validation.empty}") public static final String _label = "label";
private FieldType fieldType; private FieldType fieldType;
public static final String _fieldType = "fieldType";
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -66,4 +73,27 @@ public abstract class BaseFieldDataPersist {
public void setFieldType(FieldType fieldType) { public void setFieldType(FieldType fieldType) {
this.fieldType = fieldType; this.fieldType = fieldType;
} }
public abstract static class BaseFieldDataPersistValidator<T extends BaseFieldDataPersist> extends BaseValidator<T> {
protected final MessageSource messageSource;
protected BaseFieldDataPersistValidator(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.isEmpty(item.getLabel()))
.failOn(BaseFieldDataPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getFieldType()))
.failOn(BaseFieldDataPersist._fieldType).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,5 +1,40 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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.stereotype.Component;
import java.util.List;
public class BooleanDecisionDataPersist extends BaseFieldDataPersist { public class BooleanDecisionDataPersist extends BaseFieldDataPersist {
@Component(BooleanDecisionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class BooleanDecisionPersistValidator extends BaseFieldDataPersistValidator<BooleanDecisionDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.BooleanDecisionPersistValidator";
private final ValidatorFactory validatorFactory;
protected BooleanDecisionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<BooleanDecisionDataPersist> modelClass() {
return BooleanDecisionDataPersist.class;
}
@Override
protected List<Specification> specifications(BooleanDecisionDataPersist item) {
return getBaseSpecifications(item);
}
}
} }

View File

@ -1,6 +1,37 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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.stereotype.Component;
import java.util.List;
public class CheckBoxDataPersist extends BaseFieldDataPersist { public class CheckBoxDataPersist extends BaseFieldDataPersist {
@Component(CheckBoxDataPersist.CheckBoxDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class CheckBoxDataPersistValidator extends BaseFieldDataPersistValidator<CheckBoxDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.CheckBoxDataPersistValidator";
protected CheckBoxDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<CheckBoxDataPersist> modelClass() {
return CheckBoxDataPersist.class;
}
@Override
protected List<Specification> specifications(CheckBoxDataPersist item) {
return getBaseSpecifications(item);
}
}
} }

View File

@ -1,22 +1,36 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List;
public class ComboBoxOptionPersist { public class ComboBoxOptionPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String label = null; private String label = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}") public static final String _label = "label";
private String value = null; private String value = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}") public static final String _value = "value";
private String source = null; private String source = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}") public static final String _source = "source";
private String uri = null; private String uri = null;
public static final String _uri = "uri";
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -49,5 +63,41 @@ public class ComboBoxOptionPersist {
this.uri = uri; this.uri = uri;
} }
@Component(ComboBoxOptionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ComboBoxOptionPersistValidator extends BaseValidator<ComboBoxOptionPersist> {
public static final String ValidatorName = "DescriptionTemplate.ComboBoxOptionPersistValidator";
private final MessageSource messageSource;
protected ComboBoxOptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<ComboBoxOptionPersist> modelClass() {
return ComboBoxOptionPersist.class;
}
@Override
protected List<Specification> specifications(ComboBoxOptionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(ComboBoxOptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(ComboBoxOptionPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._value}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getSource()))
.failOn(ComboBoxOptionPersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._source}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getUri()))
.failOn(ComboBoxOptionPersist._uri).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._uri}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,15 +1,55 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotNull; 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 DatasetAutoCompleteDataPersist extends BaseFieldDataPersist { public class DatasetAutoCompleteDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
public static final String _multiAutoComplete = "multiAutoComplete";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
public void setMultiAutoComplete(Boolean multiAutoComplete) { public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete; this.multiAutoComplete = multiAutoComplete;
} }
@Component(DatasetAutoCompleteDataPersist.DatasetAutoCompleteDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DatasetAutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator<DatasetAutoCompleteDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.DatasetAutoCompleteDataPersistValidator";
protected DatasetAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<DatasetAutoCompleteDataPersist> modelClass() {
return DatasetAutoCompleteDataPersist.class;
}
@Override
protected List<Specification> specifications(DatasetAutoCompleteDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(DatasetAutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{DatasetAutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
} }

View File

@ -1,4 +1,40 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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.stereotype.Component;
import java.util.List;
public class DatePickerDataPersist extends BaseFieldDataPersist { public class DatePickerDataPersist extends BaseFieldDataPersist {
@Component(DatePickerDataPersist.DatePickerDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DatePickerDataPersistValidator extends BaseFieldDataPersistValidator<DatePickerDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.DatePickerDataPersistValidator";
private final ValidatorFactory validatorFactory;
protected DatePickerDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DatePickerDataPersist> modelClass() {
return DatePickerDataPersist.class;
}
@Override
protected List<Specification> specifications(DatePickerDataPersist item) {
return getBaseSpecifications(item);
}
}
} }

View File

@ -1,16 +1,55 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotNull; 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 DmpAutoCompleteDataPersist extends BaseFieldDataPersist { public class DmpAutoCompleteDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
public static final String _multiAutoComplete = "multiAutoComplete";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
public void setMultiAutoComplete(Boolean multiAutoComplete) { public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete; this.multiAutoComplete = multiAutoComplete;
} }
@Component(DmpAutoCompleteDataPersist.DmpAutoCompleteDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DmpAutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator<DmpAutoCompleteDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.DmpAutoCompleteDataPersistValidator";
protected DmpAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<DmpAutoCompleteDataPersist> modelClass() {
return DmpAutoCompleteDataPersist.class;
}
@Override
protected List<Specification> specifications(DmpAutoCompleteDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(DmpAutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpAutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
} }

View File

@ -1,16 +1,28 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import eu.eudat.commons.enums.FieldDataExternalDatasetType; import eu.eudat.commons.enums.FieldDataExternalDatasetType;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List;
public class ExternalDatasetDataPersist extends BaseFieldDataPersist { public class ExternalDatasetDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
@ValidEnum(message = "{validation.empty}")
public static final String _multiAutoComplete = "multiAutoComplete";
private FieldDataExternalDatasetType type; private FieldDataExternalDatasetType type;
public static final String _type = "type";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
@ -26,4 +38,36 @@ public class ExternalDatasetDataPersist extends BaseFieldDataPersist {
public void setType(FieldDataExternalDatasetType type) { public void setType(FieldDataExternalDatasetType type) {
this.type = type; this.type = type;
} }
@Component(ExternalDatasetDataPersist.ExternalDatasetDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ExternalDatasetDataPersistValidator extends BaseFieldDataPersistValidator<ExternalDatasetDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.ExternalDatasetDataPersistValidator";
protected ExternalDatasetDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<ExternalDatasetDataPersist> modelClass() {
return ExternalDatasetDataPersist.class;
}
@Override
protected List<Specification> specifications(ExternalDatasetDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(ExternalDatasetDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalDatasetDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(ExternalDatasetDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalDatasetDataPersist._type}, LocaleContextHolder.getLocale()))
));
return specifications;
}
}
} }

View File

@ -1,4 +1,36 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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.stereotype.Component;
import java.util.List;
public class FreeTextDataPersist extends BaseFieldDataPersist { public class FreeTextDataPersist extends BaseFieldDataPersist {
@Component(FreeTextDataPersist.FreeTextDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FreeTextDataPersistValidator extends BaseFieldDataPersistValidator<FreeTextDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.FreeTextDataPersistValidator";
protected FreeTextDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<FreeTextDataPersist> modelClass() {
return FreeTextDataPersist.class;
}
@Override
protected List<Specification> specifications(FreeTextDataPersist item) {
return getBaseSpecifications(item);
}
}
} }

View File

@ -1,11 +1,22 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotNull; 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 LicenseDataPersist extends BaseFieldDataPersist { public class LicenseDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
public static final String _multiAutoComplete = "multiAutoComplete";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
@ -14,4 +25,31 @@ public class LicenseDataPersist extends BaseFieldDataPersist {
this.multiAutoComplete = multiAutoComplete; this.multiAutoComplete = multiAutoComplete;
} }
@Component(LicenseDataPersist.LicenseDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class LicenseDataPersistValidator extends BaseFieldDataPersistValidator<LicenseDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.LicenseDataPersistValidator";
protected LicenseDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<LicenseDataPersist> modelClass() {
return LicenseDataPersist.class;
}
@Override
protected List<Specification> specifications(LicenseDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(LicenseDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{LicenseDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
} }

View File

@ -1,11 +1,22 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotNull; 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 OrganizationDataPersist extends BaseFieldDataPersist { public class OrganizationDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete = null; private Boolean multiAutoComplete = null;
public static final String _multiAutoComplete = "multiAutoComplete";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
@ -14,4 +25,31 @@ public class OrganizationDataPersist extends BaseFieldDataPersist {
this.multiAutoComplete = multiAutoComplete; this.multiAutoComplete = multiAutoComplete;
} }
@Component(OrganizationDataPersist.OrganizationDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class OrganizationDataPersistValidator extends BaseFieldDataPersistValidator<OrganizationDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.OrganizationDataPersistValidator";
protected OrganizationDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<OrganizationDataPersist> modelClass() {
return OrganizationDataPersist.class;
}
@Override
protected List<Specification> specifications(OrganizationDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(OrganizationDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{OrganizationDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
} }

View File

@ -1,12 +1,22 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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 jakarta.validation.constraints.NotNull; import java.util.List;
public class PublicationDataPersist extends BaseFieldDataPersist { public class PublicationDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
private Boolean multiAutoComplete; private Boolean multiAutoComplete;
public static final String _multiAutoComplete = "multiAutoComplete";
public Boolean getMultiAutoComplete() { public Boolean getMultiAutoComplete() {
return multiAutoComplete; return multiAutoComplete;
} }
@ -15,4 +25,31 @@ public class PublicationDataPersist extends BaseFieldDataPersist {
this.multiAutoComplete = multiAutoComplete; this.multiAutoComplete = multiAutoComplete;
} }
@Component(PublicationDataPersist.PublicationDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class PublicationDataPersistValidator extends BaseFieldDataPersistValidator<PublicationDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.PublicationDataPersistValidator";
protected PublicationDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<PublicationDataPersist> modelClass() {
return PublicationDataPersist.class;
}
@Override
protected List<Specification> specifications(PublicationDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getMultiAutoComplete()))
.failOn(PublicationDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{PublicationDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
} }

View File

@ -1,16 +1,24 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
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 jakarta.validation.Valid; import java.util.Arrays;
import jakarta.validation.constraints.NotNull;
import java.util.List; import java.util.List;
public class RadioBoxDataPersist extends BaseFieldDataPersist { public class RadioBoxDataPersist extends BaseFieldDataPersist {
@NotNull(message = "{validation.empty}")
@Valid
private List<RadioBoxOptionPersist> options = null; private List<RadioBoxOptionPersist> options = null;
public static final String _options = "options";
public List<RadioBoxOptionPersist> getOptions() { public List<RadioBoxOptionPersist> getOptions() {
return options; return options;
} }
@ -18,4 +26,38 @@ public class RadioBoxDataPersist extends BaseFieldDataPersist {
public void setOptions(List<RadioBoxOptionPersist> options) { public void setOptions(List<RadioBoxOptionPersist> options) {
this.options = options; this.options = options;
} }
@Component(RadioBoxDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class RadioBoxDataPersistValidator extends BaseFieldDataPersistValidator<RadioBoxDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.RadioBoxDataPersistValidator";
private final ValidatorFactory validatorFactory;
protected RadioBoxDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<RadioBoxDataPersist> modelClass() {
return RadioBoxDataPersist.class;
}
@Override
protected List<Specification> specifications(RadioBoxDataPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getOptions()))
.failOn(RadioBoxDataPersist._options).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxDataPersist._options}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getOptions()))
.on(RadioBoxDataPersist._options)
.over(item.getOptions())
.using(() -> this.validatorFactory.validator(RadioBoxOptionPersist.RadioBoxOptionPersistValidator.class))
);
}
}
} }

View File

@ -1,16 +1,28 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; 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.Arrays;
import java.util.List;
public class RadioBoxOptionPersist { public class RadioBoxOptionPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String label = null; private String label = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}") public static final String _label = "label";
private String value = null; private String value = null;
public static final String _value = "value";
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -26,4 +38,36 @@ public class RadioBoxOptionPersist {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
@Component(RadioBoxOptionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class RadioBoxOptionPersistValidator extends BaseValidator<RadioBoxOptionPersist> {
public static final String ValidatorName = "DescriptionTemplate.RadioBoxOptionPersistValidator";
private final MessageSource messageSource;
protected RadioBoxOptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<RadioBoxOptionPersist> modelClass() {
return RadioBoxOptionPersist.class;
}
@Override
protected List<Specification> specifications(RadioBoxOptionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(RadioBoxOptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxOptionPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(RadioBoxOptionPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxOptionPersist._value}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -5,7 +5,6 @@ import eu.eudat.commons.validation.ValidatorFactory;
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.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
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.beans.factory.config.ConfigurableBeanFactory;
@ -64,7 +63,7 @@ public class DefinitionPersist {
.iff(() -> !this.isNull(item.getFields())) .iff(() -> !this.isNull(item.getFields()))
.on(DefinitionPersist._fields) .on(DefinitionPersist._fields)
.over(item.getFields()) .over(item.getFields())
.using(() -> null) //TODO .using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))
); );
} }
} }

View File

@ -1,24 +1,38 @@
package eu.eudat.model.persist.referencedefinition; package eu.eudat.model.persist.referencedefinition;
import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceFieldDataType;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidEnum; 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 eu.eudat.model.persist.DescriptionTemplateTypePersist;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
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;
public class FieldPersist { public class FieldPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code = null; private String code = null;
@ValidEnum(message = "{validation.empty}") public static final String _code = "code";
private ReferenceFieldDataType dataType; private ReferenceFieldDataType dataType;
@NotNull(message = "{validation.empty}") public static final String _dataType = "dataType";
@NotEmpty(message = "{validation.empty}")
private String value = null; private String value = null;
public static final String _value = "value";
public String getCode() { public String getCode() {
return code; return code;
} }
@ -42,6 +56,41 @@ public class FieldPersist {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
@Component(FieldPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FieldPersistValidator extends BaseValidator<FieldPersist> {
public static final String ValidatorName = "Reference.FieldPersistValidator";
private final MessageSource messageSource;
protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<FieldPersist> modelClass() {
return FieldPersist.class;
}
@Override
protected List<Specification> specifications(FieldPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(FieldPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDataType()))
.failOn(FieldPersist._dataType).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dataType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -169,6 +169,7 @@ public class DescriptionController {
@PostMapping("persist-status") @PostMapping("persist-status")
@Transactional @Transactional
@ValidationFilterAnnotation(validator = DescriptionStatusPersist.DescriptionStatusPersistValidator.ValidatorName, argumentName = "model")
public Description persistStatus(@MyValidate @RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { public Description persistStatus(@MyValidate @RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persistStatus(model, fieldSet); Description persisted = this.descriptionService.persistStatus(model, fieldSet);