Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit c228b04

Browse files
SORMAS-Foundation#2993 validate not blank
1 parent 6d65466 commit c228b04

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/region/CountryDto.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.symeda.sormas.api.region;
22

3+
import javax.validation.constraints.NotBlank;
4+
import javax.validation.constraints.NotEmpty;
35
import javax.validation.constraints.Size;
46

57
import de.symeda.sormas.api.EntityDto;
@@ -17,7 +19,8 @@ public class CountryDto extends EntityDto {
1719

1820
private String defaultName;
1921
private String externalId;
20-
@Size(min = 3, max = 3)
22+
@Size(min = 2, max = 3)
23+
@NotBlank
2124
private String isoCode;
2225
@Size(min = 1, max = 3)
2326
private String unoCode;

sormas-ui/src/main/java/de/symeda/sormas/ui/caze/importer/CountryImporter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.text.MessageFormat;
99
import java.util.function.Consumer;
1010

11+
import javax.validation.constraints.NotBlank;
1112
import javax.validation.constraints.Size;
1213

1314
import org.apache.commons.lang3.StringUtils;
@@ -116,7 +117,12 @@ private void insertColumnEntryIntoData(CountryDto newEntityDto, String value, St
116117
private void validateFieldLength(String field, String value) throws ImportErrorException, InvalidColumnException {
117118
try {
118119
Size size = CountryDto.class.getDeclaredField(field).getAnnotation(Size.class);
119-
if (StringUtils.isNotEmpty(value) && size != null) {
120+
boolean shouldNotBeBlank = CountryDto.class.isAnnotationPresent(NotBlank.class);
121+
if (shouldNotBeBlank && StringUtils.isBlank(value)) {
122+
String message = "The value {0} is blank.";
123+
throw new ImportErrorException(MessageFormat.format(message, value));
124+
}
125+
if (size != null) {
120126
if (value.length() < size.min()) {
121127
String message = "The value {0} has length {1} but the minimum length is {2}";
122128
throw new ImportErrorException(MessageFormat.format(message, value, value.length(), size.min()));

0 commit comments

Comments
 (0)