Fixes on dmp template metrics queries

This commit is contained in:
Thomas Georgios Giannos 2024-04-18 11:45:25 +03:00
parent ed96403d25
commit 4d363938fc
2 changed files with 23 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
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.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.model.DmpDescriptionTemplate;
@ -41,6 +42,8 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
private Instant after; private Instant after;
private DescriptionTemplateQuery descriptionTemplateQuery;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DmpDescriptionTemplateQuery ids(UUID value) { public DmpDescriptionTemplateQuery ids(UUID value) {
@ -138,6 +141,11 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
return this; return this;
} }
public DmpDescriptionTemplateQuery descriptionTemplateSubQuery(DescriptionTemplateQuery value) {
this.descriptionTemplateQuery = value;
return this;
}
public DmpDescriptionTemplateQuery authorize(EnumSet<AuthorizationFlags> values) { public DmpDescriptionTemplateQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
@ -229,9 +237,13 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
predicates.add(inClause); predicates.add(inClause);
} }
if (this.after != null) { if (this.after != null) {
Predicate afterClause = queryContext.CriteriaBuilder.greaterThanOrEqualTo(queryContext.Root.get(DmpEntity._createdAt), this.after); Predicate afterClause = queryContext.CriteriaBuilder.greaterThanOrEqualTo(queryContext.Root.get(DmpDescriptionTemplateEntity._createdAt), this.after);
predicates.add(afterClause); predicates.add(afterClause);
} }
if (this.descriptionTemplateQuery != null) {
QueryContext<DescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.descriptionTemplateQuery, queryContext, UUID.class, descriptionTemplateEntityRoot -> descriptionTemplateEntityRoot.get(DescriptionTemplateEntity._groupId));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)).value(subQuery.Query));
}
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);

View File

@ -3,11 +3,13 @@ package eu.eudat.service.metrics;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.metrics.MetricLabels; import eu.eudat.commons.metrics.MetricLabels;
import eu.eudat.commons.metrics.MetricNames; import eu.eudat.commons.metrics.MetricNames;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.TenantEntityManager; import eu.eudat.data.TenantEntityManager;
import eu.eudat.query.*; import eu.eudat.query.*;
import eu.eudat.service.keycloak.MyKeycloakAdminRestApi; import eu.eudat.service.keycloak.MyKeycloakAdminRestApi;
import gr.cite.commons.web.keycloak.api.configuration.KeycloakClientProperties; import gr.cite.commons.web.keycloak.api.configuration.KeycloakClientProperties;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import io.micrometer.prometheus.PrometheusMeterRegistry; import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.Gauge; import io.prometheus.client.Gauge;
@ -298,20 +300,20 @@ public class MetricsServiceImpl implements MetricsService {
} }
private double calculateFinalizedTemplates(boolean forNexus) { private double calculateFinalizedTemplates(boolean forNexus) {
DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class).statuses(DescriptionTemplateStatus.Finalized).isActive(IsActive.Active); DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class).statuses(DescriptionTemplateStatus.Finalized).versionStatuses(DescriptionTemplateVersionStatus.Current).isActive(IsActive.Active);
if (forNexus) if (forNexus)
descriptionTemplateQuery.after(_config.getNexusDate()); descriptionTemplateQuery.after(_config.getNexusDate());
return descriptionTemplateQuery.count(); return descriptionTemplateQuery.count();
} }
private double calculateUsedTemplates(boolean forNexus) { private double calculateUsedTemplates(boolean forNexus) {
DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active); DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active);
descriptionTemplateQuery.setDistinct(true); dmpDescriptionTemplateQuery.setDistinct(true);
if (forNexus) if (forNexus) {
descriptionTemplateQuery.after(_config.getNexusDate()); DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).after(_config.getNexusDate());
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class); dmpDescriptionTemplateQuery.descriptionTemplateSubQuery(descriptionTemplateQuery);
descriptionTemplateQuery.dmpDescriptionTemplateSubQuery(dmpDescriptionTemplateQuery); }
return descriptionTemplateQuery.count(); return dmpDescriptionTemplateQuery.collectAs(new BaseFieldSet().ensure(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)).size();
} }
private double calculateActiveUsers() { private double calculateActiveUsers() {