Skip to content

Commit

Permalink
ISSUE: MCZ Redmine 866 tdwg/bdq#93 PURPOSE: Updating tests to current…
Browse files Browse the repository at this point in the history
… specifications. DESCRIPTION: Conforming the implementation and unit tests for AMENDMENT_EVENTDATE_FROM_YEARMONTHDAY to the expectations expressed in the validation data for handling uncertainty. This code passes validation dataID 994 (and all the other TIME test cases in v19 of the validation data except for dataID 987 which probably has a typo in the validation data).
  • Loading branch information
chicoreus committed Mar 21, 2022
1 parent fb12f74 commit 44fcccd
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 26 deletions.
72 changes: 51 additions & 21 deletions src/main/java/org/filteredpush/qc/date/DwCEventDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,6 @@ public static final DQResponse<AmendmentValue> amendmentEventDateFromYearMonthDa
// interpreted from the values in dwc:year, dwc:month and dwc:day;
// otherwise NOT_AMENDED


DQResponse<AmendmentValue> result = new DQResponse<>();
if (DateUtils.isEmpty(year)) {
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
Expand All @@ -1474,39 +1473,70 @@ public static final DQResponse<AmendmentValue> amendmentEventDateFromYearMonthDa
result.addComment("A value exists in dwc:eventDate, ammendment not attempted.");
} else {
try {
Integer.parseInt(year);
Integer.parseInt(year.trim());
try {
boolean hasMonth = false;
boolean hasDay = false;
if (!DateUtils.isEmpty(month)) {
if (month.matches("^[XIVxiv]+$")) {
// Roman numeral month values are interpretable as numbers.
if (month.matches("^[XIVxiv]+$")) {
try {
// Roman numeral month values are interpretable as numbers.
logger.debug(month);
if (DateUtils.romanMonthToInteger(month)==null) {
Integer monthInt = Integer.parseInt(month);
if (DateUtils.isMonthInRange(monthInt)) {
hasMonth=true;
}
} else {
String numericmonth = DateUtils.romanMonthToInteger(month).toString();
result.addComment("Converting month ["+month+"] to ["+ numericmonth +"] .");
month = DateUtils.romanMonthToInteger(month).toString();
if (month!=null && month.length()>0) {
hasMonth=true;
}
}
} catch (NumberFormatException e) {
result.addComment("The provided value for month ["+ month +"] is not interpretable as a month.");
}
logger.debug(month);
if (DateUtils.romanMonthToInteger(month)==null) {
Integer.parseInt(month);
hasMonth=true;
} else {
String numericmonth = DateUtils.romanMonthToInteger(month).toString();
result.addComment("Converting month ["+month+"] to ["+ numericmonth +"] .");
month = DateUtils.romanMonthToInteger(month).toString();
if (month!=null && month.length()>0) {
} else {
try {
Integer monthInt = Integer.parseInt(month);
if (DateUtils.isMonthInRange(monthInt)) {
hasMonth=true;
}
} catch (NumberFormatException e) {
result.addComment("The provided value for month ["+ month +"] is not interpretable as a month.");
}
logger.debug(month);
} else {
Integer.parseInt(month);
hasMonth=true;
}
}
if (!DateUtils.isEmpty(day)) {
Integer numericDay = Integer.parseInt(day);
if (!DateUtils.isDayInRange(numericDay)) {
throw new NumberFormatException("The provided value for Day is out of range for a day");
try {
Integer numericDay = Integer.parseInt(day.trim());
if (!DateUtils.isDayInRange(numericDay)) {
throw new NumberFormatException("The provided value for Day is out of range for a day");
} else {
hasDay = true;
}
} catch (NumberFormatException e) {
result.addComment("The provided value for day ["+ day +"] is not interpretable as an integer.");
}
}
// try, may raise exception
String resultDateString = DateUtils.createEventDateFromParts("", "", "", year, month, day);
if (!hasMonth) {
String resultDateString = year.trim();
if (hasMonth && hasDay) {
try {
resultDateString = DateUtils.createEventDateFromParts("", "", "", year, month, day);
} catch (NumberFormatException e) {
result.addComment("The combination of year ["+ year +"] with ["+month+"], and day ["+ day +"] is not interpretable as a date.");
}
} else if (hasMonth && !hasDay) {
try {
resultDateString = DateUtils.createEventDateFromParts("", "", "", year, month, "");
} catch (NumberFormatException e) {
result.addComment("The combination of year ["+ year +"] with ["+month+"] is not interpretable as a date.");
}
} else if (!hasMonth) {
// From Notes: If dwc:year and dwc:day are present,
// but dwc:month is not supplied, then just the year should be given as the proposed amendment.
resultDateString = DateUtils.createEventDateFromParts("", "", "", year, "", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,31 @@ public void testAmendmentEventdateFromYearmonthday() {
month="32";
day="15";
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.NOT_AMENDED.getLabel(), result.getResultState().getLabel());
assertEquals(ResultState.AMENDED.getLabel(), result.getResultState().getLabel());
assertNotNull(result.getValue().getObject());
resultValues = result.getValue().getObject();
assertTrue(resultValues.containsKey("dwc:eventDate"));
assertEquals("1880",resultValues.get("dwc:eventDate"));
assertEquals(1,resultValues.size());

eventDate="";
year="1880";
month="Feb";
day="15";
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.NOT_AMENDED.getLabel(), result.getResultState().getLabel());
assertEquals(ResultState.AMENDED.getLabel(), result.getResultState().getLabel());
assertNotNull(result.getValue().getObject());
resultValues = result.getValue().getObject();
assertTrue(resultValues.containsKey("dwc:eventDate"));
assertEquals("1880",resultValues.get("dwc:eventDate"));
assertEquals(1,resultValues.size());

eventDate="";
year="1880";
month="";
day="150"; // out of range
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.NOT_AMENDED.getLabel(), result.getResultState().getLabel());
assertEquals(ResultState.AMENDED.getLabel(), result.getResultState().getLabel());

// Notes in issue: "If dwc:year and dwc:day are present, but dwc:month is not supplied,
// then just the year should be given as the proposed amendment."
Expand All @@ -686,6 +696,19 @@ public void testAmendmentEventdateFromYearmonthday() {
assertEquals("1880",resultValues.get("dwc:eventDate"));
assertEquals(1,resultValues.size());

eventDate="";
year="1880";
month="10";
day="x"; // uninterpretable
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.AMENDED.getLabel(), result.getResultState().getLabel());
assertNotNull(result.getValue().getObject());
resultValues = result.getValue().getObject();
assertTrue(resultValues.containsKey("dwc:eventDate"));
assertEquals("1880-10",resultValues.get("dwc:eventDate"));
assertEquals(1,resultValues.size());


}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -709,7 +710,10 @@ public void testEventDateFromMonthDay() {
month = "text";
day = "6";
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.NOT_AMENDED.getLabel(),result.getResultState().getLabel());
assertEquals(ResultState.AMENDED.getLabel(),result.getResultState().getLabel());
Map<String, String> retval = result.getValue().getObject();
assertEquals(1, retval.size());
assertEquals("1980", retval.get("dwc:eventDate"));

eventDate = "";
year = "";
Expand All @@ -723,7 +727,10 @@ public void testEventDateFromMonthDay() {
month = "12";
day = "text";
result = DwCEventDQ.amendmentEventDateFromYearMonthDay(eventDate, year, month, day);
assertEquals(ResultState.NOT_AMENDED.getLabel(),result.getResultState().getLabel());
assertEquals(ResultState.AMENDED.getLabel(),result.getResultState().getLabel());
retval = result.getValue().getObject();
assertEquals(1, retval.size());
assertEquals("1980-12", retval.get("dwc:eventDate"));

eventDate = "";
year = "1980";
Expand Down

0 comments on commit 44fcccd

Please sign in to comment.