133 lines
5.2 KiB
Java
133 lines
5.2 KiB
Java
|
package eu.eudat.model.persist;
|
||
|
|
||
|
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||
|
import eu.eudat.commons.validation.BaseValidator;
|
||
|
import eu.eudat.convention.ConventionService;
|
||
|
import eu.eudat.data.DmpBlueprintEntity;
|
||
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||
|
import eu.eudat.model.persist.dmpblueprintdefinition.DefinitionPersist;
|
||
|
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 NewVersionDmpBlueprintPersist {
|
||
|
|
||
|
private UUID id = null;
|
||
|
|
||
|
private String label = null;
|
||
|
|
||
|
public static final String _label = "label";
|
||
|
|
||
|
private DefinitionPersist definition = null;
|
||
|
|
||
|
public static final String _definition = "definition";
|
||
|
|
||
|
private DmpBlueprintStatus status;
|
||
|
|
||
|
public static final String _status = "status";
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
public DefinitionPersist getDefinition() {
|
||
|
return definition;
|
||
|
}
|
||
|
|
||
|
public void setDefinition(DefinitionPersist definition) {
|
||
|
this.definition = definition;
|
||
|
}
|
||
|
|
||
|
public DmpBlueprintStatus getStatus() {
|
||
|
return status;
|
||
|
}
|
||
|
|
||
|
public void setStatus(DmpBlueprintStatus status) {
|
||
|
this.status = status;
|
||
|
}
|
||
|
|
||
|
public String getHash() {
|
||
|
return hash;
|
||
|
}
|
||
|
|
||
|
public void setHash(String hash) {
|
||
|
this.hash = hash;
|
||
|
}
|
||
|
|
||
|
@Component(NewVersionDmpBlueprintPersistValidator.ValidatorName)
|
||
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||
|
public static class NewVersionDmpBlueprintPersistValidator extends BaseValidator<NewVersionDmpBlueprintPersist> {
|
||
|
|
||
|
public static final String ValidatorName = "NewVersionDmpBlueprintPersistValidator";
|
||
|
|
||
|
private final MessageSource messageSource;
|
||
|
|
||
|
private final ValidatorFactory validatorFactory;
|
||
|
|
||
|
public NewVersionDmpBlueprintPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
||
|
super(conventionService, errors);
|
||
|
this.messageSource = messageSource;
|
||
|
this.validatorFactory = validatorFactory;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected Class<NewVersionDmpBlueprintPersist> modelClass() {
|
||
|
return NewVersionDmpBlueprintPersist.class;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected List<Specification> specifications(NewVersionDmpBlueprintPersist item) {
|
||
|
return Arrays.asList(
|
||
|
this.spec()
|
||
|
.iff(() -> this.isValidGuid(item.getId()))
|
||
|
.must(() -> this.isValidHash(item.getHash()))
|
||
|
.failOn(NewVersionDmpBlueprintPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpBlueprintPersist._hash}, LocaleContextHolder.getLocale())),
|
||
|
this.spec()
|
||
|
.must(() -> !this.isEmpty(item.getLabel()))
|
||
|
.failOn(NewVersionDmpBlueprintPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpBlueprintPersist._label}, LocaleContextHolder.getLocale())),
|
||
|
this.spec()
|
||
|
.iff(() -> !this.isEmpty(item.getLabel()))
|
||
|
.must(() -> this.lessEqualLength(item.getLabel(), DmpBlueprintEntity._labelLength))
|
||
|
.failOn(NewVersionDmpBlueprintPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{NewVersionDmpBlueprintPersist._label}, LocaleContextHolder.getLocale())),
|
||
|
this.spec()
|
||
|
.must(() -> !this.isNull(item.getStatus()))
|
||
|
.failOn(NewVersionDmpBlueprintPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpBlueprintPersist._status}, LocaleContextHolder.getLocale())),
|
||
|
|
||
|
this.spec()
|
||
|
.must(() -> !this.isNull(item.getDefinition()))
|
||
|
.failOn(NewVersionDmpBlueprintPersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpBlueprintPersist._definition}, LocaleContextHolder.getLocale())),
|
||
|
this.refSpec()
|
||
|
.iff(() -> !this.isNull(item.getDefinition()))
|
||
|
.on(NewVersionDmpBlueprintPersist._definition)
|
||
|
.over(item.getDefinition())
|
||
|
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class))
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|