fieldNames = Arrays.stream(anyClass.getDeclaredFields())
+ .map(field -> field.getName().toLowerCase()).collect(Collectors.toList());
for (Method method : anyClass.getMethods()) {
if ("set".equalsIgnoreCase(method.getName().substring(0, 3))) {
- setterMethodMap.put(method.getName().substring(3).toLowerCase(), method);
+ String name = method.getName().substring(3).toLowerCase();
+ String altName = StringConsts.IS + name;
+ if (!fieldNames.contains(name) && fieldNames.contains(altName)) {
+ setterMethodMap.put(altName, method);
+ } else {
+ setterMethodMap.put(name, method);
+ }
}
}
@@ -160,12 +183,17 @@ public static Object convertStringToObject(String value, Class type, DateTimeFor
*
* For example, the method: Candidate:getExternalID() will return the field name: 'externalID'
* that can be used as a valid field name in Rest.
+ * Check if the name of the method is truncating the "is" prefix.
*
* @param method A getter or setter method
* @return the field name in rest that corresponds to that getter or setter
*/
- public static String getFieldNameFromMethod(Method method) {
- return WordUtils.uncapitalize(method.getName().substring(3));
+ public static String getFieldNameFromMethod(Method method, String name) {
+ String nameFromMethod = method.getName().substring(3);
+ if (name.toLowerCase().equals(StringConsts.IS + nameFromMethod.toLowerCase())) {
+ return StringConsts.IS + nameFromMethod;
+ }
+ return WordUtils.uncapitalize(nameFromMethod);
}
private static Method getMethod(EntityInfo entityInfo, String fieldName, Map methodMap) {
diff --git a/src/main/java/com/bullhorn/dataloader/util/StringConsts.java b/src/main/java/com/bullhorn/dataloader/util/StringConsts.java
index 6e7483fd..09a1d61d 100644
--- a/src/main/java/com/bullhorn/dataloader/util/StringConsts.java
+++ b/src/main/java/com/bullhorn/dataloader/util/StringConsts.java
@@ -21,6 +21,7 @@ public class StringConsts {
public static final String EXTERNAL_ID = "externalID";
public static final String FIRST_NAME = "firstName";
public static final String ID = "id";
+ public static final String IS = "is";
public static final String IS_DELETED = "isDeleted";
public static final String IS_RESUME = "isResume";
public static final String LAST_NAME = "lastName";
diff --git a/src/test/java/com/bullhorn/dataloader/rest/FieldTest.java b/src/test/java/com/bullhorn/dataloader/rest/FieldTest.java
index 5c435209..3041150a 100644
--- a/src/test/java/com/bullhorn/dataloader/rest/FieldTest.java
+++ b/src/test/java/com/bullhorn/dataloader/rest/FieldTest.java
@@ -3,6 +3,7 @@
import java.math.BigDecimal;
import java.text.ParseException;
+import com.bullhornsdk.data.model.entity.core.standard.Placement;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -120,6 +121,34 @@ public void testDirectBooleanField() throws Exception {
Assert.assertEquals(field.getStringValueFromEntity(jobSubmission, ";"), "false");
}
+ @Test
+ public void testNonStandardBooleanField() throws Exception {
+ Cell cell = new Cell("isWorkFROMHome", "true");
+ Field field = new Field(EntityInfo.PLACEMENT, cell, true, dateTimeFormatter);
+
+ Assert.assertEquals(field.getEntityInfo(), EntityInfo.PLACEMENT);
+ Assert.assertEquals(field.isExistField(), true);
+ Assert.assertEquals(field.isToOne(), false);
+ Assert.assertEquals(field.isToMany(), false);
+ Assert.assertEquals(field.getName(), "isWorkFromHome");
+ Assert.assertEquals(field.getFieldParameterName(true), "isWorkFromHome");
+ Assert.assertEquals(field.getFieldParameterName(false), "isWorkFromHome");
+ Assert.assertEquals(field.getFieldEntity(), EntityInfo.PLACEMENT);
+ Assert.assertEquals(field.getFieldType(), Boolean.class);
+ Assert.assertEquals(field.getValue(), true);
+ Assert.assertEquals(field.getStringValue(), "true");
+
+ Placement placement = new Placement();
+
+ Assert.assertNull(placement.getWorkFromHome());
+ Assert.assertEquals(field.getStringValueFromEntity(placement, ";"), "");
+
+ field.populateFieldOnEntity(placement);
+
+ Assert.assertEquals(placement.getWorkFromHome(), true);
+ Assert.assertEquals(field.getStringValueFromEntity(placement, ";"), "true");
+ }
+
@Test
public void testDirectDateTimeField() throws Exception {
Cell cell = new Cell("dateAvailable", "02/09/2001");
diff --git a/src/test/java/com/bullhorn/dataloader/task/ExportTaskTest.java b/src/test/java/com/bullhorn/dataloader/task/ExportTaskTest.java
index 25ba4b08..b2c2b183 100644
--- a/src/test/java/com/bullhorn/dataloader/task/ExportTaskTest.java
+++ b/src/test/java/com/bullhorn/dataloader/task/ExportTaskTest.java
@@ -141,8 +141,7 @@ public void testRunFailureNoExistField() throws Exception {
task.run();
Result expectedResult = Result.failure(new DataLoaderException(ErrorInfo.MISSING_SETTING,
- ""
- + "Cannot perform export because exist field is not specified for entity: Candidate"));
+ "Cannot perform export because exist field is not specified for entity: Candidate"));
verify(csvFileWriterMock, times(1)).writeRow(any(), eq(expectedResult));
TestUtils.verifyActionTotals(actionTotalsMock, Result.Action.FAILURE, 1);
}
diff --git a/src/test/java/com/bullhorn/dataloader/util/MethodUtilTest.java b/src/test/java/com/bullhorn/dataloader/util/MethodUtilTest.java
index 5dd8c8b3..46e6fce4 100644
--- a/src/test/java/com/bullhorn/dataloader/util/MethodUtilTest.java
+++ b/src/test/java/com/bullhorn/dataloader/util/MethodUtilTest.java
@@ -13,6 +13,7 @@
import com.bullhorn.dataloader.enums.EntityInfo;
import com.bullhorn.dataloader.enums.ErrorInfo;
+
import com.bullhornsdk.data.model.entity.embedded.Address;
public class MethodUtilTest {
@@ -54,8 +55,56 @@ public void testGetSetterMethodAddress1() {
Assert.assertEquals(setterMethod.getParameterTypes()[0], String.class);
}
+ @Test
+ public void testGetGetterMethodFailure() {
+ DataLoaderException expectedException = new DataLoaderException(ErrorInfo.INCORRECT_COLUMN_NAME,
+ "'workFromHome' does not exist on Placement");
+ DataLoaderException actualException = null;
+
+ try {
+ MethodUtil.getGetterMethod(EntityInfo.PLACEMENT, "workFromHome");
+ } catch (DataLoaderException e) {
+ actualException = e;
+ }
+
+ Assert.assertNotNull(actualException);
+ Assert.assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
@Test
public void testGetSetterMethodFailure() {
+ DataLoaderException expectedException = new DataLoaderException(ErrorInfo.INCORRECT_COLUMN_NAME,
+ "'workFromHome' does not exist on Placement");
+ DataLoaderException actualException = null;
+
+ try {
+ MethodUtil.getSetterMethod(EntityInfo.PLACEMENT, "workFromHome");
+ } catch (DataLoaderException e) {
+ actualException = e;
+ }
+
+ Assert.assertNotNull(actualException);
+ Assert.assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
+ @Test
+ public void testGetGetterMethodMalformedAddressFailure() {
+ DataLoaderException expectedException = new DataLoaderException(ErrorInfo.INCORRECT_COLUMN_NAME,
+ "Invalid address field format: 'address1'. Must use: 'address.address1' to set an address field.");
+ DataLoaderException actualException = null;
+
+ try {
+ MethodUtil.getSetterMethod(EntityInfo.CANDIDATE, "address1");
+ } catch (DataLoaderException e) {
+ actualException = e;
+ }
+
+ Assert.assertNotNull(actualException);
+ Assert.assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
+ @Test
+ public void testGetSetterMethodAddressFailure() {
DataLoaderException expectedException = new DataLoaderException(ErrorInfo.INCORRECT_COLUMN_NAME,
"Invalid address field format: 'address1'. Must use: 'address.address1' to set an address field.");
DataLoaderException actualException = null;
@@ -106,4 +155,30 @@ public void testConvertStringToObjectReturnsNull() throws ParseException {
Object actual = MethodUtil.convertStringToObject("bogus", MethodUtil.class, dateTimeFormatter);
Assert.assertNull(actual);
}
+
+ @Test
+ public void testAlternativeNameGetterMethods() {
+ // The getter is named without the word is: getWorkFromHome()
+ Method methodNameMismatch = MethodUtil.getGetterMethod(EntityInfo.PLACEMENT, "isWorkFromHome");
+ Assert.assertNotNull(methodNameMismatch);
+
+ Method clientContact = MethodUtil.getGetterMethod(EntityInfo.OPPORTUNITY, "clientContact");
+ Assert.assertNotNull(clientContact);
+
+ Method isClientContact = MethodUtil.getGetterMethod(EntityInfo.OPPORTUNITY, "isClientContact");
+ Assert.assertNotNull(isClientContact);
+ }
+
+ @Test
+ public void testAlternativeNameSetterMethods() {
+ // The setter is named without the word is: getWorkFromHome()
+ Method methodNameMismatch = MethodUtil.getSetterMethod(EntityInfo.PLACEMENT, "isWorkFromHome");
+ Assert.assertNotNull(methodNameMismatch);
+
+ Method clientContact = MethodUtil.getSetterMethod(EntityInfo.OPPORTUNITY, "clientContact");
+ Assert.assertNotNull(clientContact);
+
+ Method isClientContact = MethodUtil.getSetterMethod(EntityInfo.OPPORTUNITY, "isClientContact");
+ Assert.assertNotNull(isClientContact);
+ }
}
diff --git a/src/test/resources/integrationTest/specialCharacters/AppointmentSpecialCharacters.csv b/src/test/resources/integrationTest/specialCharacters/AppointmentSpecialCharacters.csv
index a3d15ff4..fd0d6760 100644
--- a/src/test/resources/integrationTest/specialCharacters/AppointmentSpecialCharacters.csv
+++ b/src/test/resources/integrationTest/specialCharacters/AppointmentSpecialCharacters.csv
@@ -11,7 +11,6 @@ $appointment-ext-1,Meeting,Special Character: $
)appointment-ext-1,Meeting,Special Character: )
_appointment-ext-1,Meeting,Special Character: _
-appointment-ext-1,Meeting,Special Character: -
-+appointment-ext-1,Meeting,Special Character: +
\appointment-ext-1,Meeting,Special Character: \
{appointment-ext-1,Meeting,Special Character: {
}appointment-ext-1,Meeting,Special Character: }
diff --git a/src/test/resources/integrationTest/specialCharacters/CandidateSpecialCharacters.csv b/src/test/resources/integrationTest/specialCharacters/CandidateSpecialCharacters.csv
index 2f22016f..7bb98012 100644
--- a/src/test/resources/integrationTest/specialCharacters/CandidateSpecialCharacters.csv
+++ b/src/test/resources/integrationTest/specialCharacters/CandidateSpecialCharacters.csv
@@ -10,7 +10,6 @@ $candidate-ext-1,Special,Character: $,Special Character: $
)candidate-ext-1,Special,Character: ),Special Character: )
_candidate-ext-1,Special,Character: _,Special Character: _
-candidate-ext-1,Special,Character: -,Special Character: -
-+candidate-ext-1,Special,Character: +,Special Character: +
{candidate-ext-1,Special,Character: {,Special Character: {
}candidate-ext-1,Special,Character: },Special Character: }
.candidate-ext-1,Special,Character: .,Special Character: .