RED-6744 - Merge dossier and template dictionaries in redaction-service
- reformat - add junit test
This commit is contained in:
parent
9cfbf62bc5
commit
809349f65d
@ -235,11 +235,14 @@ public class DictionaryService {
|
|||||||
var type = dictionaryClient.getDictionaryForType(typeId, fromVersion);
|
var type = dictionaryClient.getDictionaryForType(typeId, fromVersion);
|
||||||
|
|
||||||
Set<DictionaryEntryModel> entries = type.getEntries() != null ? new HashSet<>(type.getEntries().stream().map(DictionaryEntryModel::new).collect(Collectors.toSet())) : new HashSet<>();
|
Set<DictionaryEntryModel> entries = type.getEntries() != null ? new HashSet<>(type.getEntries().stream().map(DictionaryEntryModel::new).collect(Collectors.toSet())) : new HashSet<>();
|
||||||
Set<DictionaryEntryModel> falsePositives = type.getFalsePositiveEntries() != null ? new HashSet<>(type.getFalsePositiveEntries().stream().map(DictionaryEntryModel::new).collect(
|
Set<DictionaryEntryModel> falsePositives = type.getFalsePositiveEntries() != null ? new HashSet<>(type.getFalsePositiveEntries()
|
||||||
Collectors.toSet())) : new HashSet<>();
|
.stream()
|
||||||
Set<DictionaryEntryModel> falseRecommendations = type.getFalseRecommendationEntries() != null ? new HashSet<>(type.getFalseRecommendationEntries().stream().map(
|
.map(DictionaryEntryModel::new)
|
||||||
DictionaryEntryModel::new).collect(
|
.collect(Collectors.toSet())) : new HashSet<>();
|
||||||
Collectors.toSet())) : new HashSet<>();
|
Set<DictionaryEntryModel> falseRecommendations = type.getFalseRecommendationEntries() != null ? new HashSet<>(type.getFalseRecommendationEntries()
|
||||||
|
.stream()
|
||||||
|
.map(DictionaryEntryModel::new)
|
||||||
|
.collect(Collectors.toSet())) : new HashSet<>();
|
||||||
|
|
||||||
if (type.isCaseInsensitive()) {
|
if (type.isCaseInsensitive()) {
|
||||||
entries.forEach(entry -> entry.setValue(entry.getValue().toLowerCase(Locale.ROOT)));
|
entries.forEach(entry -> entry.setValue(entry.getValue().toLowerCase(Locale.ROOT)));
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server;
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@ -18,23 +21,23 @@ import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.FilterType;
|
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.Colors;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.Colors;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntry;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntry;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.Type;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.Type;
|
||||||
import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
|
import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
|
||||||
import com.iqser.red.service.redaction.v1.server.multitenancy.TenantContext;
|
import com.iqser.red.service.redaction.v1.server.multitenancy.TenantContext;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryEntryModel;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryVersion;
|
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryVersion;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.service.DictionaryService;
|
import com.iqser.red.service.redaction.v1.server.redaction.service.DictionaryService;
|
||||||
import com.iqser.red.storage.commons.StorageAutoConfiguration;
|
|
||||||
import com.iqser.red.storage.commons.service.StorageService;
|
import com.iqser.red.storage.commons.service.StorageService;
|
||||||
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@Import(RedactionIntegrationTest.RedactionIntegrationTestConfiguration.class)
|
@Import(RedactionIntegrationTest.RedactionIntegrationTestConfiguration.class)
|
||||||
@ -125,4 +128,99 @@ public class DictionaryServiceTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeDictionaries() {
|
||||||
|
Set<DictionaryEntry> dossierTemplateEntries = new HashSet<>();
|
||||||
|
dossierTemplateEntries.add(new DictionaryEntry(1L, "dossierTemplateValue", 1, false, "typeId"));
|
||||||
|
Set<DictionaryEntry> dossierEntries = new HashSet<>();
|
||||||
|
dossierEntries.add(new DictionaryEntry(1L, "dossierTemplateValue", 1, true, "typeId"));
|
||||||
|
|
||||||
|
Set<DictionaryEntry> result = Sets.intersection(dossierTemplateEntries, dossierEntries);
|
||||||
|
assertThat(result.size()).isZero();
|
||||||
|
|
||||||
|
Set<DictionaryEntryModel> dossierTemplateEntries2 = new HashSet<>();
|
||||||
|
dossierTemplateEntries2.add(new DictionaryEntryModel(1L, "dossierTemplateValue1", 1, false, "typeId"));
|
||||||
|
dossierTemplateEntries2.add(new DictionaryEntryModel(2L, "dossierTemplateValue2", 1, false, "typeId"));
|
||||||
|
dossierTemplateEntries2.add(new DictionaryEntryModel(3L, "dossierTemplateValue3", 1, false, "typeId"));
|
||||||
|
|
||||||
|
Set<DictionaryEntryModel> dossierEntries2 = new HashSet<>();
|
||||||
|
dossierEntries2.add(new DictionaryEntryModel(1L, "dossierTemplateValue1", 1, true, "typeId"));
|
||||||
|
dossierEntries2.add(new DictionaryEntryModel(2L, "dossierTemplateValue2", 1, true, "typeId"));
|
||||||
|
dossierEntries2.add(new DictionaryEntryModel(4L, "dossierTemplateValue4", 1, false, "typeId2"));
|
||||||
|
|
||||||
|
Set<DictionaryEntryModel> mergedResult = new HashSet<>(dossierTemplateEntries2);
|
||||||
|
mergedResult.removeAll(dossierEntries2);
|
||||||
|
mergedResult.addAll(dossierEntries2);
|
||||||
|
assertThat(mergedResult.size()).isEqualTo(4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDictionary() {
|
||||||
|
|
||||||
|
TenantContext.setTenantId("redaction");
|
||||||
|
|
||||||
|
when(dictionaryClient.getVersion(anyString())).thenReturn(0L);
|
||||||
|
when(dictionaryClient.getColors(anyString())).thenReturn(new Colors("dtId",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc",
|
||||||
|
"#cccccc"));
|
||||||
|
|
||||||
|
var type = "type";
|
||||||
|
var dtType = new Type();
|
||||||
|
dtType.setType(type);
|
||||||
|
dtType.setId("type1");
|
||||||
|
dtType.setVersion(1L);
|
||||||
|
dtType.setHexColor("#cccccc");
|
||||||
|
dtType.setHasDictionary(true);
|
||||||
|
dtType.setDossierTemplateId("dtId");
|
||||||
|
List<DictionaryEntry> dossierTemplateEntries = Stream.of("aa", "bb").map(t -> new DictionaryEntry(1, t, 1L, false, "type1")).collect(Collectors.toList());
|
||||||
|
dossierTemplateEntries.add(new DictionaryEntry(1, "cc", 2L, false, "type1"));
|
||||||
|
assertThat(dossierTemplateEntries.size()).isEqualTo(3);
|
||||||
|
dtType.setEntries(dossierTemplateEntries);
|
||||||
|
|
||||||
|
var dossierType = new Type();
|
||||||
|
dossierType.setType(type);
|
||||||
|
dossierType.setId("dossierType");
|
||||||
|
dossierType.setVersion(1L);
|
||||||
|
dossierType.setHexColor("#cccccc");
|
||||||
|
dossierType.setHasDictionary(true);
|
||||||
|
dossierType.setDossierTemplateId("dtId");
|
||||||
|
dossierType.setDossierId("dossierId");
|
||||||
|
List<DictionaryEntry> dossierEntries = Stream.of("aa", "bb").map(t -> new DictionaryEntry(1, t, 2L, true, "dossierType")).collect(Collectors.toList());
|
||||||
|
dossierEntries.add(new DictionaryEntry(1, "dd", 1L, false, "dossierType"));
|
||||||
|
assertThat(dossierEntries.size()).isEqualTo(3);
|
||||||
|
dossierType.setEntries(dossierEntries);
|
||||||
|
|
||||||
|
when(dictionaryClient.getAllTypesForDossierTemplate(anyString(), anyBoolean())).thenReturn(List.of(dtType));
|
||||||
|
when(dictionaryClient.getAllTypesForDossier(anyString(), anyBoolean())).thenReturn(List.of(dossierType));
|
||||||
|
|
||||||
|
when(dictionaryClient.getDictionaryForType("type1", null)).thenReturn(dtType);
|
||||||
|
when(dictionaryClient.getDictionaryForType("dossierType", null)).thenReturn(dossierType);
|
||||||
|
when(dictionaryClient.getDictionaryForType("type1", 0L)).thenReturn(dtType);
|
||||||
|
when(dictionaryClient.getDictionaryForType("dossierType", 0L)).thenReturn(dossierType);
|
||||||
|
|
||||||
|
dictionaryService.updateDictionary("dtId", "dossierId");
|
||||||
|
var dict = dictionaryService.getDeepCopyDictionary("dtId", "dossierId");
|
||||||
|
assertThat(dict.getDictionaryModels().size()).isEqualTo(1);
|
||||||
|
var dictModel = dict.getDictionaryModels().get(0);
|
||||||
|
assertThat(dictModel.getType()).isEqualTo(type);
|
||||||
|
assertThat(dictModel.getEntries().size()).isEqualTo(4);
|
||||||
|
dictModel.getEntries().forEach(entry -> {
|
||||||
|
switch (entry.getValue()) {
|
||||||
|
case "aa", "dd", "bb" -> assertThat(entry.getTypeId()).isEqualTo(dossierType.getTypeId());
|
||||||
|
case "cc" -> assertThat(entry.getTypeId()).isEqualTo(dtType.getTypeId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user