107 lines
3.7 KiB
Java
107 lines
3.7 KiB
Java
package eu.eudat.model.persist;
|
|
|
|
import eu.eudat.commons.enums.DmpUserRole;
|
|
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.Arrays;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
public class DmpUserPersist {
|
|
|
|
private UUID user;
|
|
|
|
public static final String _user = "user";
|
|
|
|
private String email;
|
|
public static final String _email = "email";
|
|
|
|
private UUID sectionId;
|
|
public static final String _sectionId = "sectionId";
|
|
|
|
private DmpUserRole role;
|
|
|
|
public static final String _role = "role";
|
|
|
|
public UUID getUser() {
|
|
return user;
|
|
}
|
|
|
|
public void setUser(UUID user) {
|
|
this.user = user;
|
|
}
|
|
|
|
public UUID getSectionId() {
|
|
return sectionId;
|
|
}
|
|
|
|
public void setSectionId(UUID sectionId) {
|
|
this.sectionId = sectionId;
|
|
}
|
|
|
|
public String getEmail() {
|
|
return email;
|
|
}
|
|
|
|
public void setEmail(String email) {
|
|
this.email = email;
|
|
}
|
|
|
|
public DmpUserRole getRole() {
|
|
return role;
|
|
}
|
|
|
|
public void setRole(DmpUserRole role) {
|
|
this.role = role;
|
|
}
|
|
|
|
@Component(DmpUserPersistValidator.ValidatorName)
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public static class DmpUserPersistValidator extends BaseValidator<DmpUserPersist> {
|
|
|
|
public static final String ValidatorName = "DmpUserPersistValidator";
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
protected DmpUserPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
super(conventionService, errors);
|
|
this.messageSource = messageSource;
|
|
}
|
|
|
|
@Override
|
|
protected Class<DmpUserPersist> modelClass() {
|
|
return DmpUserPersist.class;
|
|
}
|
|
|
|
@Override
|
|
protected List<Specification> specifications(DmpUserPersist item) {
|
|
return Arrays.asList(
|
|
this.spec()
|
|
.iff(() -> this.isEmpty(item.getEmail()))
|
|
.must(() -> this.isValidGuid(item.getUser()))
|
|
.failOn(DmpUserPersist._user).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._user}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.iff(() -> !this.isValidGuid(item.getUser()))
|
|
.must(() -> !this.isEmpty(item.getEmail()))
|
|
.failOn(DmpUserPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._email}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getRole()))
|
|
.failOn(DmpUserPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._role}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.iff(() -> !this.isNull(item.getSectionId()))
|
|
.must(() -> this.isValidGuid(item.getSectionId()))
|
|
.failOn(DmpUserPersist._sectionId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._sectionId}, LocaleContextHolder.getLocale()))
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|