Solving issues with Annotation persist
This commit is contained in:
parent
f37407063f
commit
d844d35392
|
@ -21,7 +21,7 @@ public class AnnotationBuilder extends BaseBuilder<Annotation, AnnotationEntity>
|
||||||
|
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
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)));
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(AnnotationBuilder.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,6 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class AnnotationPersist {
|
public class AnnotationPersist {
|
||||||
|
|
||||||
private UUID subjectId;
|
|
||||||
|
|
||||||
public static final String _subjectId = "subjectId";
|
|
||||||
|
|
||||||
private UUID entityId;
|
private UUID entityId;
|
||||||
|
|
||||||
public static final String _entityId = "entityId";
|
public static final String _entityId = "entityId";
|
||||||
|
@ -50,18 +46,6 @@ public class AnnotationPersist {
|
||||||
|
|
||||||
public static final String _protectionType = "protectionType";
|
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() {
|
public UUID getEntityId() {
|
||||||
return entityId;
|
return entityId;
|
||||||
}
|
}
|
||||||
|
@ -118,14 +102,6 @@ public class AnnotationPersist {
|
||||||
this.protectionType = protectionType;
|
this.protectionType = protectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Instant getTimeStamp() {
|
|
||||||
return timeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeStamp(Instant timeStamp) {
|
|
||||||
this.timeStamp = timeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component(AnnotationPersistValidator.ValidatorName)
|
@Component(AnnotationPersistValidator.ValidatorName)
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public static class AnnotationPersistValidator extends BaseValidator<AnnotationPersist> {
|
public static class AnnotationPersistValidator extends BaseValidator<AnnotationPersist> {
|
||||||
|
@ -147,13 +123,6 @@ public class AnnotationPersist {
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(AnnotationPersist item) {
|
protected List<Specification> specifications(AnnotationPersist item) {
|
||||||
return Arrays.asList(
|
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()
|
this.spec()
|
||||||
.must(() -> !this.isNull(item.getEntityId()))
|
.must(() -> !this.isNull(item.getEntityId()))
|
||||||
.failOn(AnnotationPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._entityId}, LocaleContextHolder.getLocale())),
|
.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())),
|
.failOn(AnnotationPersist._parentId).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{AnnotationPersist._parentId}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.must(() -> !this.isNull(item.getProtectionType()))
|
.must(() -> !this.isNull(item.getProtectionType()))
|
||||||
.failOn(AnnotationPersist._protectionType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationPersist._protectionType}, LocaleContextHolder.getLocale())),
|
.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()))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gr.cite.annotation.service.annotation;
|
||||||
import gr.cite.annotation.authorization.AuthorizationFlags;
|
import gr.cite.annotation.authorization.AuthorizationFlags;
|
||||||
import gr.cite.annotation.authorization.Permission;
|
import gr.cite.annotation.authorization.Permission;
|
||||||
import gr.cite.annotation.common.enums.IsActive;
|
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.data.AnnotationEntity;
|
||||||
import gr.cite.annotation.model.Annotation;
|
import gr.cite.annotation.model.Annotation;
|
||||||
import gr.cite.annotation.model.builder.AnnotationBuilder;
|
import gr.cite.annotation.model.builder.AnnotationBuilder;
|
||||||
|
@ -43,15 +44,18 @@ public class AnnotationServiceImpl implements AnnotationService {
|
||||||
|
|
||||||
private final BuilderFactory builderFactory;
|
private final BuilderFactory builderFactory;
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
|
||||||
public AnnotationServiceImpl(
|
public AnnotationServiceImpl(
|
||||||
AuthorizationService authorizationService,
|
AuthorizationService authorizationService,
|
||||||
DeleterFactory deleterFactory,
|
DeleterFactory deleterFactory,
|
||||||
EntityManager entityManager,
|
EntityManager entityManager,
|
||||||
BuilderFactory builderFactory) {
|
BuilderFactory builderFactory, UserScope userScope) {
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
|
this.userScope = userScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,10 +67,15 @@ public class AnnotationServiceImpl implements AnnotationService {
|
||||||
|
|
||||||
AnnotationEntity data = new AnnotationEntity();
|
AnnotationEntity data = new AnnotationEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
|
data.setSubjectId(userScope.getUserIdSafe());
|
||||||
data.setEntityId(model.getEntityId());
|
data.setEntityId(model.getEntityId());
|
||||||
data.setEntityType(model.getEntityType());
|
data.setEntityType(model.getEntityType());
|
||||||
data.setAnchor(model.getAnchor());
|
data.setAnchor(model.getAnchor());
|
||||||
data.setPayload(model.getPayload());
|
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.setCreatedAt(Instant.now());
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
data.setIsActive(IsActive.Active);
|
data.setIsActive(IsActive.Active);
|
||||||
|
|
|
@ -12,16 +12,15 @@ export interface Annotation extends BaseEntity {
|
||||||
author: User;
|
author: User;
|
||||||
threadId: Guid;
|
threadId: Guid;
|
||||||
parent: Annotation;
|
parent: Annotation;
|
||||||
protection: AnnotationProtectionType;
|
protectionType: AnnotationProtectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnnotationPersist extends BaseEntityPersist {
|
export interface AnnotationPersist extends BaseEntityPersist {
|
||||||
subjectId: Guid;
|
|
||||||
entityId: Guid;
|
entityId: Guid;
|
||||||
entityType: string;
|
entityType: string;
|
||||||
anchor: string;
|
anchor: string;
|
||||||
payload: string;
|
payload: string;
|
||||||
threadId?: Guid;
|
threadId?: Guid;
|
||||||
parentId?: Guid;
|
parentId?: Guid;
|
||||||
protection: AnnotationProtectionType;
|
protectionType: AnnotationProtectionType;
|
||||||
}
|
}
|
Loading…
Reference in New Issue