154 lines
4.8 KiB
Java
154 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 gr.cite.tools.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.ArrayList;
|
|
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"),
|
|
@JsonSubTypes.Type(value = ReferenceTypeFieldPersist.class, name = "2")
|
|
})
|
|
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 List<String> semantics = null;
|
|
public final static String _semantics = "semantics";
|
|
|
|
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 List<String> getSemantics() {
|
|
return semantics;
|
|
}
|
|
|
|
public void setSemantics(List<String> semantics) {
|
|
this.semantics = semantics;
|
|
}
|
|
|
|
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) {
|
|
List<Specification> specifications = new ArrayList<>();
|
|
specifications.addAll( 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.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()))
|
|
));
|
|
return specifications;
|
|
}
|
|
|
|
}
|
|
|
|
}
|