RED-6912- Entries not sorted correctly in the dossier dictionary

- update the sorting to be case-insensitive
- update junit tests
This commit is contained in:
Corina Olariu 2023-06-26 10:27:27 +03:00
parent 37dc9277bd
commit df2739713a
2 changed files with 14 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import static com.iqser.red.keycloak.commons.roles.ActionRoles.WRITE_COLORS;
import static com.iqser.red.service.persistence.management.v1.processor.utils.TypeIdUtils.toTypeId;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -24,6 +25,7 @@ import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import com.amazonaws.util.StringUtils;
import com.iqser.red.service.dictionarymerge.commons.CommonsDictionaryModel;
import com.iqser.red.service.dictionarymerge.commons.DictionaryEntry;
import com.iqser.red.service.dictionarymerge.commons.DictionaryEntryModel;
@ -258,18 +260,23 @@ public class DictionaryService {
DictionaryEntry.class));
return Dictionary.builder()
.entries(dictionaryForType.getEntries().stream().filter(e -> !e.isDeleted()).map(DictionaryEntry::getValue).sorted().collect(Collectors.toList()))
.entries(dictionaryForType.getEntries()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.collect(Collectors.toList()))
.falsePositiveEntries(dictionaryForType.getFalsePositiveEntries()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted()
.sorted(Comparator.comparing(StringUtils::lowerCase))
.collect(Collectors.toList()))
.falseRecommendationEntries(dictionaryForType.getFalseRecommendationEntries()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted()
.sorted(Comparator.comparing(StringUtils::lowerCase))
.collect(Collectors.toList()))
.hexColor(dictionaryForType.getHexColor())
.recommendationHexColor(dictionaryForType.getRecommendationHexColor())

View File

@ -422,7 +422,7 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
assertThat(type.getSkippedHexColor()).isEqualTo("#aaaaaa");
assertThat(type.isDossierDictionaryOnly()).isTrue();
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("word1", "anotherone", "morewords"), false, null, DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Charalampos", "Carina Wilson", "carlsen"), false, null, DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("false_positive1", "false_positive"), false, null, DictionaryEntryType.FALSE_POSITIVE);
dictionaryClient.addEntry(type.getType(),
type.getDossierTemplateId(),
@ -435,9 +435,9 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
var entries = loadedType1.getEntries();
assertThat(entries).hasSize(3);
assertThat(entries.get(0)).isEqualTo("anotherone");
assertThat(entries.get(1)).isEqualTo("morewords");
assertThat(entries.get(2)).isEqualTo("word1");
assertThat(entries.get(0)).isEqualTo("Carina Wilson");
assertThat(entries.get(1)).isEqualTo("carlsen");
assertThat(entries.get(2)).isEqualTo("Charalampos");
assertThat(loadedType1.getFalsePositiveEntries()).hasSize(2);
assertThat(loadedType1.getFalsePositiveEntries().get(0)).isEqualTo("false_positive");
assertThat(loadedType1.getFalsePositiveEntries().get(1)).isEqualTo("false_positive1");