Adding versions on description template query

This commit is contained in:
Thomas Georgios Giannos 2024-02-09 11:45:17 +02:00
parent 174e57f62b
commit 510ec954fa
2 changed files with 123 additions and 57 deletions

View File

@ -6,7 +6,6 @@ import eu.eudat.commons.enums.DescriptionTemplateStatus;
import eu.eudat.commons.enums.DescriptionTemplateVersionStatus; import eu.eudat.commons.enums.DescriptionTemplateVersionStatus;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.DescriptionTemplate;
@ -39,6 +38,8 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
private Collection<IsActive> isActives; private Collection<IsActive> isActives;
private Collection<Short> versions;
private Collection<DescriptionTemplateVersionStatus> versionStatuses; private Collection<DescriptionTemplateVersionStatus> versionStatuses;
private Collection<DescriptionTemplateStatus> statuses; private Collection<DescriptionTemplateStatus> statuses;
@ -116,6 +117,21 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
return this; return this;
} }
public DescriptionTemplateQuery versions(Short value) {
this.versions = List.of(value);
return this;
}
public DescriptionTemplateQuery versions(Short... value) {
this.versions = Arrays.asList(value);
return this;
}
public DescriptionTemplateQuery versions(Collection<Short> values) {
this.versions = values;
return this;
}
public DescriptionTemplateQuery statuses(DescriptionTemplateStatus value) { public DescriptionTemplateQuery statuses(DescriptionTemplateStatus value) {
this.statuses = List.of(value); this.statuses = List.of(value);
return this; return this;
@ -182,8 +198,11 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
} }
private final UserScope userScope; private final UserScope userScope;
private final AuthorizationService authService; private final AuthorizationService authService;
private final QueryUtilsService queryUtilsService; private final QueryUtilsService queryUtilsService;
public DescriptionTemplateQuery( public DescriptionTemplateQuery(
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) { UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
this.userScope = userScope; this.userScope = userScope;
@ -198,20 +217,24 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.typeIds) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.groupIds) ||this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.excludedGroupIds)|| this.isEmpty(this.statuses); return this.isEmpty(this.ids) || this.isEmpty(this.typeIds) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.groupIds) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.excludedGroupIds) || this.isEmpty(this.statuses);
} }
@Override @Override
protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) { protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) {
if (this.authorize.contains(AuthorizationFlags.None)) return null; if (this.authorize.contains(AuthorizationFlags.None))
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionTemplate)) return null; return null;
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionTemplate))
return null;
UUID userId; UUID userId;
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public); boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe(); if (this.authorize.contains(AuthorizationFlags.DmpAssociated))
else userId = null; userId = this.userScope.getUserIdSafe();
else
userId = null;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
if (userId != null || usePublic ) { if (userId != null || usePublic) {
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext) new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)) .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId))
@ -261,13 +284,18 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.versions != null) {
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._version));
for (Short item : this.versions)
inClause.value(item);
predicates.add(inClause);
}
if (this.versionStatuses != null) { if (this.versionStatuses != null) {
CriteriaBuilder.In<DescriptionTemplateVersionStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._versionStatus)); CriteriaBuilder.In<DescriptionTemplateVersionStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._versionStatus));
for (DescriptionTemplateVersionStatus item : this.versionStatuses) for (DescriptionTemplateVersionStatus item : this.versionStatuses)
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.statuses != null) { if (this.statuses != null) {
CriteriaBuilder.In<DescriptionTemplateStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._status)); CriteriaBuilder.In<DescriptionTemplateStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._status));
for (DescriptionTemplateStatus item : this.statuses) for (DescriptionTemplateStatus item : this.statuses)
@ -315,22 +343,38 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
@Override @Override
protected String fieldNameOf(FieldResolver item) { protected String fieldNameOf(FieldResolver item) {
if (item.match(DescriptionTemplate._id)) return DescriptionTemplateEntity._id; if (item.match(DescriptionTemplate._id))
else if (item.match(DescriptionTemplate._label)) return DescriptionTemplateEntity._label; return DescriptionTemplateEntity._id;
else if (item.prefix(DescriptionTemplate._definition)) return DescriptionTemplateEntity._definition; else if (item.match(DescriptionTemplate._label))
else if (item.prefix(DescriptionTemplate._users)) return DescriptionTemplateEntity._id; return DescriptionTemplateEntity._label;
else if (item.match(DescriptionTemplate._description)) return DescriptionTemplateEntity._description; else if (item.prefix(DescriptionTemplate._definition))
else if (item.match(DescriptionTemplate._groupId)) return DescriptionTemplateEntity._groupId; return DescriptionTemplateEntity._definition;
else if (item.match(DescriptionTemplate._version)) return DescriptionTemplateEntity._version; else if (item.prefix(DescriptionTemplate._users))
else if (item.match(DescriptionTemplate._language)) return DescriptionTemplateEntity._language; return DescriptionTemplateEntity._id;
else if (item.prefix(DescriptionTemplate._type)) return DescriptionTemplateEntity._typeId; else if (item.match(DescriptionTemplate._description))
else if (item.match(DescriptionTemplate._createdAt)) return DescriptionTemplateEntity._createdAt; return DescriptionTemplateEntity._description;
else if (item.match(DescriptionTemplate._updatedAt)) return DescriptionTemplateEntity._updatedAt; else if (item.match(DescriptionTemplate._groupId))
else if (item.match(DescriptionTemplate._hash)) return DescriptionTemplateEntity._updatedAt; return DescriptionTemplateEntity._groupId;
else if (item.match(DescriptionTemplate._isActive)) return DescriptionTemplateEntity._isActive; else if (item.match(DescriptionTemplate._version))
else if (item.match(DescriptionTemplate._status)) return DescriptionTemplateEntity._status; return DescriptionTemplateEntity._version;
else if (item.match(DescriptionTemplate._versionStatus)) return DescriptionTemplateEntity._versionStatus; else if (item.match(DescriptionTemplate._language))
else return null; return DescriptionTemplateEntity._language;
else if (item.prefix(DescriptionTemplate._type))
return DescriptionTemplateEntity._typeId;
else if (item.match(DescriptionTemplate._createdAt))
return DescriptionTemplateEntity._createdAt;
else if (item.match(DescriptionTemplate._updatedAt))
return DescriptionTemplateEntity._updatedAt;
else if (item.match(DescriptionTemplate._hash))
return DescriptionTemplateEntity._updatedAt;
else if (item.match(DescriptionTemplate._isActive))
return DescriptionTemplateEntity._isActive;
else if (item.match(DescriptionTemplate._status))
return DescriptionTemplateEntity._status;
else if (item.match(DescriptionTemplate._versionStatus))
return DescriptionTemplateEntity._versionStatus;
else
return null;
} }
} }

View File

@ -7,7 +7,6 @@ import eu.eudat.query.DescriptionTemplateQuery;
import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -16,9 +15,13 @@ public class DescriptionTemplateLookup extends Lookup {
private String like; private String like;
private List<IsActive> isActive; private List<IsActive> isActive;
private List<UUID> groupIds; private List<UUID> groupIds;
private List<Short> versions;
private List<DescriptionTemplateStatus> statuses; private List<DescriptionTemplateStatus> statuses;
private List<DescriptionTemplateVersionStatus> versionStatuses; private List<DescriptionTemplateVersionStatus> versionStatuses;
private List<UUID> ids; private List<UUID> ids;
@ -45,20 +48,20 @@ public class DescriptionTemplateLookup extends Lookup {
this.isActive = isActive; this.isActive = isActive;
} }
public List<UUID> getIds() { public List<UUID> getGroupIds() {
return ids; return groupIds;
} }
public void setIds(List<UUID> ids) { public void setGroupIds(List<UUID> groupIds) {
this.ids = ids; this.groupIds = groupIds;
} }
public List<UUID> getExcludedIds() { public List<Short> getVersions() {
return excludedIds; return versions;
} }
public void setExcludedIds(List<UUID> excludeIds) { public void setVersions(List<Short> versions) {
this.excludedIds = excludeIds; this.versions = versions;
} }
public List<DescriptionTemplateStatus> getStatuses() { public List<DescriptionTemplateStatus> getStatuses() {
@ -69,6 +72,22 @@ public class DescriptionTemplateLookup extends Lookup {
this.statuses = statuses; this.statuses = statuses;
} }
public List<DescriptionTemplateVersionStatus> getVersionStatuses() {
return versionStatuses;
}
public void setVersionStatuses(List<DescriptionTemplateVersionStatus> versionStatuses) {
this.versionStatuses = versionStatuses;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getTypeIds() { public List<UUID> getTypeIds() {
return typeIds; return typeIds;
} }
@ -77,20 +96,12 @@ public class DescriptionTemplateLookup extends Lookup {
this.typeIds = typeIds; this.typeIds = typeIds;
} }
public List<UUID> getGroupIds() { public List<UUID> getExcludedIds() {
return groupIds; return excludedIds;
} }
public void setGroupIds(List<UUID> groupIds) { public void setExcludedIds(List<UUID> excludedIds) {
this.groupIds = groupIds; this.excludedIds = excludedIds;
}
public List<DescriptionTemplateVersionStatus> getVersionStatuses() {
return versionStatuses;
}
public void setVersionStatuses(List<DescriptionTemplateVersionStatus> versionStatuses) {
this.versionStatuses = versionStatuses;
} }
public List<UUID> getExcludedGroupIds() { public List<UUID> getExcludedGroupIds() {
@ -103,15 +114,26 @@ public class DescriptionTemplateLookup extends Lookup {
public DescriptionTemplateQuery enrich(QueryFactory queryFactory) { public DescriptionTemplateQuery enrich(QueryFactory queryFactory) {
DescriptionTemplateQuery query = queryFactory.query(DescriptionTemplateQuery.class); DescriptionTemplateQuery query = queryFactory.query(DescriptionTemplateQuery.class);
if (this.like != null) query.like(this.like); if (this.like != null)
if (this.isActive != null) query.isActive(this.isActive); query.like(this.like);
if (this.groupIds != null) query.groupIds(this.groupIds); if (this.isActive != null)
if (this.statuses != null) query.statuses(this.statuses); query.isActive(this.isActive);
if (this.ids != null) query.ids(this.ids); if (this.groupIds != null)
if (this.excludedIds != null) query.excludedIds(this.excludedIds); query.groupIds(this.groupIds);
if (this.excludedGroupIds != null) query.excludedGroupIds(this.excludedGroupIds); if (this.statuses != null)
if (this.typeIds != null) query.typeIds(this.typeIds); query.statuses(this.statuses);
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.ids != null)
query.ids(this.ids);
if (this.excludedIds != null)
query.excludedIds(this.excludedIds);
if (this.excludedGroupIds != null)
query.excludedGroupIds(this.excludedGroupIds);
if (this.typeIds != null)
query.typeIds(this.typeIds);
if (this.versions != null)
query.versions(this.versions);
if (this.versionStatuses != null)
query.versionStatuses(this.versionStatuses);
this.enrichCommon(query); this.enrichCommon(query);