Skip to content

Commit

Permalink
fix(Country Names): #290 (#295)
Browse files Browse the repository at this point in the history
Ignoring case sensitivity when converting country names to country IDs
  • Loading branch information
ndickerson authored Apr 26, 2019
1 parent cf0cae2 commit 22d99d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/bullhorn/dataloader/rest/Preloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ private Cell convertCell(Cell cell) {
if (cell.isAddress() && cell.getAssociationFieldName().equalsIgnoreCase(StringConsts.COUNTRY_NAME)) {
String name = cell.getAssociationBaseName() + "." + StringConsts.COUNTRY_ID;
String value = cell.getValue();
if (getCountryNameToIdMap().containsKey(cell.getValue())) {
value = getCountryNameToIdMap().get(cell.getValue()).toString();
if (getCountryNameToIdMap().containsKey(value.toLowerCase())) {
value = getCountryNameToIdMap().get(value.toLowerCase()).toString();
}
return new Cell(name, value);
}
Expand Down Expand Up @@ -80,7 +80,7 @@ private Map<String, Integer> createCountryNameToIdMap() {
Map<String, Integer> countryNameToIdMap = new HashMap<>();
List<Country> countryList = restApi.queryForList(Country.class, "id IS NOT null",
Sets.newHashSet("id", "name"), ParamFactory.queryParams());
countryList.forEach(n -> countryNameToIdMap.put(n.getName().trim(), n.getId()));
countryList.forEach(n -> countryNameToIdMap.put(n.getName().trim().toLowerCase(), n.getId()));
return countryNameToIdMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public void testIntegration() throws IOException {
// Test that the byte order mark is ignored when it's present in the input file as the first (hidden) character
runAllCommandsAgainstDirectory(TestUtils.getResourceFilePath("byteOrderMark"), false);

// Test that country names are case insensitive
runAllCommandsAgainstDirectory(TestUtils.getResourceFilePath("countryNames"), false);

// Test for wildcard associations for candidates in a note
System.setProperty("wildcardMatching", "true");
runAllCommandsAgainstDirectory(TestUtils.getResourceFilePath("wildcardMatching"), false);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/bullhorn/dataloader/rest/PreloaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public void testConvertRowSuccess() throws IOException {
verify(restApiMock, times(1)).queryForList(any(), any(), any(), any());
}

@Test
public void testConvertRowCaseInsensitive() throws IOException {
Row row = TestUtils.createRow("address.city,address.state,address.countryName",
"St. Louis,MO,UNITED STATES");
Row expectedRow = TestUtils.createRow("address.city,address.state,address.countryID",
"St. Louis,MO,1");

Row convertedRow = preloader.convertRow(row);

for (int i = 0; i < expectedRow.getCells().size(); ++i) {
Assert.assertThat(convertedRow.getCells().get(i), new ReflectionEquals(expectedRow.getCells().get(i)));
}
verify(restApiMock, times(1)).queryForList(any(), any(), any(), any());
}

@Test
public void testConvertRowInvalid() throws IOException {
Row row = TestUtils.createRow("address.city,address.state,address.countryName",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
externalID ,firstName,lastName ,name ,address.countryName
candidateCountryNames-ext-1,Country ,Name Test,Country Name Test,UNITED STATES

0 comments on commit 22d99d5

Please sign in to comment.