Fixes bug on External References not updating values.

This commit is contained in:
gkolokythas 2019-09-20 17:51:13 +03:00
parent 302a22e20a
commit 68cb9846bb
2 changed files with 28 additions and 41 deletions

View File

@ -276,32 +276,25 @@ public class Dataset implements DataEntity<Dataset, UUID> {
@Override
public void update(Dataset entity) {
this.setRegistries(entity.getRegistries());
if (this.getDatasetDataRepositories() == null) this.setDatasetDataRepositories(new HashSet<>());
if (!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())) {
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item -> {
item.setDataset(this);
return item;
}).collect(Collectors.toList()));
}
this.setUri(entity.getUri());
this.setDescription(entity.getDescription());
this.setLabel(entity.getLabel());
this.setProperties(entity.getProperties());
if (this.getDatasetExternalDatasets() == null) this.setDatasetExternalDatasets(new HashSet<>());
if (!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) {
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
if (entity.getDatasetDataRepositories() != null)
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories());
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> {
item.setDataset(this);
return item;
}).collect(Collectors.toList()));
}
if (this.getServices() == null) this.setServices(new HashSet<>());
if(!this.getServices().containsAll(entity.getServices())) {
if (entity.getDatasetExternalDatasets() != null)
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets());
this.setRegistries(entity.getRegistries());
this.getServices().removeAll(this.getServices());
if (entity.getServices() != null)
this.getServices().addAll(entity.getServices());
}
this.setDmp(entity.getDmp());
this.setStatus(entity.getStatus());
this.setProfile(entity.getProfile());

View File

@ -412,41 +412,35 @@ public class DatasetManager {
datasetDataRepository.setDataset(dataset);
dataset.getDatasetDataRepositories().add(datasetDataRepository);
} else {
dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository());
DataRepository dataRepository = dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository());
datasetDataRepository.setDataset(dataset);
datasetDataRepository.setDataRepository(dataRepository);
dataset.getDatasetDataRepositories().add(datasetDataRepository);
}
}
}
}
private void createServicesIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
Set<DatasetService> services = dataset.getServices();
dataset.setServices(new HashSet<>());
if (services != null && !services.isEmpty()) {
for (eu.eudat.data.entities.DatasetService datasetService : services) {
if (dataset.getServices() != null && !dataset.getServices().isEmpty()) {
for (DatasetService service : dataset.getServices()) {
ServiceCriteria criteria = new ServiceCriteria();
criteria.setLike(datasetService.getService().getLabel());
criteria.setLike(service.getService().getLabel());
List<eu.eudat.data.entities.Service> entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList();
if (entries != null && !entries.isEmpty()) {
datasetService.getService().setId(entries.get(0).getId());
datasetService.setDataset(dataset);
dataset.getServices().add(datasetService);
} else {
datasetService.getService().setCreated(new Date());
Service service = databaseRepository.getServiceDao().createOrUpdate(datasetService.getService());
datasetService.setService(service);
datasetService.setDataset(dataset);
dataset.getServices().add(datasetService);
if (entries != null && entries.isEmpty()) {
service.setDataset(dataset);
service.getService().setCreated(new Date());
service.setService(service.getService());
this.databaseRepository.getServiceDao().createOrUpdate(service.getService());
dataset.getServices().add(service);
}
}
}
}
private void createExternalDatasetsIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
Set<DatasetExternalDataset> externalDatasets = dataset.getDatasetExternalDatasets();
dataset.setDatasetExternalDatasets(new HashSet<>());
if (externalDatasets != null && !externalDatasets.isEmpty()) {
for (eu.eudat.data.entities.DatasetExternalDataset datasetExternalDataset : externalDatasets) {
if (dataset.getDatasetExternalDatasets() != null && !dataset.getDatasetExternalDatasets().isEmpty()) {
for (eu.eudat.data.entities.DatasetExternalDataset datasetExternalDataset : dataset.getDatasetExternalDatasets()) {
ExternalDatasetCriteria criteria = new ExternalDatasetCriteria();
criteria.setLike(datasetExternalDataset.getExternalDataset().getLabel());
List<eu.eudat.data.entities.ExternalDataset> entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList();