Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2023-12-04 17:56:35 +02:00
commit 84726a250f
4 changed files with 37 additions and 8 deletions

View File

@ -10,6 +10,8 @@ import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.model.Description; import eu.eudat.model.Description;
import eu.eudat.model.Dmp;
import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.model.PublicDescription; import eu.eudat.model.PublicDescription;
import eu.eudat.query.utils.BuildSubQueryInput; import eu.eudat.query.utils.BuildSubQueryInput;
import eu.eudat.query.utils.QueryUtilsService; import eu.eudat.query.utils.QueryUtilsService;
@ -255,13 +257,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
predicates.add(inClause); predicates.add(inClause);
} }
if (this.dmpDescriptionTemplateQuery != null) { if (this.dmpDescriptionTemplateQuery != null) {
Subquery<DmpDescriptionTemplateEntity> subQuery = queryContext.Query.subquery(this.dmpDescriptionTemplateQuery.entityClass()); QueryContext<DmpDescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, DmpDescriptionTemplate._id);
this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext.CriteriaBuilder, subQuery);
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery)); predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery));
} }
if (this.dmpQuery != null) { if (this.dmpQuery != null) {
Subquery<DmpEntity> subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass()); QueryContext<DmpEntity, UUID> subQuery = this.applySubQuery(this.dmpQuery, queryContext, UUID.class, Dmp._id);
this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery);
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(subQuery)); predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(subQuery));
} }
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {

View File

@ -7,21 +7,24 @@ import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.DmpVersionStatus; import eu.eudat.commons.enums.DmpVersionStatus;
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.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.model.PublicDmp; import eu.eudat.model.PublicDmp;
import eu.eudat.query.utils.QueryUtilsService; import eu.eudat.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.*; import gr.cite.tools.data.query.*;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.*;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.function.Function;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -43,6 +46,8 @@ public class DmpQuery extends QueryBase<DmpEntity> {
private Collection<UUID> groupIds; private Collection<UUID> groupIds;
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final UserScope userScope; private final UserScope userScope;
@ -180,6 +185,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
return this; return this;
} }
public DmpQuery dmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery subQuery) {
this.dmpDescriptionTemplateQuery = subQuery;
return this;
}
public DmpQuery authorize(EnumSet<AuthorizationFlags> values) { public DmpQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
@ -187,7 +197,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses); return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses)|| this.isFalseQuery(this.dmpDescriptionTemplateQuery);
} }
@Override @Override
@ -276,6 +286,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.dmpDescriptionTemplateQuery != null) {
QueryContext<DmpDescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, DmpDescriptionTemplate._dmp);
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery));
}
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray); return queryContext.CriteriaBuilder.and(predicatesArray);

View File

@ -6,6 +6,7 @@ import eu.eudat.commons.enums.DmpVersionStatus;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.elastic.query.DmpElasticQuery; import eu.eudat.elastic.query.DmpElasticQuery;
import eu.eudat.elastic.query.InnerObjectDmpElasticQuery; import eu.eudat.elastic.query.InnerObjectDmpElasticQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
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;
@ -29,6 +30,8 @@ public class DmpLookup extends Lookup {
private List<Integer> versions; private List<Integer> versions;
private DmpDescriptionTemplateQuery dmpDescriptionTemplateSubQuery;
public String getLike() { public String getLike() {
return like; return like;
} }
@ -93,6 +96,14 @@ public class DmpLookup extends Lookup {
this.versionStatuses = versionStatuses; this.versionStatuses = versionStatuses;
} }
public DmpDescriptionTemplateQuery getDmpDescriptionTemplateSubQuery() {
return dmpDescriptionTemplateSubQuery;
}
public void setDmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery dmpDescriptionTemplateSubQuery) {
this.dmpDescriptionTemplateSubQuery = dmpDescriptionTemplateSubQuery;
}
public DmpQuery enrich(QueryFactory queryFactory) { public DmpQuery enrich(QueryFactory queryFactory) {
DmpQuery query = queryFactory.query(DmpQuery.class); DmpQuery query = queryFactory.query(DmpQuery.class);
if (this.like != null) query.like(this.like); if (this.like != null) query.like(this.like);
@ -103,6 +114,7 @@ public class DmpLookup extends Lookup {
if (this.statuses != null) query.statuses(this.statuses); if (this.statuses != null) query.statuses(this.statuses);
if (this.versions != null) query.versions(this.versions); if (this.versions != null) query.versions(this.versions);
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery);
this.enrichCommon(query); this.enrichCommon(query);
@ -118,6 +130,7 @@ public class DmpLookup extends Lookup {
if (this.statuses != null) query.statuses(this.statuses); if (this.statuses != null) query.statuses(this.statuses);
if (this.versions != null) query.versions(this.versions); if (this.versions != null) query.versions(this.versions);
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
this.enrichCommon(query); this.enrichCommon(query);
@ -133,6 +146,7 @@ public class DmpLookup extends Lookup {
if (this.statuses != null) query.statuses(this.statuses); if (this.statuses != null) query.statuses(this.statuses);
if (this.versions != null) query.versions(this.versions); if (this.versions != null) query.versions(this.versions);
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
return query; return query;
} }

View File

@ -315,7 +315,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>data-tools</artifactId> <artifactId>data-tools</artifactId>
<version>2.1.0</version> <version>2.1.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>