This repository was archived by the owner on May 5, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
java/de/symeda/sormas/api
java/de/symeda/sormas/backend/region
test/java/de/symeda/sormas/backend/region
sormas-ui/src/main/java/de/symeda/sormas/ui/caze/importer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ public interface Validations {
5353 String importCommunityAlreadyExists = "importCommunityAlreadyExists" ;
5454 String importCommunityNotUnique = "importCommunityNotUnique" ;
5555 String importCountryAlreadyExists = "importCountryAlreadyExists" ;
56+ String importCountryEmptyIso = "importCountryEmptyIso" ;
5657 String importDistrictAlreadyExists = "importDistrictAlreadyExists" ;
5758 String importDistrictNotUnique = "importDistrictNotUnique" ;
5859 String importEntryCommunityNotInUsersJurisdiction = "importEntryCommunityNotInUsersJurisdiction" ;
Original file line number Diff line number Diff line change 11package de .symeda .sormas .api .region ;
22
3- import javax .validation .constraints .NotBlank ;
4- import javax .validation .constraints .NotEmpty ;
53import javax .validation .constraints .Size ;
64
75import de .symeda .sormas .api .EntityDto ;
@@ -20,7 +18,6 @@ public class CountryDto extends EntityDto {
2018 private String defaultName ;
2119 private String externalId ;
2220 @ Size (min = 2 , max = 3 )
23- @ NotBlank
2421 private String isoCode ;
2522 @ Size (min = 1 , max = 3 )
2623 private String unoCode ;
Original file line number Diff line number Diff line change 1+ package de .symeda .sormas .api .utils ;
2+
3+ /**
4+ * Thrown when an entity that is supposed to be saved has an empty value which should not be empty
5+ */
6+ @ SuppressWarnings ("serial" )
7+ public class EmptyValueException extends ValidationRuntimeException {
8+
9+ public EmptyValueException (String message ) {
10+ super (message );
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ importInvalidDate = Invalid date in column %s; Allowed date formats are dd/MM/yy
4646importLineTooLong = This line is longer than the header line
4747importAreaNotUnique = Invalid value %s in column %s; Area name is not unique, make sure there is only one area with this name in the database
4848importRegionNotUnique = Invalid value %s in column %s; Region name is not unique, make sure there is only one region with this name in the database
49+ importCountryEmptyIso = The ISO code is empty.
4950importCountryAlreadyExists = The database already contains a country with this ISO code or this UNO code.
5051importRegionAlreadyExists = The database already contains a region with this name.
5152importDistrictAlreadyExists = The database already contains a district with this name in the specified region.
Original file line number Diff line number Diff line change 2424import de .symeda .sormas .api .region .CountryFacade ;
2525import de .symeda .sormas .api .region .CountryIndexDto ;
2626import de .symeda .sormas .api .region .CountryReferenceDto ;
27+ import de .symeda .sormas .api .utils .EmptyValueException ;
2728import de .symeda .sormas .api .utils .SortProperty ;
2829import de .symeda .sormas .api .utils .ValidationRuntimeException ;
2930import de .symeda .sormas .backend .util .DtoHelper ;
3031import de .symeda .sormas .backend .util .ModelConstants ;
3132import org .apache .commons .lang3 .ObjectUtils ;
33+ import org .apache .commons .lang3 .StringUtils ;
3234
3335@ Stateless (name = "CountryFacade" )
3436public class CountryFacadeEjb implements CountryFacade {
@@ -115,6 +117,10 @@ public long count(CountryCriteria criteria) {
115117
116118 @ Override
117119 public String saveCountry (CountryDto dto ) throws ValidationRuntimeException {
120+ if (StringUtils .isBlank (dto .getIsoCode ())) {
121+ throw new EmptyValueException (I18nProperties .getValidationError (Validations .importCountryEmptyIso ));
122+ }
123+
118124 Country country = countryService .getByUuid (dto .getUuid ());
119125
120126 if (country == null
Original file line number Diff line number Diff line change @@ -5560,7 +5560,7 @@ CREATE TABLE country (
55605560 archived boolean not null default false,
55615561 defaultname varchar (255 ),
55625562 externalid varchar (255 ),
5563- isocode varchar (3 ) unique,
5563+ isocode varchar (3 ) unique not null ,
55645564 unocode varchar (3 ) unique,
55655565 primary key (id)
55665566);
Original file line number Diff line number Diff line change 88import java .util .Objects ;
99
1010import de .symeda .sormas .api .region .CountryIndexDto ;
11+ import de .symeda .sormas .api .utils .EmptyValueException ;
1112import org .junit .Test ;
1213
1314import de .symeda .sormas .api .region .CountryCriteria ;
@@ -70,6 +71,13 @@ public void testSaveCountrySuccessful() throws Exception {
7071 assertTrue (entityIsEqualToDto (actual , expected ));
7172 }
7273
74+ @ Test (expected = EmptyValueException .class )
75+ public void testSaveCountryIsoCodeEmpty () {
76+ CountryDto country = new CountryDto ();
77+ country .setDefaultName ("Romania" );
78+ getCountryFacade ().saveCountry (country );
79+ }
80+
7381 @ Test (expected = ValidationRuntimeException .class )
7482 public void testSaveCountryIsoCodeExists () {
7583 creator .createCountry ("Romania" , "ROU" , "642" );
Original file line number Diff line number Diff line change 1111import javax .validation .constraints .NotBlank ;
1212import javax .validation .constraints .Size ;
1313
14+ import de .symeda .sormas .api .utils .EmptyValueException ;
1415import org .apache .commons .lang3 .StringUtils ;
1516
1617import com .opencsv .exceptions .CsvValidationException ;
@@ -67,6 +68,9 @@ protected ImportLineResult importDataFromCsvLine(
6768 try {
6869 FacadeProvider .getCountryFacade ().saveCountry (newEntityDto );
6970 return ImportLineResult .SUCCESS ;
71+ } catch (EmptyValueException e ) {
72+ writeImportError (values , e .getMessage ());
73+ return ImportLineResult .ERROR ;
7074 } catch (ValidationRuntimeException e ) {
7175 writeImportError (values , e .getMessage ());
7276 return ImportLineResult .DUPLICATE ;
You can’t perform that action at this time.
0 commit comments