Make dataset queries to return distinct results (avoid duplicate Id issues)

This commit is contained in:
George Kalampokis 2021-11-24 16:23:02 +02:00
parent e546362f58
commit fc71e95cf3
4 changed files with 10 additions and 6 deletions

View File

@ -54,6 +54,7 @@ public class DashBoardController extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
}
@Deprecated
@RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json")
public ResponseEntity<ResponseItem<RecentActivity>> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) {
RecentActivity statistics = dashBoardManager.getRecentActivity(principal, numberOfActivities);

View File

@ -152,7 +152,7 @@ public class DashBoardManager {
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).countAsync()
CompletableFuture datasetFuture = datasetRepository.getAuthenticated( datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().countAsync()
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
CompletableFuture.allOf(dmpFuture, datasetFuture).join();
} else {
@ -168,6 +168,7 @@ public class DashBoardManager {
return statistics;
}
@Deprecated
public RecentActivity getRecentActivity(Principal principal, Integer numberofactivities) {
RecentActivity activity = new RecentActivity();
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
@ -190,7 +191,7 @@ public class DashBoardManager {
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).build())
.whenComplete((dmpActivities, throwable) -> activity.setRecentDmpActivities(dmpActivities));
CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles)
CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct()
.withHint("datasetRecentActivity")
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.take(numberofactivities)
@ -334,6 +335,7 @@ public class DashBoardManager {
List<RecentActivityModel> recentDatasetModels = datasetList
.withHint(HintedModelFactory.getHint(DatasetListingModel.class))
.distinct()
.select(item -> new RecentDatasetModel().fromEntity(item));
recentActivityModels.addAll(recentDatasetModels);
}/*);*/

View File

@ -185,6 +185,7 @@ public class DataManagementPlanManager {
dataTable.setData(dmps1.stream().map(dmp -> {
DatasetCriteria datasetCriteria = new DatasetCriteria();
datasetCriteria.setDmpIds(Collections.singletonList(dmp.getId()));
datasetCriteria.setAllVersions(false);
dmp.setDataset(retrieveRelevantDatasets(datasetCriteria, principalID));
@ -250,14 +251,14 @@ public class DataManagementPlanManager {
roles.add(1);
datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(datasetItems, userInfo, roles);
}
Long maxDatasets = datasetItems.count();
Long maxDatasets = datasetItems.distinct().count();
DatasetTableRequest datasetTableRequest = new DatasetTableRequest();
datasetTableRequest.setOffset(0);
datasetTableRequest.setLength(3);
Set<Dataset> datasetsSet = new LinkedHashSet<>();
try {
datasetItems = PaginationManager.applyPaging(datasetItems, datasetTableRequest);
List<Dataset> datasets = datasetItems.toList();
List<Dataset> datasets = datasetItems.distinct().toList();
datasetsSet.addAll(datasets);
for (int i = 0; i < maxDatasets - datasets.size(); i++) {
Dataset fakedataset = new Dataset();

View File

@ -210,9 +210,9 @@ public class DatasetManager {
DataTableData<DatasetListingModel> dataTable = new DataTableData<>();
dataTable.setData(pagedItems.select(this::mapModel).stream().filter(Objects::nonNull).collect(Collectors.toList()));
dataTable.setData(pagedItems.distinct().select(this::mapModel).stream().filter(Objects::nonNull).collect(Collectors.toList()));
dataTable.setTotalCount(authItems.count());
dataTable.setTotalCount(authItems.distinct().count());
//CompletableFuture.allOf(itemsFuture, countFuture).join();
return dataTable;