2023-12-08 17:05:48 +01:00
|
|
|
package eu.eudat.model.persist;
|
|
|
|
|
|
|
|
import eu.eudat.commons.enums.LockTargetType;
|
2024-01-03 15:45:57 +01:00
|
|
|
import eu.eudat.commons.validation.BaseValidator;
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
2024-01-03 15:45:57 +01:00
|
|
|
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;
|
2023-12-08 17:05:48 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class LockPersist {
|
|
|
|
|
|
|
|
private UUID id;
|
|
|
|
|
|
|
|
private UUID target;
|
|
|
|
|
2024-01-03 15:45:57 +01:00
|
|
|
public static final String _target = "target";
|
|
|
|
|
2023-12-08 17:05:48 +01:00
|
|
|
private LockTargetType targetType;
|
|
|
|
|
2024-01-03 15:45:57 +01:00
|
|
|
public static final String _targetType = "targetType";
|
|
|
|
|
2023-12-08 17:05:48 +01:00
|
|
|
private UUID lockedBy;
|
|
|
|
|
2024-01-03 15:45:57 +01:00
|
|
|
public static final String _lockedBy = "lockedBy";
|
2023-12-08 17:05:48 +01:00
|
|
|
|
|
|
|
private String hash;
|
|
|
|
|
|
|
|
public static final String _hash = "hash";
|
|
|
|
|
|
|
|
public UUID getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId(UUID id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UUID getTarget() {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTarget(UUID target) {
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LockTargetType getTargetType() {
|
|
|
|
return targetType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTargetType(LockTargetType targetType) {
|
|
|
|
this.targetType = targetType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UUID getLockedBy() {
|
|
|
|
return lockedBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLockedBy(UUID lockedBy) {
|
|
|
|
this.lockedBy = lockedBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getHash() {
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHash(String hash) {
|
|
|
|
this.hash = hash;
|
|
|
|
}
|
2024-01-03 15:45:57 +01:00
|
|
|
|
|
|
|
@Component(LockPersistValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public static class LockPersistValidator extends BaseValidator<LockPersist> {
|
|
|
|
|
|
|
|
public static final String ValidatorName = "LockPersistValidator";
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
protected LockPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
|
|
super(conventionService, errors);
|
|
|
|
this.messageSource = messageSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<LockPersist> modelClass() {
|
|
|
|
return LockPersist.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(LockPersist item) {
|
|
|
|
return Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> this.isValidGuid(item.getId()))
|
|
|
|
.must(() -> this.isValidHash(item.getHash()))
|
|
|
|
.failOn(LockPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._hash}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> !this.isValidGuid(item.getId()))
|
|
|
|
.must(() -> !this.isValidHash(item.getHash()))
|
|
|
|
.failOn(LockPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> this.isValidGuid(item.getTarget()))
|
|
|
|
.failOn(LockPersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._target}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getTargetType()))
|
|
|
|
.failOn(LockPersist._targetType).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._targetType}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> this.isValidGuid(item.getLockedBy()))
|
|
|
|
.failOn(LockPersist._lockedBy).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._lockedBy}, LocaleContextHolder.getLocale()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 17:05:48 +01:00
|
|
|
}
|
2024-03-19 16:21:50 +01:00
|
|
|
|