Fixed dataset indexing when finalizing DMPs

This commit is contained in:
George Kalampokis 2020-04-13 16:35:32 +03:00
parent 20466bf693
commit 80a11b2cb3
1 changed files with 36 additions and 6 deletions

View File

@ -1530,6 +1530,23 @@ public class DataManagementPlanManager {
sendNotification(dmp, user, NotificationType.DMP_PUBLISH);
}
private void updateDatasetsIndex(List<Dataset> datasets) {
datasets.forEach(dataset -> {
List<Tag> tags = new ArrayList<>();
eu.eudat.elastic.entities.Dataset elastic = null;
try {
elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
if (elastic != null) {
tags = elastic.getTags();
}
this.datasetManager.updateTags(dataset, tags);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
});
}
public void makeFinalize(UUID id, Principal principal, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception {
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
if (!isUserOwnerOfDmp(dmp, principal))
@ -1539,20 +1556,28 @@ public class DataManagementPlanManager {
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp);
List<Dataset> indexDatasets = new ArrayList<>();
if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList());
finalizedDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.FINALISED.getValue()));
indexDatasets.addAll(finalizedDatasets);
List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (Dataset dataset : dmp.getDataset()) {
if (!dataset.getStatus().equals(Dataset.Status.FINALISED.getValue()) && !datasetsToBeFinalized.getUuids().contains(dataset.getId())) {
datasetsToBeCanceled.add(dataset.getId());
}
}
if (!datasetsToBeCanceled.isEmpty())
if (!datasetsToBeCanceled.isEmpty()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
List<Dataset> cancelledDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList());
cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue()));
indexDatasets.addAll(cancelledDatasets);
}
} else {
List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (Dataset dataset : dmp.getDataset()) {
@ -1560,14 +1585,19 @@ public class DataManagementPlanManager {
datasetsToBeCanceled.add(dataset.getId());
}
}
if (!datasetsToBeCanceled.isEmpty())
if (!datasetsToBeCanceled.isEmpty()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
List<Dataset> cancelledDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList());
cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue()));
indexDatasets.addAll(cancelledDatasets);
}
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
}
this.updateDatasetsIndex(indexDatasets);
}
private boolean isUserOwnerOfDmp(DMP dmp, Principal principal) {