cessda / cessda.cvs.two

Apache License 2.0
0 stars 2 forks source link

Fix duplicate language entries in SKOS exports by filtering out versions that are not the latest version #621

Closed matthew-morris-cessda closed 1 year ago

matthew-morris-cessda commented 1 year ago

This PR only targets SKOS exports, it can be generalised to other export types if required.

This commit also removes writing export files to disk, instead directly serving the files from application memory.

This closes #604.

matthew-morris-cessda commented 1 year ago

The functional change in this PR has been provided in this code snippet. The large diff has been caused by changes in the indentation from tabs to spaces.


if (downloadType.equals(ExportService.DownloadType.SKOS)) {
    Map<String, VersionDTO> latestVersionsMap = new LinkedHashMap<>();
    for (VersionDTO versionDTO : includedVersions) {
        latestVersionsMap.merge(versionDTO.getLanguage(), versionDTO,
            // Select the latest version (defined by the lower result from the comparator)
            (r, k) -> VocabularyUtils.versionDtoComparator().compare(r, k) < 0 ? r : k
        );
    }
    includedVersions = new LinkedHashSet<>(latestVersionsMap.values());
}
Joshocan commented 1 year ago

@MartinBobak @Stifo please can you review this code so it can be merged?