RED-6216- Allow add-to-dict for expressions consisting of less than 2 characters

- remove limitation of at least 2 characters for expression
- add to stopwords all ascii printable characters (lower case)
This commit is contained in:
devplant 2023-03-21 15:02:11 +02:00
parent 112a27561b
commit c0b01d202b
3 changed files with 84 additions and 6 deletions

View File

@ -11,7 +11,6 @@ import lombok.experimental.UtilityClass;
public class DictionaryValidator {
public final String EMPTY_MSG = "%s is empty.";
public final String MIN_LENGTH_MSG = "%s should contain at least 2 letters.";
public final String COLOR_VALUE_MSG = "Invalid HEX color";
public final String BOOLEAN_MSG = "Boolean value for %s not set.";
@ -27,10 +26,8 @@ public class DictionaryValidator {
if (StringUtils.isBlank(value)) {
return Optional.of(String.format(EMPTY_MSG, valueType.name()));
}
// no need to test the length of the value (at least 1 character is acceptable for non-latin words
if (value.strip().length() < 2) {
return Optional.of(String.format(MIN_LENGTH_MSG, valueType.name()));
}
return Optional.empty();
}

View File

@ -664,4 +664,46 @@ yourself
yourselves
you've
z
zero
zero
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
[
\
]
^
_
`
{
|
}
~

View File

@ -100,6 +100,45 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
}
}
@Test
public void testAddEntriesWithStopWord2() {
var dossier = dossierTesterAndProvider.provideTestDossier();
var typeId = "dossier_redaction";
var entries = new ArrayList<String>();
entries.add("age");
entries.add("p");
try {
dictionaryClient.addEntry(typeId, dossier.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
} catch (FeignException e) {
assertThat(e.status()).isEqualTo(400);
}
entries.remove(1);
entries.add("5");
try {
dictionaryClient.addEntry(typeId, dossier.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
} catch (FeignException e) {
assertThat(e.status()).isEqualTo(400);
}
entries.remove(1);
entries.add("12");
try {
dictionaryClient.addEntry(typeId, dossier.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
} catch (FeignException e) {
assertThat(e.status()).isEqualTo(400);
}
entries.remove(1);
entries.add(";");
try {
dictionaryClient.addEntry(typeId, dossier.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
} catch (FeignException e) {
assertThat(e.status()).isEqualTo(400);
}
entries.add("");
dictionaryClient.addEntry(typeId, dossier.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
}
@Test
public void testAddWordMultipleTimes() {
@ -278,7 +317,7 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
dictionaryClient.deleteType(createdType.getType(), createdType.getDossierTemplateId(),null);
assertThat(dictionaryClient.getAllTypes(createdType.getDossierTemplateId(),null,false).getTypes().size()).isEqualTo(0);
createdType = dictionaryClient.addType(type,null);
dictionaryClient.addType(type,null);
dictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);