Skip to content

Commit

Permalink
Work in progress checking implementation of DwCGeoRefDQ methods again…
Browse files Browse the repository at this point in the history
…st current (2023-06-12) test descriptions. Addressed implementation of tdwg/bdq#87 VALIDATION_COORDINATES_NOTZERO   Adding ProvidesVersion annotations.   Removing now empty file stubs for checked methods.  Adding to unit test.
  • Loading branch information
chicoreus committed Jun 18, 2023
1 parent beb521e commit 74ca7ce
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
22 changes: 16 additions & 6 deletions src/main/java/org/filteredpush/qc/georeference/DwCGeoRefDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,16 @@ public static DQResponse<ComplianceValue> validationDecimallatitudeInrange(
* Are the values of either dwc:decimalLatitude or dwc:decimalLongitude numbers that are not equal to 0?
*
* Provides: #87 VALIDATION_COORDINATES_NOTZERO
* Version: 2022-05-22
*
* @param decimalLatitude the provided dwc:decimalLatitude to evaluate
* @param decimalLongitude the provided dwc:decimalLongitude to evaluate
* @return DQResponse the response of type ComplianceValue to return
*/
@Validation(label="VALIDATION_COORDINATES_NOTZERO", description="Are the values of either dwc:decimalLatitude or dwc:decimalLongitude numbers that are not equal to 0?")
@Provides("1bf0e210-6792-4128-b8cc-ab6828aa4871")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/1bf0e210-6792-4128-b8cc-ab6828aa4871/2022-05-22")
@Specification("INTERNAL_PREREQUISITES_NOT_MET if dwc:decimalLatitude and/or dwc:decimalLongitude are EMPTY or both of the values are not interpretable as numbers; COMPLIANT if either the value of dwc:decimalLatitude is not = 0 or the value of dwc:decimalLongitude is not = 0; otherwise NOT_COMPLIANT ")
public static DQResponse<ComplianceValue> validationCoordinatesNotzero(@ActedUpon("dwc:decimalLatitude") String decimalLatitude, @ActedUpon("dwc:decimalLongitude") String decimalLongitude) {
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();

Expand All @@ -1048,13 +1051,20 @@ public static DQResponse<ComplianceValue> validationCoordinatesNotzero(@ActedUpo
} else if (GEOUtil.isEmpty(decimalLongitude)) {
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
result.addComment("provided value for dwc:decimalLongitude is empty.");
} else if (!GEOUtil.isNumericCharacters(decimalLatitude)) {
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
result.addComment("provided value for dwc:decimalLatitude ["+decimalLatitude+"] contains non-numeric characters.");
} else if (!GEOUtil.isNumericCharacters(decimalLongitude)) {
} else if (!GEOUtil.isNumericCharacters(decimalLatitude) && !GEOUtil.isNumericCharacters(decimalLongitude)) {
// internal prerequisites not met only if both are not numbers
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
result.addComment("provided value for dwc:decimalLongitude ["+decimalLongitude+"] contains non-numeric characters.");
} else {
result.addComment("provided value for dwc:decimalLatitude ["+decimalLatitude+"] and dwc:decimalLongitude ["+decimalLatitude+"] both contain non-numeric characters.");
} else {
// internal prerequisites not met only if both are not numbers, if one is, set it to 1 and test the other for zero.
if (!GEOUtil.isNumericCharacters(decimalLongitude)) {
result.addComment("provided value for dwc:decimalLongitude ["+decimalLongitude+"] contains non-numeric characters.");
decimalLongitude="1";
}
if (!GEOUtil.isNumericCharacters(decimalLatitude)) {
result.addComment("provided value for dwc:decimalLatitude ["+decimalLatitude+"] contains non-numeric characters.");
decimalLatitude="1";
}
try {
Double decimalLatitudeNumber = Double.parseDouble(decimalLatitude);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,33 +623,6 @@ public DQResponse<AmendmentValue> amendmentCountrycodeFromCoordinates(@ActedUpon
return result;
}

/**
* Are the values of either dwc:decimalLatitude or dwc:decimalLongitude numbers that are not equal to 0?
*
* Provides: VALIDATION_COORDINATES_NOTZERO
* Version: 2022-05-22
*
* @param decimalLatitude the provided dwc:decimalLatitude to evaluate
* @param decimalLongitude the provided dwc:decimalLongitude to evaluate
* @return DQResponse the response of type ComplianceValue to return
*/
@Validation(label="VALIDATION_COORDINATES_NOTZERO", description="Are the values of either dwc:decimalLatitude or dwc:decimalLongitude numbers that are not equal to 0?")
@Provides("1bf0e210-6792-4128-b8cc-ab6828aa4871")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/1bf0e210-6792-4128-b8cc-ab6828aa4871/2022-05-22")
@Specification("INTERNAL_PREREQUISITES_NOT_MET if dwc:decimalLatitude and/or dwc:decimalLongitude are EMPTY or both of the values are not interpretable as numbers; COMPLIANT if either the value of dwc:decimalLatitude is not = 0 or the value of dwc:decimalLongitude is not = 0; otherwise NOT_COMPLIANT ")
public DQResponse<ComplianceValue> validationCoordinatesNotzero(@ActedUpon("dwc:decimalLatitude") String decimalLatitude, @ActedUpon("dwc:decimalLongitude") String decimalLongitude) {
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();

//TODO: Implement specification
// INTERNAL_PREREQUISITES_NOT_MET if dwc:decimalLatitude and/or
// dwc:decimalLongitude are EMPTY or both of the values are
// not interpretable as numbers; COMPLIANT if either the value
// of dwc:decimalLatitude is not = 0 or the value of dwc:decimalLongitude
// is not = 0; otherwise NOT_COMPLIANT

return result;
}

/**
* Is there a value in dwc:decimalLongitude?
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ public void testValidationCoordinatesNotzero() {
logger.debug(result.getComment());
assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState());
assertNull(result.getValue());
assertNotNull(result.getComment());

result = DwCGeoRefDQ.validationCoordinatesNotzero("A","B");
logger.debug(result.getComment());
assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState());
assertNull(result.getValue());
assertNotNull(result.getComment());

result = DwCGeoRefDQ.validationCoordinatesNotzero("1.4","3.6");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());
assertNotNull(result.getComment());

result = DwCGeoRefDQ.validationCoordinatesNotzero("0","0");
logger.debug(result.getComment());
Expand All @@ -56,6 +64,41 @@ public void testValidationCoordinatesNotzero() {
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());

result = DwCGeoRefDQ.validationCoordinatesNotzero("1.4","B");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());

result = DwCGeoRefDQ.validationCoordinatesNotzero("A","-26.42552");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());

// test does not evaluate sanity of numbers
result = DwCGeoRefDQ.validationCoordinatesNotzero("1000.00002","-5000.00133");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());

result = DwCGeoRefDQ.validationCoordinatesNotzero(Integer.toString(Integer.MAX_VALUE), Integer.toString(Integer.MAX_VALUE));
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel());

// given note: "A record with 0.0 is interpreted as the string "0""

// treat -0 as the same as 0
result = DwCGeoRefDQ.validationCoordinatesNotzero("-0","-0");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), result.getValue().getLabel());

result = DwCGeoRefDQ.validationCoordinatesNotzero("0.0","0.0");
logger.debug(result.getComment());
assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel());
assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), result.getValue().getLabel());

}

/**
Expand Down Expand Up @@ -85,7 +128,7 @@ public void testValidationCountrycodeStandard() {
assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState());
assertEquals(ComplianceValue.COMPLIANT, result.getValue());

}
}

/**
* Test method for {@link org.filteredpush.qc.georeference.DwCGeoRefDQ#validationMaxdepthInrange(java.lang.String)}.
Expand Down

0 comments on commit 74ca7ce

Please sign in to comment.