155 lines
5.7 KiB
Java
155 lines
5.7 KiB
Java
package gr.cite.annotation.model.persist;
|
|
|
|
import gr.cite.annotation.common.enums.AnnotationProtectionType;
|
|
import gr.cite.annotation.common.validation.BaseValidator;
|
|
import gr.cite.annotation.convention.ConventionService;
|
|
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
|
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.time.Instant;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
public class AnnotationPersist {
|
|
|
|
private UUID entityId;
|
|
|
|
public static final String _entityId = "entityId";
|
|
|
|
private String entityType;
|
|
|
|
public static final String _entityType = "entityType";
|
|
|
|
private String anchor;
|
|
|
|
public static final String _anchor = "anchor";
|
|
|
|
private String payload;
|
|
|
|
public static final String _payload = "payload";
|
|
|
|
private UUID threadId;
|
|
|
|
public static final String _threadId = "threadId";
|
|
|
|
private UUID parentId;
|
|
|
|
public static final String _parentId = "parentId";
|
|
|
|
private AnnotationProtectionType protectionType;
|
|
|
|
public static final String _protectionType = "protectionType";
|
|
|
|
public UUID getEntityId() {
|
|
return entityId;
|
|
}
|
|
|
|
public void setEntityId(UUID entityId) {
|
|
this.entityId = entityId;
|
|
}
|
|
|
|
public String getEntityType() {
|
|
return entityType;
|
|
}
|
|
|
|
public void setEntityType(String entityType) {
|
|
this.entityType = entityType;
|
|
}
|
|
|
|
public String getAnchor() {
|
|
return anchor;
|
|
}
|
|
|
|
public void setAnchor(String anchor) {
|
|
this.anchor = anchor;
|
|
}
|
|
|
|
public String getPayload() {
|
|
return payload;
|
|
}
|
|
|
|
public void setPayload(String payload) {
|
|
this.payload = payload;
|
|
}
|
|
|
|
public UUID getThreadId() {
|
|
return threadId;
|
|
}
|
|
|
|
public void setThreadId(UUID threadId) {
|
|
this.threadId = threadId;
|
|
}
|
|
|
|
public UUID getParentId() {
|
|
return parentId;
|
|
}
|
|
|
|
public void setParentId(UUID parentId) {
|
|
this.parentId = parentId;
|
|
}
|
|
|
|
public AnnotationProtectionType getProtectionType() {
|
|
return protectionType;
|
|
}
|
|
|
|
public void setProtectionType(AnnotationProtectionType protectionType) {
|
|
this.protectionType = protectionType;
|
|
}
|
|
|
|
@Component(AnnotationPersistValidator.ValidatorName)
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public static class AnnotationPersistValidator extends BaseValidator<AnnotationPersist> {
|
|
|
|
public static final String ValidatorName = "AnnotationIntegrationEventPersistValidator";
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
protected AnnotationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
super(conventionService, errors);
|
|
this.messageSource = messageSource;
|
|
}
|
|
|
|
@Override
|
|
protected Class<AnnotationPersist> modelClass() {
|
|
return AnnotationPersist.class;
|
|
}
|
|
|
|
@Override
|
|
protected List<Specification> specifications(AnnotationPersist item) {
|
|
return Arrays.asList(
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getEntityId()))
|
|
.failOn(AnnotationPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._entityId}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.iff(() -> !this.isNull(item.getEntityId()))
|
|
.must(() -> this.isValidGuid(item.getEntityId()))
|
|
.failOn(AnnotationPersist._entityId).failWith(messageSource.getMessage("validation.invalidid", new Object[]{AnnotationPersist._entityId}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getEntityType()))
|
|
.failOn(AnnotationPersist._entityType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._entityType}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getPayload()))
|
|
.failOn(AnnotationPersist._payload).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._payload}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.iff(() -> !this.isNull(item.getThreadId()))
|
|
.must(() -> this.isValidGuid(item.getThreadId()))
|
|
.failOn(AnnotationPersist._threadId).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{AnnotationPersist._threadId}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.iff(() -> !this.isNull(item.getParentId()))
|
|
.must(() -> this.isValidGuid(item.getParentId()))
|
|
.failOn(AnnotationPersist._parentId).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{AnnotationPersist._parentId}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getProtectionType()))
|
|
.failOn(AnnotationPersist._protectionType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._protectionType}, LocaleContextHolder.getLocale()))
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|