When new DMP Version is made create also Dataset description index for the new version

This commit is contained in:
George Kalampokis 2020-03-13 12:02:19 +02:00
parent 4ae13704c5
commit 286c5d8900
1 changed files with 34 additions and 10 deletions

View File

@ -17,6 +17,8 @@ import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.elastic.entities.Collaborator;
import eu.eudat.elastic.entities.Organization;
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.exceptions.security.UnauthorisedException;
@ -920,18 +922,40 @@ public class DataManagementPlanManager {
newDataset.setCreated(new Date());
return newDataset;
}).thenApplyAsync(item -> {
futures.add(datasetDao.createOrUpdateAsync(item));
futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> {
eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset();
datasetElastic.setId(dataset1.getId().toString());
datasetElastic.setLabel(dataset1.getLabel());
datasetElastic.setTemplate(dataset1.getProfile().getId());
datasetElastic.setStatus(dataset1.getStatus());
datasetElastic.setDmp(dataset1.getDmp().getId());
datasetElastic.setGroup(dataset1.getDmp().getGroupId());
datasetElastic.setGrant(dataset1.getDmp().getGrant().getId());
if (dataset1.getDmp().getUsers() != null) {
datasetElastic.setCollaborators(dataset1.getDmp().getUsers().stream().map(user -> {
Collaborator collaborator = new Collaborator();
collaborator.setId(user.getId().toString());
// collaborator.setName(user.getUser().getName());
return collaborator;
}).collect(Collectors.toList()));
}
datasetElastic.setLastVersion(true);
if (dataset1.getDmp().getOrganisations() != null) {
datasetElastic.setOrganizations(dataset1.getDmp().getOrganisations().stream().map(org -> {
Organization organization = new Organization();
organization.setId(org.getId().toString());
organization.setName(org.getLabel());
return organization;
}).collect(Collectors.toList()));
}
try {
apiContext.getOperationsContext().getDatasetRepository().createOrUpdate(datasetElastic);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
})));
return futures;
}).join();
DatasetCriteria criteria = new DatasetCriteria();
criteria.setDmpIds(Collections.singletonList(newDmp.getId()));
datasetDao.getWithCriteria(criteria).toList().stream().max(Comparator.comparing(Dataset::getCreated)).ifPresent(dataset1 -> {
try {
datasetManager.updateTags(apiContext.getOperationsContext().getDatasetRepository(), new DatasetWizardModel().fromDataModel(dataset1));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
}
}