|
|
|
@ -47,17 +47,17 @@ import java.util.stream.Stream;
|
|
|
|
|
public class DashBoardManager {
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class);
|
|
|
|
|
|
|
|
|
|
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][] {
|
|
|
|
|
{ "modified", Comparator.comparing(o -> ((RecentActivityModel)o).getModified()).reversed()},
|
|
|
|
|
{ "created", Comparator.comparing(o -> ((RecentActivityModel)o).getCreated()).reversed()},
|
|
|
|
|
{ "label", Comparator.comparing(o -> ((RecentActivityModel)o).getTitle())},
|
|
|
|
|
{ "status", Comparator.comparing(o -> ((RecentActivityModel)o).getStatus()).reversed()},
|
|
|
|
|
{ "finalizedAt", Comparator.comparing(o -> ((RecentActivityModel)o).getFinalizedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()},
|
|
|
|
|
{ "publishedAt", Comparator.comparing(o -> ((RecentActivityModel)o).getPublishedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()}
|
|
|
|
|
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>)data[1]));
|
|
|
|
|
|
|
|
|
|
private ApiContext apiContext;
|
|
|
|
|
private DatabaseRepository databaseRepository;
|
|
|
|
|
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][]{
|
|
|
|
|
{"modified", Comparator.comparing(o -> ((RecentActivityModel) o).getModified()).reversed()},
|
|
|
|
|
{"created", Comparator.comparing(o -> ((RecentActivityModel) o).getCreated()).reversed()},
|
|
|
|
|
{"label", Comparator.comparing(o -> ((RecentActivityModel) o).getTitle())},
|
|
|
|
|
{"status", Comparator.comparing(o -> ((RecentActivityModel) o).getStatus()).reversed()},
|
|
|
|
|
{"finalizedAt", Comparator.comparing(o -> ((RecentActivityModel) o).getFinalizedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()},
|
|
|
|
|
{"publishedAt", Comparator.comparing(o -> ((RecentActivityModel) o).getPublishedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()}
|
|
|
|
|
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>) data[1]));
|
|
|
|
|
|
|
|
|
|
private final ApiContext apiContext;
|
|
|
|
|
private final DatabaseRepository databaseRepository;
|
|
|
|
|
private final DataManagementPlanManager dataManagementPlanManager;
|
|
|
|
|
private final DatasetManager datasetManager;
|
|
|
|
|
|
|
|
|
@ -152,21 +152,14 @@ public class DashBoardManager {
|
|
|
|
|
|
|
|
|
|
List<Integer> roles = new LinkedList<>();
|
|
|
|
|
if ((dmps == null || dmps == 0L) && (datasets == null || datasets == 0L)) {
|
|
|
|
|
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().countAsync()
|
|
|
|
|
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
|
|
|
|
CompletableFuture datasetFuture = datasetRepository.getAuthenticated( datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().countAsync()
|
|
|
|
|
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
|
|
|
|
CompletableFuture.allOf(dmpFuture, datasetFuture).join();
|
|
|
|
|
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().count());
|
|
|
|
|
statistics.setTotalDataSetCount(datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().count());
|
|
|
|
|
} else {
|
|
|
|
|
statistics.setTotalDataManagementPlanCount(dmps);
|
|
|
|
|
statistics.setTotalDataSetCount(datasets);
|
|
|
|
|
}
|
|
|
|
|
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
|
|
|
|
|
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
|
|
|
|
CompletableFuture orgnanisationFuture = organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).countAsync()
|
|
|
|
|
.whenComplete((organisationStats, throwable) -> statistics.setTotalOrganisationCount(organisationStats));
|
|
|
|
|
|
|
|
|
|
CompletableFuture.allOf( grantFuture, orgnanisationFuture).join();
|
|
|
|
|
statistics.setTotalGrantCount(grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).count());
|
|
|
|
|
statistics.setTotalOrganisationCount(organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).count());
|
|
|
|
|
return statistics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|