2021-04-09 18:05:04 +02:00
package eu.eudat.logic.managers ;
2023-10-27 17:46:34 +02:00
import eu.eudat.commons.enums.DescriptionTemplateStatus ;
2023-11-07 13:53:36 +01:00
import eu.eudat.commons.enums.IsActive ;
2021-06-29 13:33:57 +02:00
import eu.eudat.data.dao.criteria.* ;
2023-10-27 17:46:34 +02:00
import eu.eudat.data.DescriptionTemplateEntity ;
2021-06-29 13:33:57 +02:00
import eu.eudat.logic.services.ApiContext ;
2023-11-07 13:53:36 +01:00
import eu.eudat.query.DmpDescriptionTemplateQuery ;
2021-10-13 16:49:32 +02:00
import eu.eudat.types.MetricNames ;
2023-11-07 13:53:36 +01:00
import gr.cite.tools.data.query.QueryFactory ;
2021-06-29 13:33:57 +02:00
import io.micrometer.prometheus.PrometheusMeterRegistry ;
2021-04-09 18:05:04 +02:00
import io.prometheus.client.Gauge ;
2021-04-12 11:00:07 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2021-04-09 18:05:04 +02:00
import org.springframework.beans.factory.annotation.Autowired ;
2021-04-12 11:00:07 +02:00
import org.springframework.core.env.Environment ;
import org.springframework.scheduling.annotation.Scheduled ;
2021-04-09 18:05:04 +02:00
import org.springframework.stereotype.Component ;
2023-10-03 16:29:45 +02:00
import jakarta.annotation.PostConstruct ;
import jakarta.transaction.Transactional ;
2023-10-18 17:52:03 +02:00
import javax.management.InvalidApplicationException ;
2021-04-12 11:00:07 +02:00
import java.io.IOException ;
2021-11-09 12:05:38 +01:00
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.time.LocalDate ;
import java.time.ZoneId ;
2022-07-28 10:23:39 +02:00
import java.util.* ;
2021-04-09 18:05:04 +02:00
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
@Component
public class MetricsManager {
2021-04-12 11:00:07 +02:00
private final static Logger logger = LoggerFactory . getLogger ( MetricsManager . class ) ;
2021-06-29 13:33:57 +02:00
private final Map < String , Gauge > gauges ;
2021-04-15 17:30:16 +02:00
2022-01-27 10:05:40 +01:00
public static final Map < Short , String > datasetTemplateStatus = Stream . of ( new Object [ ] [ ] {
2023-10-27 17:46:34 +02:00
{ DescriptionTemplateStatus . Draft . getValue ( ) , MetricNames . DRAFT } ,
{ DescriptionTemplateStatus . Finalized . getValue ( ) , MetricNames . ACTIVE } ,
2022-01-27 10:05:40 +01:00
} ) . collect ( Collectors . toMap ( data - > ( Short ) data [ 0 ] , data - > ( String ) data [ 1 ] ) ) ;
2021-06-29 13:33:57 +02:00
public void increaseValue ( String name , int amount , String label ) {
2021-04-15 17:30:16 +02:00
if ( label ! = null ) {
gauges . get ( name ) . labels ( label ) . inc ( amount ) ;
} else {
gauges . get ( name ) . inc ( amount ) ;
}
2021-04-09 18:05:04 +02:00
}
2021-06-29 13:33:57 +02:00
public void decreaseValue ( String name , int amount , String label ) {
2021-04-15 17:30:16 +02:00
if ( label ! = null ) {
gauges . get ( name ) . labels ( label ) . dec ( amount ) ;
} else {
gauges . get ( name ) . dec ( amount ) ;
}
2021-04-09 18:05:04 +02:00
}
2021-06-29 13:33:57 +02:00
public Integer getValue ( String name , String label ) {
2021-04-15 17:30:16 +02:00
if ( label ! = null ) {
return Double . valueOf ( gauges . get ( name ) . labels ( label ) . get ( ) ) . intValue ( ) ;
} else {
return Double . valueOf ( gauges . get ( name ) . get ( ) ) . intValue ( ) ;
}
2021-04-09 18:05:04 +02:00
}
2021-06-29 13:33:57 +02:00
public void calculateValue ( String name , int amount , String label ) {
2021-04-15 17:30:16 +02:00
Integer orig = getValue ( name , label ) ;
2021-04-09 18:05:04 +02:00
int diff = orig - amount ;
if ( diff ! = 0 ) {
if ( diff > 0 ) {
2021-04-15 17:30:16 +02:00
decreaseValue ( name , diff , label ) ;
2021-04-09 18:05:04 +02:00
} else {
2021-04-15 17:30:16 +02:00
increaseValue ( name , Math . abs ( diff ) , label ) ;
2021-04-09 18:05:04 +02:00
}
}
}
2021-06-29 13:33:57 +02:00
private final ApiContext apiContext ;
2021-04-12 11:00:07 +02:00
private final UserManager userManager ;
private final Environment environment ;
2023-11-07 13:53:36 +01:00
private final QueryFactory queryFactory ;
2021-04-09 18:05:04 +02:00
@Autowired
2023-11-07 13:53:36 +01:00
public MetricsManager ( ApiContext apiContext , UserManager userManager , Environment environment , PrometheusMeterRegistry registry , QueryFactory queryFactory ) {
2021-06-29 13:33:57 +02:00
this . apiContext = apiContext ;
2021-04-12 11:00:07 +02:00
this . userManager = userManager ;
this . environment = environment ;
2023-11-07 13:53:36 +01:00
this . queryFactory = queryFactory ;
2021-06-29 13:33:57 +02:00
registry . clear ( ) ;
this . gauges = Stream . of ( new Object [ ] [ ] {
2021-10-13 16:49:32 +02:00
{ MetricNames . DMP , Gauge . build ( ) . name ( MetricNames . DMP ) . help ( " Number of managed DMPs " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-11-09 12:05:38 +01:00
{ MetricNames . NEXUS + MetricNames . DMP , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . DMP ) . help ( " Number of managed DMPs during Nexus " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-10-13 16:49:32 +02:00
{ MetricNames . FUNDERS , Gauge . build ( ) . name ( MetricNames . FUNDERS ) . help ( " Number of registered Funders " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . GRANTS , Gauge . build ( ) . name ( MetricNames . GRANTS ) . help ( " Number of registered Grants " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . PROJECT , Gauge . build ( ) . name ( MetricNames . PROJECT ) . help ( " Number of registered Projects " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . RESEARCHER , Gauge . build ( ) . name ( MetricNames . RESEARCHER ) . help ( " Number of Colaborators/Researchers " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-11-09 12:05:38 +01:00
{ MetricNames . NEXUS + MetricNames . FUNDERS , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . FUNDERS ) . help ( " Number of registered Funders during Nexus " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . NEXUS + MetricNames . GRANTS , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . GRANTS ) . help ( " Number of registered Grants during Nexus " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . NEXUS + MetricNames . PROJECT , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . PROJECT ) . help ( " Number of registered Projects during Nexus " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . NEXUS + MetricNames . RESEARCHER , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . RESEARCHER ) . help ( " Number of Colaborators/Researchers during Nexus " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-10-13 16:49:32 +02:00
{ MetricNames . DATASET , Gauge . build ( ) . name ( MetricNames . DATASET ) . help ( " Number of managed Dataset Descriptions " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-11-09 12:05:38 +01:00
{ MetricNames . NEXUS + MetricNames . DATASET , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . DATASET ) . help ( " Number of managed Dataset Descriptions during Nexus " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-10-13 16:49:32 +02:00
{ MetricNames . DATASET_TEMPLATE , Gauge . build ( ) . name ( MetricNames . DATASET_TEMPLATE ) . help ( " Number of dataset Templates " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-11-09 12:05:38 +01:00
{ MetricNames . NEXUS + MetricNames . DATASET_TEMPLATE , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . DATASET_TEMPLATE ) . help ( " Number of dataset Templates during Nexus " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-10-13 16:49:32 +02:00
{ MetricNames . USERS , Gauge . build ( ) . name ( MetricNames . USERS ) . help ( " Number of users " ) . labelNames ( " type " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-10-13 16:49:32 +02:00
{ MetricNames . LANGUAGES , Gauge . build ( ) . name ( MetricNames . LANGUAGES ) . help ( " Number of Languages " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
2021-11-09 12:05:38 +01:00
{ MetricNames . DMP_WITH_GRANT , Gauge . build ( ) . name ( MetricNames . DMP_WITH_GRANT ) . help ( " Number of Grants based on the status of the DMP that is using them " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-12-07 15:52:49 +01:00
{ MetricNames . NEXUS + MetricNames . DMP_WITH_GRANT , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . DMP_WITH_GRANT ) . help ( " Number of Grants based on the status of the DMP that is using them during Nexus " ) . labelNames ( " status " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-10-20 11:42:08 +02:00
2021-12-06 14:32:38 +01:00
{ MetricNames . INSTALLATIONS , Gauge . build ( ) . name ( MetricNames . INSTALLATIONS ) . help ( " Number of Installations " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
{ MetricNames . NEXUS + MetricNames . INSTALLATIONS , Gauge . build ( ) . name ( MetricNames . NEXUS + MetricNames . INSTALLATIONS ) . help ( " Number of Installations " ) . register ( registry . getPrometheusRegistry ( ) ) } ,
2021-06-29 13:33:57 +02:00
} ) . collect ( Collectors . toMap ( data - > ( String ) data [ 0 ] , data - > ( Gauge ) data [ 1 ] ) ) ;
2021-04-09 18:05:04 +02:00
}
@PostConstruct
@Transactional
2021-04-12 11:00:07 +02:00
@Scheduled ( initialDelay = 1000 * 60 * 60 , fixedDelay = 1000 * 60 * 60 )
2023-10-18 17:52:03 +02:00
public void init ( ) throws IOException , InvalidApplicationException {
2021-04-12 11:00:07 +02:00
logger . info ( " Start calculating Metrics " ) ;
2023-11-07 09:02:09 +01:00
// calculateValue(MetricNames.DMP, (int) countAllDraftDMPs(), MetricNames.DRAFT);
// calculateValue(MetricNames.DMP, (int) countAllFinalizedDMPs(), MetricNames.FINALIZED);
// calculateValue(MetricNames.DMP, (int) countAllPublishedDMPs(), MetricNames.PUBLISHED);
// calculateValue(MetricNames.DMP, (int) countAllDoiedDMPs(), MetricNames.DOIED);
//
// calculateValue(MetricNames.NEXUS + MetricNames.DMP, (int) countAllDraftDMPs(true), MetricNames.DRAFT);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP, (int) countAllFinalizedDMPs(true), MetricNames.FINALIZED);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP, (int) countAllPublishedDMPs(true), MetricNames.PUBLISHED);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP, (int) countAllDoiedDMPs(true), MetricNames.DOIED);
//
// calculateValue(MetricNames.DMP_WITH_GRANT, (int) countAllDraftDMPsWithGrantId(), MetricNames.DRAFT);
// calculateValue(MetricNames.DMP_WITH_GRANT, (int) countAllFinalizedDMPsWithGrantId(), MetricNames.FINALIZED);
// calculateValue(MetricNames.DMP_WITH_GRANT, (int) countAllPublishedDMPsWithGrantId(), MetricNames.PUBLISHED);
// calculateValue(MetricNames.DMP_WITH_GRANT, (int) countAllDoiedDMPsWithGrantId(), MetricNames.DOIED);
//
// calculateValue(MetricNames.NEXUS + MetricNames.DMP_WITH_GRANT, (int) countAllDraftDMPsWithGrantId(true), MetricNames.DRAFT);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP_WITH_GRANT, (int) countAllFinalizedDMPsWithGrantId(true), MetricNames.FINALIZED);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP_WITH_GRANT, (int) countAllPublishedDMPsWithGrantId(true), MetricNames.PUBLISHED);
// calculateValue(MetricNames.NEXUS + MetricNames.DMP_WITH_GRANT, (int) countAllDoiedDMPsWithGrantId(true), MetricNames.DOIED);
//
// calculateValue(MetricNames.FUNDERS, (int) countAllFunders(), null);
// calculateValue(MetricNames.GRANTS, (int) countAllGrants(), null);
// calculateValue(MetricNames.PROJECT, (int) countAllProjects(), null);
// calculateValue(MetricNames.RESEARCHER, (int) countAllResearchers(), null);
//
// calculateValue(MetricNames.NEXUS + MetricNames.FUNDERS, (int) countAllFunders(true), null);
// calculateValue(MetricNames.NEXUS + MetricNames.GRANTS, (int) countAllGrants(true), null);
// calculateValue(MetricNames.NEXUS + MetricNames.PROJECT, (int) countAllProjects(true), null);
// calculateValue(MetricNames.NEXUS + MetricNames.RESEARCHER, (int) countAllResearchers(true), null);
//
// calculateValue(MetricNames.DATASET, (int) countAllDraftDatasets(), MetricNames.DRAFT);
// calculateValue(MetricNames.DATASET, (int) countAllFinalizedDatasets(), MetricNames.FINALIZED);
// calculateValue(MetricNames.DATASET, (int) countAllPublicDatasets(), MetricNames.PUBLISHED);
// calculateValue(MetricNames.DATASET, (int) countAllDatasetsWithDoi(), MetricNames.DOIED);
//
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET, (int) countAllDraftDatasets(true), MetricNames.DRAFT);
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET, (int) countAllFinalizedDatasets(true), MetricNames.FINALIZED);
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET, (int) countAllPublicDatasets(true), MetricNames.PUBLISHED);
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET, (int) countAllDatasetsWithDoi(true), MetricNames.DOIED);
//
// calculateValue(MetricNames.DATASET_TEMPLATE, (int) countAllDraftTemplates(), MetricNames.DRAFT);
// calculateValue(MetricNames.DATASET_TEMPLATE, (int) countAllFinalizedTemplates(), MetricNames.ACTIVE);
// calculateValue(MetricNames.DATASET_TEMPLATE, (int) countAllUsedTemplates(), MetricNames.USED);
//
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET_TEMPLATE, (int) countAllDraftTemplates(true), MetricNames.DRAFT);
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET_TEMPLATE, (int) countAllFinalizedTemplates(true), MetricNames.ACTIVE);
// calculateValue(MetricNames.NEXUS + MetricNames.DATASET_TEMPLATE, (int) countAllUsedTemplates(true), MetricNames.USED);
//
// calculateValue(MetricNames.USERS, (int) userManager.countActiveUsers().intValue(), MetricNames.LOGGEDIN);
// calculateValue(MetricNames.USERS, (int) userManager.countAllUsers().intValue(), MetricNames.TOTAL);
//
// try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
// long files = paths.count();
// calculateValue(MetricNames.LANGUAGES, (int) files, null);
// } catch (Exception e) {
// logger.error("Could not calculate languages.");
// }
//
// calculateValue(MetricNames.INSTALLATIONS, 1, null);
// calculateValue(MetricNames.NEXUS + MetricNames.INSTALLATIONS, 1, null);
2021-12-06 14:32:38 +01:00
2021-04-12 11:00:07 +02:00
logger . info ( " Metrics calculation Completed " ) ;
2021-04-09 18:05:04 +02:00
}
2021-11-09 12:05:38 +01:00
private Date getNexusDate ( ) {
try {
return new SimpleDateFormat ( " yyyy-MM-dd " ) . parse ( " 2021-01-01 " ) ;
} catch ( ParseException e ) {
logger . error ( e . getLocalizedMessage ( ) , e ) ;
}
return Date . from ( LocalDate . of ( 2021 , 1 , 1 ) . atStartOfDay ( ZoneId . systemDefault ( ) ) . toInstant ( ) ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDraftDMPs ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDraftDMPs ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDraftDMPs ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setStatus ( 0 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllFinalizedDMPs ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllFinalizedDMPs ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllFinalizedDMPs ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setStatus ( 1 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllPublishedDMPs ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllPublishedDMPs ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllPublishedDMPs ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setIsPublic ( true ) ;
criteria . setOnlyPublic ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDoiedDMPs ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDoiedDMPs ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDoiedDMPs ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setHasDoi ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDraftDMPsWithGrantId ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDraftDMPsWithGrantId ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDraftDMPsWithGrantId ( boolean countNexus ) throws InvalidApplicationException {
2021-10-20 11:42:08 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setStatus ( 0 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-10-20 11:42:08 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . groupBy ( ( builder , root ) - > root . get ( " grant " ) ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllFinalizedDMPsWithGrantId ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllFinalizedDMPsWithGrantId ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllFinalizedDMPsWithGrantId ( boolean countNexus ) throws InvalidApplicationException {
2021-10-20 11:42:08 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setStatus ( 1 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-10-20 11:42:08 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . groupBy ( ( builder , root ) - > root . get ( " grant " ) ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllPublishedDMPsWithGrantId ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllPublishedDMPsWithGrantId ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllPublishedDMPsWithGrantId ( boolean countNexus ) throws InvalidApplicationException {
2021-10-20 11:42:08 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setIsPublic ( true ) ;
criteria . setOnlyPublic ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-10-20 11:42:08 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . groupBy ( ( builder , root ) - > root . get ( " grant " ) ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDoiedDMPsWithGrantId ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDoiedDMPsWithGrantId ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllDoiedDMPsWithGrantId ( boolean countNexus ) throws InvalidApplicationException {
2021-10-20 11:42:08 +02:00
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria ( ) ;
criteria . setHasDoi ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-10-20 11:42:08 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . getWithCriteria ( criteria ) . groupBy ( ( builder , root ) - > root . get ( " grant " ) ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllResearchers ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllResearchers ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllResearchers ( boolean countNexus ) throws InvalidApplicationException {
2024-01-04 11:55:42 +01:00
// ResearcherCriteria criteria = new ResearcherCriteria();
// if (countNexus) criteria.setPeriodStart(getNexusDate());
// return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(criteria).count();
return 0 ;
2021-06-29 13:33:57 +02:00
}
2023-10-18 17:52:03 +02:00
private long countAllProjects ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllProjects ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllProjects ( boolean countNexus ) throws InvalidApplicationException {
2024-01-04 11:55:42 +01:00
// ProjectCriteria criteria = new ProjectCriteria();
// if (countNexus) criteria.setPeriodStart(getNexusDate());
// return apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(criteria).count();
return 0 ;
2021-06-29 13:33:57 +02:00
}
2023-10-18 17:52:03 +02:00
private long countAllFunders ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllFunders ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllFunders ( boolean countNexus ) throws InvalidApplicationException {
2024-01-04 11:55:42 +01:00
// FunderCriteria criteria = new FunderCriteria();
// if (countNexus) criteria.setPeriodStart(getNexusDate());
// return apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(criteria).count();
return 0 ;
2021-06-29 13:33:57 +02:00
}
2023-10-18 17:52:03 +02:00
private long countAllGrants ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllGrants ( false ) ;
}
2023-10-18 17:52:03 +02:00
private long countAllGrants ( boolean countNexus ) throws InvalidApplicationException {
2024-01-04 11:55:42 +01:00
// GrantCriteria criteria = new GrantCriteria();
// if (countNexus) criteria.setPeriodStart(getNexusDate());
// return apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).count();
return 0 ;
2021-06-29 13:33:57 +02:00
}
2023-10-18 17:52:03 +02:00
public long countAllDraftDatasets ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDraftDatasets ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllDraftDatasets ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
eu . eudat . data . dao . criteria . DatasetCriteria criteria = new eu . eudat . data . dao . criteria . DatasetCriteria ( ) ;
criteria . setStatus ( 0 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllFinalizedDatasets ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllFinalizedDatasets ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllFinalizedDatasets ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
eu . eudat . data . dao . criteria . DatasetCriteria criteria = new eu . eudat . data . dao . criteria . DatasetCriteria ( ) ;
criteria . setStatus ( 1 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllPublicDatasets ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllPublicDatasets ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllPublicDatasets ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
eu . eudat . data . dao . criteria . DatasetCriteria criteria = new eu . eudat . data . dao . criteria . DatasetCriteria ( ) ;
criteria . setIsPublic ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllDatasetsWithDoi ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDatasetsWithDoi ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllDatasetsWithDoi ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
eu . eudat . data . dao . criteria . DatasetCriteria criteria = new eu . eudat . data . dao . criteria . DatasetCriteria ( ) ;
criteria . setHasDoi ( true ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllDraftTemplates ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllDraftTemplates ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllDraftTemplates ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DatasetProfileCriteria criteria = new DatasetProfileCriteria ( ) ;
criteria . setStatus ( 0 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetProfileDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllFinalizedTemplates ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllFinalizedTemplates ( false ) ;
}
2023-10-18 17:52:03 +02:00
public long countAllFinalizedTemplates ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DatasetProfileCriteria criteria = new DatasetProfileCriteria ( ) ;
criteria . setStatus ( 1 ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2021-06-29 13:33:57 +02:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetProfileDao ( ) . getWithCriteria ( criteria ) . count ( ) ;
}
@Transactional
2023-10-18 17:52:03 +02:00
public long countAllUsedTemplates ( ) throws InvalidApplicationException {
2021-11-09 12:05:38 +01:00
return countAllUsedTemplates ( false ) ;
}
@Transactional
2023-10-18 17:52:03 +02:00
public long countAllUsedTemplates ( boolean countNexus ) throws InvalidApplicationException {
2021-06-29 13:33:57 +02:00
DatasetProfileCriteria criteria = new DatasetProfileCriteria ( ) ;
criteria . setStatus ( 1 ) ;
criteria . setAllVersions ( false ) ;
2021-11-09 12:05:38 +01:00
if ( countNexus ) criteria . setPeriodStart ( getNexusDate ( ) ) ;
2023-10-27 17:46:34 +02:00
List < DescriptionTemplateEntity > descriptionTemplateEntities = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetProfileDao ( ) . getWithCriteria ( criteria ) . withFields ( Collections . singletonList ( " id " ) ) . toList ( ) ;
2022-02-18 16:51:57 +01:00
DatasetCriteria datasetCriteria = new DatasetCriteria ( ) ;
2023-10-27 17:46:34 +02:00
datasetCriteria . setDatasetTemplates ( descriptionTemplateEntities . stream ( ) . map ( DescriptionTemplateEntity : : getId ) . collect ( Collectors . toList ( ) ) ) ;
2023-11-24 11:39:26 +01:00
return apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . getWithCriteria ( datasetCriteria ) . select ( root - > root . getDescriptionTemplateId ( ) ) . stream ( ) . distinct ( ) . count ( ) ;
2021-06-29 13:33:57 +02:00
}
2021-04-09 18:05:04 +02:00
}