Updating Annotation persist and validator

This commit is contained in:
Thomas Georgios Giannos 2024-03-07 14:22:29 +02:00
parent 50dd06b3f1
commit 8141d40ecf
2 changed files with 70 additions and 3 deletions

View File

@ -45,7 +45,7 @@ public class AnnotationEntity {
public static final String _subjectId = "subjectId";
@Column(name = "thread_id", columnDefinition = "uuid", nullable = false)
@Column(name = "thread_id", columnDefinition = "uuid")
private UUID threadId;
public static final String _threadId = "threadId";

View File

@ -1,5 +1,6 @@
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;
@ -10,6 +11,7 @@ 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;
@ -36,6 +38,22 @@ public class AnnotationPersist {
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";
private Instant timeStamp;
public static final String _timeStamp = "timeStamp";
public UUID getSubjectId() {
return subjectId;
}
@ -76,6 +94,38 @@ public class AnnotationPersist {
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;
}
public Instant getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(Instant timeStamp) {
this.timeStamp = timeStamp;
}
@Component(AnnotationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class AnnotationPersistValidator extends BaseValidator<AnnotationPersist> {
@ -97,6 +147,9 @@ public class AnnotationPersist {
@Override
protected List<Specification> specifications(AnnotationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getSubjectId()))
.failOn(AnnotationPersist._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._subjectId}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getSubjectId()))
.must(() -> this.isValidGuid(item.getSubjectId()))
@ -107,13 +160,27 @@ public class AnnotationPersist {
this.spec()
.iff(() -> !this.isNull(item.getEntityId()))
.must(() -> this.isValidGuid(item.getEntityId()))
.failOn(AnnotationPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._entityId}, LocaleContextHolder.getLocale())),
.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()))
.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())),
this.spec()
.must(() -> !this.isNull(item.getTimeStamp()))
.failOn(AnnotationPersist._timeStamp).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._timeStamp}, LocaleContextHolder.getLocale()))
);
}
}