Calculating doied datasets and used description templates query

This commit is contained in:
Thomas Georgios Giannos 2024-04-16 13:21:05 +03:00
parent 2e083df185
commit 1b156ca78e
2 changed files with 28 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.query.utils.BuildSubQueryInput;
import eu.eudat.query.utils.QueryUtilsService;
@ -53,6 +54,8 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
private Instant after;
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DescriptionTemplateQuery like(String value) {
@ -200,6 +203,11 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
return this;
}
public DescriptionTemplateQuery dmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery value) {
this.dmpDescriptionTemplateQuery = value;
return this;
}
public DescriptionTemplateQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -327,6 +335,11 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
predicates.add(afterClause);
}
if (this.dmpDescriptionTemplateQuery != null) {
QueryContext<DmpDescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, dmpDescriptionTemplateEntityRoot -> dmpDescriptionTemplateEntityRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._groupId)).value(subQuery.Query));
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);

View File

@ -279,7 +279,15 @@ public class MetricsServiceImpl implements MetricsService {
}
private double calculateDoiedDatasets(boolean forNexus) {
return 0;
DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class).statuses(DescriptionStatus.Finalized).isActive(IsActive.Active);
if (forNexus)
descriptionQuery.createdAfter(_config.getNexusDate());
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active);
EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).types(EntityType.DMP).isActive(IsActive.Active);
dmpQuery.entityDoiSubQuery(entityDoiQuery);
descriptionQuery.dmpSubQuery(dmpQuery);
descriptionQuery.setDistinct(true);
return descriptionQuery.count();
}
private double calculateDraftTemplates(boolean forNexus) {
@ -297,11 +305,13 @@ public class MetricsServiceImpl implements MetricsService {
}
private double calculateUsedTemplates(boolean forNexus) {
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active);
dmpDescriptionTemplateQuery.setDistinct(true);
DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active);
descriptionTemplateQuery.setDistinct(true);
if (forNexus)
dmpDescriptionTemplateQuery.after(_config.getNexusDate());
return dmpDescriptionTemplateQuery.count();
descriptionTemplateQuery.after(_config.getNexusDate());
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class);
descriptionTemplateQuery.dmpDescriptionTemplateSubQuery(dmpDescriptionTemplateQuery);
return descriptionTemplateQuery.count();
}
private double calculateActiveUsers() {