Solving issues with Annotation persist

This commit is contained in:
Thomas Georgios Giannos 2024-03-08 17:38:03 +02:00
parent f37407063f
commit d844d35392
4 changed files with 14 additions and 40 deletions

View File

@ -21,7 +21,7 @@ public class AnnotationBuilder extends BaseBuilder<Annotation, AnnotationEntity>
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public AnnotationBuilder(ConventionService conventionService, LoggerService logger) {
public AnnotationBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(AnnotationBuilder.class)));
}

View File

@ -18,10 +18,6 @@ import java.util.UUID;
public class AnnotationPersist {
private UUID subjectId;
public static final String _subjectId = "subjectId";
private UUID entityId;
public static final String _entityId = "entityId";
@ -50,18 +46,6 @@ public class AnnotationPersist {
public static final String _protectionType = "protectionType";
private Instant timeStamp;
public static final String _timeStamp = "timeStamp";
public UUID getSubjectId() {
return subjectId;
}
public void setSubjectId(UUID subjectId) {
this.subjectId = subjectId;
}
public UUID getEntityId() {
return entityId;
}
@ -118,14 +102,6 @@ public class AnnotationPersist {
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> {
@ -147,13 +123,6 @@ 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()))
.failOn(AnnotationPersist._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._subjectId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getEntityId()))
.failOn(AnnotationPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._entityId}, LocaleContextHolder.getLocale())),
@ -177,10 +146,7 @@ public class AnnotationPersist {
.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()))
.failOn(AnnotationPersist._protectionType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._protectionType}, LocaleContextHolder.getLocale()))
);
}
}

View File

@ -3,6 +3,7 @@ package gr.cite.annotation.service.annotation;
import gr.cite.annotation.authorization.AuthorizationFlags;
import gr.cite.annotation.authorization.Permission;
import gr.cite.annotation.common.enums.IsActive;
import gr.cite.annotation.common.scope.user.UserScope;
import gr.cite.annotation.data.AnnotationEntity;
import gr.cite.annotation.model.Annotation;
import gr.cite.annotation.model.builder.AnnotationBuilder;
@ -43,15 +44,18 @@ public class AnnotationServiceImpl implements AnnotationService {
private final BuilderFactory builderFactory;
private final UserScope userScope;
public AnnotationServiceImpl(
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
EntityManager entityManager,
BuilderFactory builderFactory) {
BuilderFactory builderFactory, UserScope userScope) {
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.entityManager = entityManager;
this.builderFactory = builderFactory;
this.userScope = userScope;
}
@Override
@ -63,10 +67,15 @@ public class AnnotationServiceImpl implements AnnotationService {
AnnotationEntity data = new AnnotationEntity();
data.setId(UUID.randomUUID());
data.setSubjectId(userScope.getUserIdSafe());
data.setEntityId(model.getEntityId());
data.setEntityType(model.getEntityType());
data.setAnchor(model.getAnchor());
data.setPayload(model.getPayload());
data.setThreadId(model.getThreadId());
data.setParentId(model.getParentId());
data.setProtectionType(model.getProtectionType());
data.setTimeStamp(Instant.now());
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
data.setIsActive(IsActive.Active);

View File

@ -12,16 +12,15 @@ export interface Annotation extends BaseEntity {
author: User;
threadId: Guid;
parent: Annotation;
protection: AnnotationProtectionType;
protectionType: AnnotationProtectionType;
}
export interface AnnotationPersist extends BaseEntityPersist {
subjectId: Guid;
entityId: Guid;
entityType: string;
anchor: string;
payload: string;
threadId?: Guid;
parentId?: Guid;
protection: AnnotationProtectionType;
protectionType: AnnotationProtectionType;
}