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.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.model.DescriptionTemplate;
@ -39,6 +38,8 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
private Collection<IsActive> isActives;
private Collection<Short> versions;
private Collection<DescriptionTemplateVersionStatus> versionStatuses;
private Collection<DescriptionTemplateStatus> statuses;
@ -116,6 +117,21 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
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) {
this.statuses = List.of(value);
return this;
@ -182,8 +198,11 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
}
private final UserScope userScope;
private final AuthorizationService authService;
private final QueryUtilsService queryUtilsService;
public DescriptionTemplateQuery(
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
this.userScope = userScope;
@ -198,20 +217,24 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
@Override
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
protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) {
if (this.authorize.contains(AuthorizationFlags.None)) return null;
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionTemplate)) return null;
if (this.authorize.contains(AuthorizationFlags.None))
return null;
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionTemplate))
return null;
UUID userId;
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe();
else userId = null;
if (this.authorize.contains(AuthorizationFlags.DmpAssociated))
userId = this.userScope.getUserIdSafe();
else
userId = null;
List<Predicate> predicates = new ArrayList<>();
if (userId != null || usePublic ) {
if (userId != null || usePublic) {
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId))
@ -261,13 +284,18 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
inClause.value(item);
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) {
CriteriaBuilder.In<DescriptionTemplateVersionStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._versionStatus));
for (DescriptionTemplateVersionStatus item : this.versionStatuses)
inClause.value(item);
predicates.add(inClause);
}
if (this.statuses != null) {
CriteriaBuilder.In<DescriptionTemplateStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._status));
for (DescriptionTemplateStatus item : this.statuses)
@ -315,22 +343,38 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(DescriptionTemplate._id)) return DescriptionTemplateEntity._id;
else if (item.match(DescriptionTemplate._label)) return DescriptionTemplateEntity._label;
else if (item.prefix(DescriptionTemplate._definition)) return DescriptionTemplateEntity._definition;
else if (item.prefix(DescriptionTemplate._users)) return DescriptionTemplateEntity._id;
else if (item.match(DescriptionTemplate._description)) return DescriptionTemplateEntity._description;
else if (item.match(DescriptionTemplate._groupId)) return DescriptionTemplateEntity._groupId;
else if (item.match(DescriptionTemplate._version)) return DescriptionTemplateEntity._version;
else if (item.match(DescriptionTemplate._language)) 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;
if (item.match(DescriptionTemplate._id))
return DescriptionTemplateEntity._id;
else if (item.match(DescriptionTemplate._label))
return DescriptionTemplateEntity._label;
else if (item.prefix(DescriptionTemplate._definition))
return DescriptionTemplateEntity._definition;
else if (item.prefix(DescriptionTemplate._users))
return DescriptionTemplateEntity._id;
else if (item.match(DescriptionTemplate._description))
return DescriptionTemplateEntity._description;
else if (item.match(DescriptionTemplate._groupId))
return DescriptionTemplateEntity._groupId;
else if (item.match(DescriptionTemplate._version))
return DescriptionTemplateEntity._version;
else if (item.match(DescriptionTemplate._language))
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.QueryFactory;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
@ -16,9 +15,13 @@ public class DescriptionTemplateLookup extends Lookup {
private String like;
private List<IsActive> isActive;
private List<UUID> groupIds;
private List<Short> versions;
private List<DescriptionTemplateStatus> statuses;
private List<DescriptionTemplateVersionStatus> versionStatuses;
private List<UUID> ids;
@ -45,20 +48,20 @@ public class DescriptionTemplateLookup extends Lookup {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
public List<UUID> getGroupIds() {
return groupIds;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
public List<UUID> getExcludedIds() {
return excludedIds;
public List<Short> getVersions() {
return versions;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
public void setVersions(List<Short> versions) {
this.versions = versions;
}
public List<DescriptionTemplateStatus> getStatuses() {
@ -69,6 +72,22 @@ public class DescriptionTemplateLookup extends Lookup {
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() {
return typeIds;
}
@ -77,20 +96,12 @@ public class DescriptionTemplateLookup extends Lookup {
this.typeIds = typeIds;
}
public List<UUID> getGroupIds() {
return groupIds;
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
public List<DescriptionTemplateVersionStatus> getVersionStatuses() {
return versionStatuses;
}
public void setVersionStatuses(List<DescriptionTemplateVersionStatus> versionStatuses) {
this.versionStatuses = versionStatuses;
public void setExcludedIds(List<UUID> excludedIds) {
this.excludedIds = excludedIds;
}
public List<UUID> getExcludedGroupIds() {
@ -103,15 +114,26 @@ public class DescriptionTemplateLookup extends Lookup {
public DescriptionTemplateQuery enrich(QueryFactory queryFactory) {
DescriptionTemplateQuery query = queryFactory.query(DescriptionTemplateQuery.class);
if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive);
if (this.groupIds != null) query.groupIds(this.groupIds);
if (this.statuses != null) query.statuses(this.statuses);
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.versionStatuses != null) query.versionStatuses(this.versionStatuses);
if (this.like != null)
query.like(this.like);
if (this.isActive != null)
query.isActive(this.isActive);
if (this.groupIds != null)
query.groupIds(this.groupIds);
if (this.statuses != null)
query.statuses(this.statuses);
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);