Makes the code of Dataset Profile version checking on a Dataset more maintainable. (Ticket #59)
This commit is contained in:
parent
b52225308d
commit
5557111e93
|
@ -55,6 +55,7 @@ import java.nio.file.Paths;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
@ -174,36 +175,31 @@ public class DatasetManager {
|
|||
uuidList.add(profileId);
|
||||
profileCriteria.setGroupIds(uuidList);
|
||||
profileCriteria.setAllVersions(true);
|
||||
List<eu.eudat.data.entities.DatasetProfile> items = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria)
|
||||
.orderBy(((builder, root) -> builder.asc(root.get("version"))))
|
||||
.toList();
|
||||
|
||||
// Search if the Dataset needs dataset Profile update depending on his DMP associated profiles.
|
||||
AssociatedProfile associatedProfile = new AssociatedProfile();
|
||||
boolean y = true;
|
||||
// Start the Dataset Profile List from the latest to the earliest.
|
||||
for (int x=(items.size()-1); x>=0; x--) {
|
||||
associatedProfile.setId(items.get(x).getId());
|
||||
// Check if Dmp contains this profile.
|
||||
for(AssociatedProfile p : dataset.getDmp().getProfiles() ) {
|
||||
if (p.getId().toString().equals(associatedProfile.getId().toString())) {
|
||||
Short latestVersion = items.get(x).getVersion();
|
||||
if (latestVersion.equals(datasetEntity.getProfile().getVersion())) {
|
||||
dataset.setIsProfileLatestVersion(true);
|
||||
y = false;
|
||||
break;
|
||||
} else {
|
||||
dataset.setIsProfileLatestVersion(false);
|
||||
y = false;
|
||||
break;
|
||||
}
|
||||
List<eu.eudat.data.entities.DatasetProfile> profileVersions = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria)
|
||||
.orderBy(((builder, root) -> builder.desc(root.get("version"))))
|
||||
.toList();
|
||||
List<DatasetProfile> profileVersionsIncluded = new LinkedList<>();
|
||||
|
||||
// Iterate through the versions and remove those that are not included in the DMP of the dataset in question.
|
||||
for(DatasetProfile version : profileVersions) {
|
||||
for(AssociatedProfile p : dataset.getDmp().getProfiles()){
|
||||
if(version.getId().toString().equals(p.getId().toString())) {
|
||||
profileVersionsIncluded.add(version);
|
||||
}
|
||||
}
|
||||
if (!y){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the list with the included Versions.
|
||||
Stream<DatasetProfile> sorted = profileVersionsIncluded.stream().sorted(Comparator.comparing(DatasetProfile::getVersion).reversed());
|
||||
|
||||
// Make the Stream into List and get the first item.
|
||||
DatasetProfile profile = sorted.collect(Collectors.toList()).iterator().next();
|
||||
|
||||
// Check if the dataset is on the latest Version.
|
||||
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
|
||||
dataset.setIsProfileLatestVersion(latestVersion);
|
||||
|
||||
dataset.setTags(datasetElastic.getTags());
|
||||
return dataset;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue