Improve data integrity of recent Activity data retrieval and added elastic support to it
This commit is contained in:
parent
b7b8e0b0e8
commit
9c9db0b646
|
@ -193,6 +193,7 @@ public class DashBoardManager {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) {
|
public List<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) {
|
||||||
|
boolean isAuthenticated = principal.getId() != null;
|
||||||
List<RecentActivityModel> recentActivityModels = new ArrayList<>();
|
List<RecentActivityModel> recentActivityModels = new ArrayList<>();
|
||||||
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
||||||
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
||||||
|
@ -201,26 +202,67 @@ public class DashBoardManager {
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setLike(tableRequest.getCriteria().getLike());
|
datasetCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||||
datasetCriteria.setAllVersions(false);
|
datasetCriteria.setAllVersions(false);
|
||||||
|
datasetCriteria.setIsPublic(!isAuthenticated);
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
dataManagementPlanCriteria.setAllVersions(false);
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
dataManagementPlanCriteria.setLike(tableRequest.getCriteria().getLike());
|
dataManagementPlanCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||||
|
dataManagementPlanCriteria.setIsPublic(!isAuthenticated);
|
||||||
|
dataManagementPlanCriteria.setOnlyPublic(!isAuthenticated);
|
||||||
|
|
||||||
QueryableList<DMP> dmpList;
|
QueryableList<DMP> dmpList;
|
||||||
QueryableList<Dataset> datasetList;
|
QueryableList<Dataset> datasetList;
|
||||||
|
|
||||||
if (principal.getId() != null) {
|
List<eu.eudat.elastic.entities.Dataset> datasets = null;
|
||||||
datasetCriteria.setIsPublic(false);
|
List<eu.eudat.elastic.entities.Dmp> dmps = null;
|
||||||
List<Integer> roles = new LinkedList<>();
|
|
||||||
dmpList = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles);
|
if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository() != null) {
|
||||||
datasetList = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles);
|
try {
|
||||||
|
eu.eudat.elastic.criteria.DatasetCriteria datasetElasticCriteria = new eu.eudat.elastic.criteria.DatasetCriteria();
|
||||||
|
datasetElasticCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||||
|
datasetElasticCriteria.setAllowAllVersions(false);
|
||||||
|
datasetElasticCriteria.setPublic(!isAuthenticated);
|
||||||
|
datasets = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(datasetElasticCriteria);
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.warn(e.getMessage(), e);
|
||||||
|
datasets = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) {
|
||||||
|
try {
|
||||||
|
eu.eudat.elastic.criteria.DmpCriteria dmpElasticCriteria = new eu.eudat.elastic.criteria.DmpCriteria();
|
||||||
|
dmpElasticCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||||
|
dmpElasticCriteria.setAllowAllVersions(false);
|
||||||
|
dmpElasticCriteria.setPublic(!isAuthenticated);
|
||||||
|
dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().query(dmpElasticCriteria);
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.warn(e.getMessage(), e);
|
||||||
|
datasets = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dmps != null) {
|
||||||
|
List<Dmp> finalDmps = dmps;
|
||||||
|
dmpList = dataManagementPlanRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList()))).distinct();
|
||||||
|
} else {
|
||||||
|
dmpList = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria).distinct();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (datasets != null) {
|
||||||
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
|
datasetList = datasetRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
||||||
} else {
|
} else {
|
||||||
dataManagementPlanCriteria.setIsPublic(true);
|
|
||||||
dataManagementPlanCriteria.setOnlyPublic(true);
|
|
||||||
datasetCriteria.setIsPublic(true);
|
|
||||||
dmpList = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria);
|
|
||||||
datasetList = datasetRepository.getWithCriteria(datasetCriteria);
|
datasetList = datasetRepository.getWithCriteria(datasetCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isAuthenticated) {
|
||||||
|
|
||||||
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
dmpList = dataManagementPlanRepository.getAuthenticated(dmpList, principal.getId(), roles);
|
||||||
|
datasetList = datasetRepository.getAuthenticated(datasetList, user, roles);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*CompletableFuture future = CompletableFuture.runAsync(() -> */{
|
/*CompletableFuture future = CompletableFuture.runAsync(() -> */{
|
||||||
recentActivityModels.addAll(dmpList
|
recentActivityModels.addAll(dmpList
|
||||||
.withHint(HintedModelFactory.getHint(RecentDmpModel.class))
|
.withHint(HintedModelFactory.getHint(RecentDmpModel.class))
|
||||||
|
|
Loading…
Reference in New Issue