Fixes bug on public dashboard counting non public entities. (Issue #157)
This commit is contained in:
parent
e50875c988
commit
2008986daf
|
@ -8,6 +8,9 @@ import eu.eudat.data.dao.entities.DMPDao;
|
|||
import eu.eudat.data.dao.entities.DatasetDao;
|
||||
import eu.eudat.data.dao.entities.OrganisationDao;
|
||||
import eu.eudat.data.dao.entities.GrantDao;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.Dataset;
|
||||
import eu.eudat.data.entities.Grant;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
|
@ -40,23 +43,26 @@ public class DashBoardManager {
|
|||
public DashBoardStatistics getStatistics() {
|
||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||
|
||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
||||
datasetCriteria.setAllVersions(false);
|
||||
dataManagementPlanCriteria.setAllVersions(false);
|
||||
organisationCriteria.setPublic(false);
|
||||
dataManagementPlanCriteria.setIsPublic(true);
|
||||
organisationCriteria.setPublic(true);
|
||||
|
||||
CompletableFuture dmpFuture = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).countAsync()
|
||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||
CompletableFuture datasetFuture = databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).countAsync()
|
||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||
CompletableFuture grantFuture = databaseRepository.getGrantDao().asQueryable().countAsync()
|
||||
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
||||
CompletableFuture organisationFuture = databaseRepository.getOrganisationDao().getWithCriteria(organisationCriteria).countAsync()
|
||||
.whenComplete((organisationStats, throwable) -> statistics.setTotalOrganisationCount(organisationStats));
|
||||
List<DMP> dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList();
|
||||
long numberOfDatasets = 0;
|
||||
LinkedList<Grant> grants = new LinkedList<>();
|
||||
for (DMP dmp : dmps) {
|
||||
numberOfDatasets = numberOfDatasets + dmp.getDataset().stream()
|
||||
.filter(item -> item.getStatus() == Dataset.Status.FINALISED.getValue()).count();
|
||||
grants.add(dmp.getGrant());
|
||||
}
|
||||
|
||||
statistics.setTotalDataManagementPlanCount((long) dmps.size());
|
||||
statistics.setTotalDataSetCount(numberOfDatasets);
|
||||
statistics.setTotalGrantCount(grants.stream().distinct().count());
|
||||
statistics.setTotalOrganisationCount(databaseRepository.getOrganisationDao().getWithCriteria(organisationCriteria).count());
|
||||
|
||||
CompletableFuture.allOf(dmpFuture, datasetFuture, grantFuture, organisationFuture).join();
|
||||
return statistics;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue