argos/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java

106 lines
3.6 KiB
Java

package eu.eudat.model.persist;
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.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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class CloneDmpPersist {
private UUID id = null;
public static final String _id = "id";
private String label = null;
public static final String _label = "label";
private String description = null;
public static final String _description = "description";
private List<UUID> descriptions = new ArrayList<>();
public static final String _descriptions = "descriptions";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<UUID> getDescriptions() {
return descriptions;
}
public void setDescriptions(List<UUID> descriptions) {
this.descriptions = descriptions;
}
@Component(CloneDmpPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class CloneDmpPersistValidator extends BaseValidator<CloneDmpPersist> {
public static final String ValidatorName = "CloneDmpPersistValidator";
private final MessageSource messageSource;
protected CloneDmpPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<CloneDmpPersist> modelClass() {
return CloneDmpPersist.class;
}
@Override
protected List<Specification> specifications(CloneDmpPersist item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getId()))
.failOn(CloneDmpPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(CloneDmpPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getDescription()))
.failOn(CloneDmpPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._description}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDescriptions()))
.failOn(CloneDmpPersist._descriptions).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._descriptions}, LocaleContextHolder.getLocale()))
);
}
}
}