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.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
@ -174,36 +175,31 @@ public class DatasetManager {
|
||||||
uuidList.add(profileId);
|
uuidList.add(profileId);
|
||||||
profileCriteria.setGroupIds(uuidList);
|
profileCriteria.setGroupIds(uuidList);
|
||||||
profileCriteria.setAllVersions(true);
|
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.
|
List<eu.eudat.data.entities.DatasetProfile> profileVersions = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria)
|
||||||
AssociatedProfile associatedProfile = new AssociatedProfile();
|
.orderBy(((builder, root) -> builder.desc(root.get("version"))))
|
||||||
boolean y = true;
|
.toList();
|
||||||
// Start the Dataset Profile List from the latest to the earliest.
|
List<DatasetProfile> profileVersionsIncluded = new LinkedList<>();
|
||||||
for (int x=(items.size()-1); x>=0; x--) {
|
|
||||||
associatedProfile.setId(items.get(x).getId());
|
// Iterate through the versions and remove those that are not included in the DMP of the dataset in question.
|
||||||
// Check if Dmp contains this profile.
|
for(DatasetProfile version : profileVersions) {
|
||||||
for(AssociatedProfile p : dataset.getDmp().getProfiles() ) {
|
for(AssociatedProfile p : dataset.getDmp().getProfiles()){
|
||||||
if (p.getId().toString().equals(associatedProfile.getId().toString())) {
|
if(version.getId().toString().equals(p.getId().toString())) {
|
||||||
Short latestVersion = items.get(x).getVersion();
|
profileVersionsIncluded.add(version);
|
||||||
if (latestVersion.equals(datasetEntity.getProfile().getVersion())) {
|
|
||||||
dataset.setIsProfileLatestVersion(true);
|
|
||||||
y = false;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
dataset.setIsProfileLatestVersion(false);
|
|
||||||
y = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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());
|
dataset.setTags(datasetElastic.getTags());
|
||||||
return dataset;
|
return dataset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue