2024-02-22 18:01:23 +01:00
|
|
|
package eu.eudat.model.persist;
|
|
|
|
|
|
|
|
import eu.eudat.commons.validation.BaseValidator;
|
|
|
|
import eu.eudat.convention.ConventionService;
|
|
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
2024-02-23 13:30:05 +01:00
|
|
|
import eu.eudat.model.persist.prefillingsourcedefinition.PrefillingSourceDefinitionPersist;
|
2024-02-22 18:01:23 +01:00
|
|
|
import gr.cite.tools.validation.ValidatorFactory;
|
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
|
|
|
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;
|
|
|
|
|
|
|
|
public class PrefillingSourcePersist {
|
|
|
|
|
|
|
|
private UUID id;
|
|
|
|
|
|
|
|
private String label;
|
|
|
|
|
|
|
|
public static final String _label = "label";
|
|
|
|
|
2024-02-23 13:30:05 +01:00
|
|
|
private PrefillingSourceDefinitionPersist definition;
|
2024-02-22 18:01:23 +01:00
|
|
|
|
|
|
|
public static final String _definition = "definition";
|
|
|
|
|
|
|
|
private String hash;
|
|
|
|
|
|
|
|
public static final String _hash = "hash";
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-02-23 13:30:05 +01:00
|
|
|
public PrefillingSourceDefinitionPersist getDefinition() {
|
2024-02-22 18:01:23 +01:00
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
|
2024-02-23 13:30:05 +01:00
|
|
|
public void setDefinition(PrefillingSourceDefinitionPersist definition) {
|
2024-02-22 18:01:23 +01:00
|
|
|
this.definition = definition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getHash() {
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHash(String hash) {
|
|
|
|
this.hash = hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component(PrefillingSourcePersistValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public static class PrefillingSourcePersistValidator extends BaseValidator<PrefillingSourcePersist> {
|
|
|
|
|
|
|
|
public static final String ValidatorName = "PrefillingSourcePersistValidator";
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
private final ValidatorFactory validatorFactory;
|
|
|
|
|
|
|
|
protected PrefillingSourcePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
|
|
|
super(conventionService, errors);
|
|
|
|
this.messageSource = messageSource;
|
|
|
|
this.validatorFactory = validatorFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<PrefillingSourcePersist> modelClass() {
|
|
|
|
return PrefillingSourcePersist.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(PrefillingSourcePersist item) {
|
|
|
|
return Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> this.isValidGuid(item.getId()))
|
|
|
|
.must(() -> this.isValidHash(item.getHash()))
|
|
|
|
.failOn(PrefillingSourcePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._hash}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> !this.isValidGuid(item.getId()))
|
|
|
|
.must(() -> !this.isValidHash(item.getHash()))
|
|
|
|
.failOn(PrefillingSourcePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getLabel()))
|
2024-02-23 13:30:05 +01:00
|
|
|
.failOn(PrefillingSourcePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._label}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getDefinition()))
|
|
|
|
.failOn(PrefillingSourcePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._definition}, LocaleContextHolder.getLocale())),
|
|
|
|
this.refSpec()
|
|
|
|
.iff(() -> !this.isNull(item.getDefinition()))
|
|
|
|
.on(PrefillingSourcePersist._definition)
|
|
|
|
.over(item.getDefinition())
|
|
|
|
.using(() -> this.validatorFactory.validator(PrefillingSourceDefinitionPersist.PrefillingSourceDefinitionPersistValidator.class))
|
2024-02-22 18:01:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|