Fix dashboard showing incorrect dmp and dataset counts
This commit is contained in:
parent
672055f9ca
commit
7082b958ac
|
@ -15,6 +15,7 @@ import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -36,7 +37,7 @@ public class DashBoardController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
|
||||||
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) {
|
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) throws IOException {
|
||||||
DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal);
|
DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
import eu.eudat.data.dao.criteria.*;
|
||||||
import eu.eudat.data.dao.criteria.DatasetCriteria;
|
|
||||||
import eu.eudat.data.dao.criteria.OrganisationCriteria;
|
|
||||||
import eu.eudat.data.dao.criteria.GrantCriteria;
|
|
||||||
import eu.eudat.data.dao.entities.DMPDao;
|
import eu.eudat.data.dao.entities.DMPDao;
|
||||||
import eu.eudat.data.dao.entities.DatasetDao;
|
import eu.eudat.data.dao.entities.DatasetDao;
|
||||||
import eu.eudat.data.dao.entities.OrganisationDao;
|
import eu.eudat.data.dao.entities.OrganisationDao;
|
||||||
import eu.eudat.data.dao.entities.GrantDao;
|
import eu.eudat.data.dao.entities.GrantDao;
|
||||||
import eu.eudat.data.entities.*;
|
import eu.eudat.data.entities.*;
|
||||||
|
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
|
||||||
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -21,9 +19,12 @@ import eu.eudat.types.searchbar.SearchBarItemType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DashBoardManager {
|
public class DashBoardManager {
|
||||||
|
@ -40,13 +41,25 @@ public class DashBoardManager {
|
||||||
public DashBoardStatistics getStatistics() {
|
public DashBoardStatistics getStatistics() {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
|
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagmentPlanPublicTableRequest publicTableRequest = new DataManagmentPlanPublicTableRequest();
|
||||||
|
|
||||||
|
DataManagementPlanPublicCriteria publicCriteria = new DataManagementPlanPublicCriteria();
|
||||||
|
|
||||||
|
publicCriteria.setAllVersions(false);
|
||||||
|
|
||||||
|
publicTableRequest.setCriteria(publicCriteria);
|
||||||
|
|
||||||
|
publicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable());
|
||||||
|
|
||||||
|
List<DMP> dmps = publicTableRequest.applyCriteria().toList();
|
||||||
|
|
||||||
|
// DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
||||||
dataManagementPlanCriteria.setAllVersions(false);
|
/*dataManagementPlanCriteria.setAllVersions(false);
|
||||||
dataManagementPlanCriteria.setIsPublic(true);
|
dataManagementPlanCriteria.setIsPublic(true);*/
|
||||||
organisationCriteria.setPublic(true);
|
organisationCriteria.setPublic(true);
|
||||||
|
|
||||||
List<DMP> dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList();
|
// List<DMP> dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList();
|
||||||
long numberOfDatasets = 0;
|
long numberOfDatasets = 0;
|
||||||
LinkedList<Grant> grants = new LinkedList<>();
|
LinkedList<Grant> grants = new LinkedList<>();
|
||||||
for (DMP dmp : dmps) {
|
for (DMP dmp : dmps) {
|
||||||
|
@ -63,7 +76,8 @@ public class DashBoardManager {
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DashBoardStatistics getMeStatistics(Principal principal) {
|
public DashBoardStatistics getMeStatistics(Principal principal) throws IOException {
|
||||||
|
List<eu.eudat.elastic.entities.Dataset> datasets = null;
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
||||||
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
||||||
|
@ -72,6 +86,12 @@ public class DashBoardManager {
|
||||||
UserInfo user = new UserInfo();
|
UserInfo user = new UserInfo();
|
||||||
user.setId(principal.getId());
|
user.setId(principal.getId());
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
|
if (apiContext.getOperationsContext().getDatasetRepository() != null) {
|
||||||
|
eu.eudat.elastic.criteria.DatasetCriteria datasetElasticCriteria = new eu.eudat.elastic.criteria.DatasetCriteria();
|
||||||
|
datasetElasticCriteria.setAllowAllVersions(false);
|
||||||
|
datasetElasticCriteria.setPublic(false);
|
||||||
|
datasets = apiContext.getOperationsContext().getDatasetRepository().query(datasetElasticCriteria);
|
||||||
|
}
|
||||||
datasetCriteria.setAllVersions(false);
|
datasetCriteria.setAllVersions(false);
|
||||||
datasetCriteria.setIsPublic(false);
|
datasetCriteria.setIsPublic(false);
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
|
@ -81,7 +101,8 @@ public class DashBoardManager {
|
||||||
List<Integer> roles = new LinkedList<>();
|
List<Integer> roles = new LinkedList<>();
|
||||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
|
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
|
||||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||||
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).countAsync()
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
|
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasets !=null ? datasetRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList()))) : datasetRepository.getWithCriteria(datasetCriteria), user, roles).countAsync()
|
||||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||||
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
|
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
|
||||||
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
||||||
|
|
Loading…
Reference in New Issue