Adding new columns on Annotation entity

This commit is contained in:
Thomas Georgios Giannos 2024-03-07 13:36:27 +02:00
parent fa97c55862
commit 9d706c6e11
10 changed files with 243 additions and 6 deletions

View File

@ -0,0 +1,30 @@
package gr.cite.annotation.common.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import gr.cite.annotation.data.conventers.DatabaseEnum;
import java.util.Map;
public enum AnnotationProtectionType implements DatabaseEnum<Short> {
Private((short) 0),
EntityAccessors((short) 1);
private final Short value;
AnnotationProtectionType(Short value) {
this.value = value;
}
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, AnnotationProtectionType> map = EnumUtils.getEnumValueMap(AnnotationProtectionType.class);
public static AnnotationProtectionType of(Short i) {
return map.get(i);
}
}

View File

@ -1,6 +1,8 @@
package gr.cite.annotation.data; package gr.cite.annotation.data;
import gr.cite.annotation.common.enums.AnnotationProtectionType;
import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.common.enums.IsActive;
import gr.cite.annotation.data.conventers.AnnotationProtectionTypeConverter;
import gr.cite.annotation.data.conventers.IsActiveConverter; import gr.cite.annotation.data.conventers.IsActiveConverter;
import jakarta.persistence.*; import jakarta.persistence.*;
@ -18,7 +20,7 @@ public class AnnotationEntity {
public static final String _id = "id"; public static final String _id = "id";
@Id @Id
@Column(name = "id", columnDefinition = "uuid", nullable = false) @Column(name = "entity_id", columnDefinition = "uuid", nullable = false)
private UUID entityId; private UUID entityId;
public static final String _entityId = "entityId"; public static final String _entityId = "entityId";
@ -33,12 +35,37 @@ public class AnnotationEntity {
public static final String _anchor = "anchor"; public static final String _anchor = "anchor";
@Id
@Column(name = "payload", nullable = false) @Column(name = "payload", nullable = false)
private String payload; private String payload;
public static final String _payload = "payload"; public static final String _payload = "payload";
@Column(name = "subject_id", columnDefinition = "uuid", nullable = false)
private UUID subjectId;
public static final String _subjectId = "subjectId";
@Column(name = "thread_id", columnDefinition = "uuid", nullable = false)
private UUID threadId;
public static final String _threadId = "threadId";
@Column(name = "parent_id", columnDefinition = "uuid")
private UUID parentId;
public static final String _parentId = "parentId";
@Column(name = "protection_type", nullable = false)
@Convert(converter = AnnotationProtectionTypeConverter.class)
private AnnotationProtectionType protectionType;
public static final String _protectionType = "protectionType";
@Column(name = "time_stamp", nullable = false)
private Instant timeStamp;
public static final String _timeStamp = "timeStamp";
@Column(name = "\"created_at\"", nullable = false) @Column(name = "\"created_at\"", nullable = false)
private Instant createdAt; private Instant createdAt;
@ -95,6 +122,46 @@ public class AnnotationEntity {
this.payload = payload; this.payload = payload;
} }
public UUID getSubjectId() {
return subjectId;
}
public void setSubjectId(UUID subjectId) {
this.subjectId = subjectId;
}
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 Instant getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(Instant timeStamp) {
this.timeStamp = timeStamp;
}
public AnnotationProtectionType getProtectionType() {
return protectionType;
}
public void setProtectionType(AnnotationProtectionType protectionType) {
this.protectionType = protectionType;
}
public Instant getCreatedAt() { public Instant getCreatedAt() {
return createdAt; return createdAt;
} }

View File

@ -0,0 +1,12 @@
package gr.cite.annotation.data.conventers;
import gr.cite.annotation.common.enums.AnnotationProtectionType;
import jakarta.persistence.Converter;
@Converter
public class AnnotationProtectionTypeConverter extends DatabaseEnumConverter<AnnotationProtectionType, Short>{
@Override
protected AnnotationProtectionType of(Short i) {
return AnnotationProtectionType.of(i);
}
}

View File

@ -1,6 +1,10 @@
package gr.cite.annotation.model; package gr.cite.annotation.model;
import gr.cite.annotation.common.enums.AnnotationProtectionType;
import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.common.enums.IsActive;
import gr.cite.annotation.data.conventers.AnnotationProtectionTypeConverter;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@ -27,6 +31,26 @@ public class Annotation {
public static final String _payload = "payload"; public static final String _payload = "payload";
private UUID subjectId;
public static final String _subjectId = "subjectId";
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";
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@ -79,6 +103,46 @@ public class Annotation {
this.payload = payload; this.payload = payload;
} }
public UUID getSubjectId() {
return subjectId;
}
public void setSubjectId(UUID subjectId) {
this.subjectId = subjectId;
}
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;
}
public Instant getCreatedAt() { public Instant getCreatedAt() {
return createdAt; return createdAt;
} }

View File

@ -53,6 +53,16 @@ public class AnnotationBuilder extends BaseBuilder<Annotation, AnnotationEntity>
m.setAnchor(d.getAnchor()); m.setAnchor(d.getAnchor());
if (fields.hasField(this.asIndexer(Annotation._payload))) if (fields.hasField(this.asIndexer(Annotation._payload)))
m.setPayload(d.getPayload()); m.setPayload(d.getPayload());
if (fields.hasField(this.asIndexer(Annotation._subjectId)))
m.setSubjectId(d.getSubjectId());
if (fields.hasField(this.asIndexer(Annotation._threadId)))
m.setThreadId(d.getThreadId());
if (fields.hasField(this.asIndexer(Annotation._parentId)))
m.setParentId(d.getParentId());
if (fields.hasField(this.asIndexer(Annotation._protectionType)))
m.setProtectionType(d.getProtectionType());
if (fields.hasField(this.asIndexer(Annotation._timeStamp)))
m.setTimeStamp(d.getTimeStamp());
if (fields.hasField(this.asIndexer(Annotation._createdAt))) if (fields.hasField(this.asIndexer(Annotation._createdAt)))
m.setCreatedAt(d.getCreatedAt()); m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Annotation._updatedAt))) if (fields.hasField(this.asIndexer(Annotation._updatedAt)))

View File

@ -1,6 +1,7 @@
package gr.cite.annotation.query; package gr.cite.annotation.query;
import gr.cite.annotation.authorization.AuthorizationFlags; import gr.cite.annotation.authorization.AuthorizationFlags;
import gr.cite.annotation.common.enums.AnnotationProtectionType;
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.common.scope.user.UserScope;
import gr.cite.annotation.data.AnnotationEntity; import gr.cite.annotation.data.AnnotationEntity;
@ -37,6 +38,8 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
private Collection<String> anchors; private Collection<String> anchors;
private Collection<UUID> threadIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final UserScope userScope; private final UserScope userScope;
@ -143,6 +146,21 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
return this; return this;
} }
public AnnotationQuery threadIds(UUID value) {
this.threadIds = List.of(value);
return this;
}
public AnnotationQuery threadIds(UUID... value) {
this.threadIds = Arrays.asList(value);
return this;
}
public AnnotationQuery threadIds(Collection<UUID> values) {
this.threadIds = values;
return this;
}
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds); return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds);
@ -199,6 +217,12 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.threadIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(AnnotationEntity._threadId));
for (UUID item : this.threadIds)
inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
@ -220,6 +244,16 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
return AnnotationEntity._anchor; return AnnotationEntity._anchor;
else if (item.match(Annotation._payload)) else if (item.match(Annotation._payload))
return AnnotationEntity._payload; return AnnotationEntity._payload;
else if (item.match(Annotation._subjectId))
return AnnotationEntity._subjectId;
else if (item.match(Annotation._threadId))
return AnnotationEntity._threadId;
else if (item.match(Annotation._parentId))
return AnnotationEntity._parentId;
else if (item.match(Annotation._protectionType))
return AnnotationEntity._protectionType;
else if (item.match(Annotation._timeStamp))
return AnnotationEntity._timeStamp;
else if (item.match(Annotation._createdAt)) else if (item.match(Annotation._createdAt))
return AnnotationEntity._createdAt; return AnnotationEntity._createdAt;
else if (item.match(Annotation._updatedAt)) else if (item.match(Annotation._updatedAt))
@ -239,6 +273,11 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
item.setEntityType(QueryBase.convertSafe(tuple, columns, AnnotationEntity._entityType, String.class)); item.setEntityType(QueryBase.convertSafe(tuple, columns, AnnotationEntity._entityType, String.class));
item.setAnchor(QueryBase.convertSafe(tuple, columns, AnnotationEntity._anchor, String.class)); item.setAnchor(QueryBase.convertSafe(tuple, columns, AnnotationEntity._anchor, String.class));
item.setPayload(QueryBase.convertSafe(tuple, columns, AnnotationEntity._payload, String.class)); item.setPayload(QueryBase.convertSafe(tuple, columns, AnnotationEntity._payload, String.class));
item.setSubjectId(QueryBase.convertSafe(tuple, columns, AnnotationEntity._subjectId, UUID.class));
item.setThreadId(QueryBase.convertSafe(tuple, columns, AnnotationEntity._threadId, UUID.class));
item.setParentId(QueryBase.convertSafe(tuple, columns, AnnotationEntity._parentId, UUID.class));
item.setProtectionType(QueryBase.convertSafe(tuple, columns, AnnotationEntity._protectionType, AnnotationProtectionType.class));
item.setTimeStamp(QueryBase.convertSafe(tuple, columns, AnnotationEntity._timeStamp, Instant.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, AnnotationEntity._createdAt, Instant.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, AnnotationEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, AnnotationEntity._updatedAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, AnnotationEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, AnnotationEntity._isActive, IsActive.class)); item.setIsActive(QueryBase.convertSafe(tuple, columns, AnnotationEntity._isActive, IsActive.class));

View File

@ -24,6 +24,8 @@ public class AnnotationLookup extends Lookup {
private List<String> anchors; private List<String> anchors;
private List<UUID> threadIds;
public String getLike() { public String getLike() {
return like; return like;
} }
@ -80,6 +82,14 @@ public class AnnotationLookup extends Lookup {
this.anchors = anchors; this.anchors = anchors;
} }
public List<UUID> getThreadIds() {
return threadIds;
}
public void setThreadIds(List<UUID> threadIds) {
this.threadIds = threadIds;
}
public AnnotationQuery enrich(QueryFactory queryFactory) { public AnnotationQuery enrich(QueryFactory queryFactory) {
AnnotationQuery query = queryFactory.query(AnnotationQuery.class); AnnotationQuery query = queryFactory.query(AnnotationQuery.class);
if (this.like != null) if (this.like != null)
@ -96,6 +106,8 @@ public class AnnotationLookup extends Lookup {
query.entityTypes(this.entityTypes); query.entityTypes(this.entityTypes);
if (this.anchors != null) if (this.anchors != null)
query.anchors(this.anchors); query.anchors(this.anchors);
if (this.threadIds != null)
query.threadIds(this.threadIds);
this.enrichCommon(query); this.enrichCommon(query);

View File

@ -7,10 +7,11 @@ export class AnnotationLookup extends Lookup implements AnnotationFilter {
like: string; like: string;
ids: Guid[]; ids: Guid[];
excludedIds: Guid[]; excludedIds: Guid[];
isActive: IsActive; isActive: IsActive[];
entityIds: Guid[]; entityIds: Guid[];
entityTypes: string[]; entityTypes: string[];
anchors: string[]; anchors: string[];
groupIds: Guid[];
constructor() { constructor() {
super(); super();
@ -22,8 +23,9 @@ export interface AnnotationFilter {
like: string; like: string;
ids: Guid[]; ids: Guid[];
excludedIds: Guid[]; excludedIds: Guid[];
isActive: IsActive; isActive: IsActive[];
entityIds: Guid[]; entityIds: Guid[];
entityTypes: string[]; entityTypes: string[];
anchors: string[]; anchors: string[];
groupIds: Guid[];
} }

View File

@ -10,7 +10,7 @@ import { catchError } from "rxjs/operators";
@Injectable() @Injectable()
export class AnnotationService { export class AnnotationService {
private get apiBase(): string { return `${this.installationConfiguration.annotationServiceAddress}/annotation`; } private get apiBase(): string { return `${this.installationConfiguration.annotationServiceAddress}annotation`; }
constructor( constructor(
private installationConfiguration: ConfigurationService, private installationConfiguration: ConfigurationService,

View File

@ -27,6 +27,7 @@ export abstract class BaseInterceptor implements HttpInterceptor {
return (req.params instanceof BaseHttpParams && req.params.interceptorContext && Array.isArray(req.params.interceptorContext.interceptAllRequests) && req.params.interceptorContext.interceptAllRequests.includes(this.type)) return (req.params instanceof BaseHttpParams && req.params.interceptorContext && Array.isArray(req.params.interceptorContext.interceptAllRequests) && req.params.interceptorContext.interceptAllRequests.includes(this.type))
|| req.url.startsWith(this.configurationService.server) || req.url.startsWith(this.configurationService.server)
|| req.url.startsWith(this.configurationService.notificationServiceAddress); || req.url.startsWith(this.configurationService.notificationServiceAddress)
|| req.url.startsWith(this.configurationService.annotationServiceAddress);
} }
} }