145 lines
4.8 KiB
Java
145 lines
4.8 KiB
Java
package eu.eudat.model.persist.dmpblueprintdefinition;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
|
import eu.eudat.commons.validation.BaseValidator;
|
|
import eu.eudat.commons.validation.specification.Specification;
|
|
import eu.eudat.convention.ConventionService;
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
|
import org.springframework.context.MessageSource;
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@JsonTypeInfo(
|
|
use = JsonTypeInfo.Id.NAME,
|
|
include = JsonTypeInfo.As.PROPERTY,
|
|
property = "category",
|
|
visible = true)
|
|
@JsonSubTypes({
|
|
@JsonSubTypes.Type(value = SystemFieldPersist.class, name = "0"),
|
|
@JsonSubTypes.Type(value = ExtraFieldPersist.class, name = "1")
|
|
})
|
|
public abstract class FieldPersist {
|
|
|
|
private UUID id = null;
|
|
|
|
public static final String _id = "id";
|
|
|
|
private DmpBlueprintFieldCategory category;
|
|
|
|
public static final String _category = "category";
|
|
|
|
private String label = null;
|
|
|
|
public static final String _label = "label";
|
|
|
|
private String placeholder = null;
|
|
|
|
public static final String _placeholder = "placeholder";
|
|
|
|
private String description;
|
|
|
|
private Integer ordinal = null;
|
|
|
|
public static final String _ordinal = "ordinal";
|
|
|
|
private Boolean required = null;
|
|
|
|
public static final String _required = "required";
|
|
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public DmpBlueprintFieldCategory getCategory() {
|
|
return category;
|
|
}
|
|
|
|
public void setCategory(DmpBlueprintFieldCategory category) {
|
|
this.category = category;
|
|
}
|
|
|
|
public String getLabel() {
|
|
return label;
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
this.label = label;
|
|
}
|
|
|
|
public String getPlaceholder() {
|
|
return placeholder;
|
|
}
|
|
|
|
public void setPlaceholder(String placeholder) {
|
|
this.placeholder = placeholder;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public Integer getOrdinal() {
|
|
return ordinal;
|
|
}
|
|
|
|
public void setOrdinal(Integer ordinal) {
|
|
this.ordinal = ordinal;
|
|
}
|
|
|
|
public Boolean getRequired() {
|
|
return required;
|
|
}
|
|
|
|
public void setRequired(Boolean required) {
|
|
this.required = required;
|
|
}
|
|
|
|
public abstract static class BaseFieldPersistValidator<T extends FieldPersist> extends BaseValidator<T> {
|
|
|
|
protected final MessageSource messageSource;
|
|
|
|
protected BaseFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
super(conventionService, errors);
|
|
this.messageSource = messageSource;
|
|
}
|
|
|
|
protected List<Specification> getBaseSpecifications(T item) {
|
|
return Arrays.asList(
|
|
this.spec()
|
|
.must(() -> this.isValidGuid(item.getId()))
|
|
.failOn(FieldPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._id}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getCategory()))
|
|
.failOn(FieldPersist._category).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._category}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getLabel()))
|
|
.failOn(FieldPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._label}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getPlaceholder()))
|
|
.failOn(FieldPersist._placeholder).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._placeholder}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getOrdinal()))
|
|
.failOn(FieldPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._ordinal}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getRequired()))
|
|
.failOn(FieldPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._required}, LocaleContextHolder.getLocale()))
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|