Skip to content

Commit 18a0583

Browse files
leventegal-sheLevente Gal
andauthored
#13227 Allow "+" character as a value (e.g. "A+B") in the customizabl… (#13251)
* #13227 Allow "+" character as a value (e.g. "A+B") in the customizable enums * #13227 Allow "+" character as a value (e.g. "A+B") in the customizable enums - update validation message --------- Co-authored-by: Levente Gal <levente.gal.ext@vitagroup.ag>
1 parent 467ad5a commit 18a0583

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class CustomizableEnumHelper {
2121

22-
private static final String ENUM_VALUE_PATTERN = "[A-Z0-9_.]+";
22+
private static final String ENUM_VALUE_PATTERN = "[A-Z0-9_.+]+";
2323

2424
public static boolean isValidEnumValue(String value) {
2525
return Pattern.matches(ENUM_VALUE_PATTERN, value);

sormas-api/src/main/resources/validations.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ defaultInfrastructureInvalidParentDistrict = This community is in a different di
292292
defaultInfrastructureNotRemovableChildCommunity = You have to remove the default community before removing the default district.
293293
defaultInfrastructureNotRemovableChildDistrict = You have to remove the default district before removing the default region.
294294
emailTemplateSubjectInvalid=The first line of the email template needs to start with a "#" character followed by at most 50 characters
295-
customizableEnumValueAllowedCharacters = Value may only consist of uppercase letters, numbers, and the characters "_" and ".".
295+
customizableEnumValueAllowedCharacters = Value may only consist of uppercase letters, numbers, and the characters "_", "." and "+".
296296
customizableEnumValueEmptyTranslations = Please select languages and enter captions for all translations in the list.
297297
customizableEnumValueDuplicateLanguage = Please only add one translation per language.
298298
customizableEnumValueDuplicateValue = The value %s already exists for data type %s. Enum values have to be unique.

sormas-backend/src/test/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjbTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package de.symeda.sormas.backend.customizableenum;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
45
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
57

68
import java.util.HashSet;
79
import java.util.List;
@@ -13,6 +15,7 @@
1315
import de.symeda.sormas.api.Disease;
1416
import de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException;
1517
import de.symeda.sormas.api.customizableenum.CustomizableEnum;
18+
import de.symeda.sormas.api.customizableenum.CustomizableEnumHelper;
1619
import de.symeda.sormas.api.customizableenum.CustomizableEnumType;
1720
import de.symeda.sormas.backend.AbstractBeanTest;
1821

@@ -61,4 +64,19 @@ public void tetGetUnknownDiseaseVariantWithNullDisease() throws CustomEnumNotFou
6164
CustomEnumNotFoundException.class,
6265
() -> getCustomizableEnumFacade().getEnumValue(CustomizableEnumType.DISEASE_VARIANT, "any", null));
6366
}
67+
68+
@Test
69+
public void testEnumValueValidation() {
70+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALIDSIMPLEVALUE"));
71+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIMPLE_VALUE"));
72+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID.SIMPLE.VALUE"));
73+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID+SIMPLE+VALUE"));
74+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIM+PLE.VALUE"));
75+
assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIMPLE.VALUE+1"));
76+
77+
assertFalse(CustomizableEnumHelper.isValidEnumValue("invalidvalue"));
78+
assertFalse(CustomizableEnumHelper.isValidEnumValue("INVALID-VALUE"));
79+
assertFalse(CustomizableEnumHelper.isValidEnumValue("INVALID$VALUE"));
80+
81+
}
6482
}

0 commit comments

Comments
 (0)