Skip to content

Commit

Permalink
Adding implementations for tdwg/bdq#268 and tdwg/bdq#269 dwc:establis…
Browse files Browse the repository at this point in the history
…hmentMeans amendment and validation along with default methods and unit tests.
  • Loading branch information
chicoreus committed Jul 27, 2024
1 parent 287a6ff commit 005d9d9
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 16 deletions.
116 changes: 100 additions & 16 deletions src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
* #284 33c45ae1-e2db-462a-a59e-7169bb01c5d6 AMENDMENT_SEX_STANDARDIZED
* #275 060e7734-607d-4737-8b2c-bfa17788bf1a VALIDATION_DEGREEOFESTABLISHMENT_STANDARD
* #276 74ef1034-e289-4596-b5b0-cde73796697d AMENDMENT_DEGREEOFESTABLISHMENT_STANDARDIZED
* #268 4eb48fdf-7299-4d63-9d08-246902e2857f VALIDATION_ESTABLISHMENTMEANS_STANDARD
* #269 15d15927-7a22-43f8-88d6-298f5eb45c4c AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED
*
* TODO: Implement:
*
Expand Down Expand Up @@ -1187,22 +1189,24 @@ public static DQResponse<ComplianceValue> validationReproductiveconditionNotempt
/**
* Does the value of dwc:establishmentMeans occur in bdq:sourceAuthority?
*
* Provides: VALIDATION_ESTABLISHMENTMEANS_STANDARD
* Provides: 268 VALIDATION_ESTABLISHMENTMEANS_STANDARD
* Version: 2024-02-08
*
* @param establishmentMeans the provided dwc:establishmentMeans to evaluate as ActedUpon.
* @param sourceAuthority the bdq:sourceAuthority to consult.
* @return DQResponse the response of type ComplianceValue to return
*/
@Validation(label="VALIDATION_ESTABLISHMENTMEANS_STANDARD", description="Does the value of dwc:establishmentMeans occur in bdq:sourceAuthority?")
@Provides("4eb48fdf-7299-4d63-9d08-246902e2857f")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/4eb48fdf-7299-4d63-9d08-246902e2857f/2024-02-08")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL_PREREQUISITES_NOT_MET if dwc:establishmentMeans is EMPTY; COMPLIANT if the value of dwc:establishmentMeans is in the bdq:sourceAuthority; otherwise NOT_COMPLIANT. bdq:sourceAuthority default = 'Darwin Core establishmentMeans' {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]} {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}")
public DQResponse<ComplianceValue> validationEstablishmentmeansStandard(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans
public static DQResponse<ComplianceValue> validationEstablishmentmeansStandard(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans,
@Parameter(name="bdq:sourceAuthority") String sourceAuthority
) {
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();

//TODO: Implement specification
// Specification
// EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority
// is not available; INTERNAL_PREREQUISITES_NOT_MET if dwc:establishmentMeans
// is EMPTY; COMPLIANT if the value of dwc:establishmentMeans
Expand All @@ -1212,42 +1216,122 @@ public DQResponse<ComplianceValue> validationEstablishmentmeansStandard(
// vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}
//

//TODO: Parameters. This test is defined as parameterized.
// bdq:sourceAuthority
// Parameters. This test is defined as parameterized.
// bdq:sourceAuthority default = "Establishment Means
// Controlled Vocabulary List of Terms" {[https://dwc.tdwg.org/em/]} {GBIF
// vocabulary API
// [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}

if (MetadataUtils.isEmpty(establishmentMeans)) {
result.addComment("No Value provided for dwc:establishmentMeans");
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
} else {
if (MetadataUtils.isEmpty(sourceAuthority)) {
sourceAuthority = "GBIF EstablishmentMeans Vocabulary";
}
try {
MetadataSourceAuthority sourceAuthorityObject = new MetadataSourceAuthority(sourceAuthority);
if (sourceAuthorityObject.getAuthority().equals(EnumMetadataSourceAuthority.INVALID)) {
throw new SourceAuthorityException("Invalid source authority.");
}
if (!MetadataSingleton.getInstance().isLoaded()) {
result.addComment("Error accessing sourceAuthority: " + MetadataSingleton.getInstance().getLoadError() );
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
} else {
result.setResultState(ResultState.RUN_HAS_RESULT);
if (MetadataSingleton.getInstance().getEstablishmentMeansTerms().containsKey(establishmentMeans)) {
result.addComment("Provided value of dwc:establishmentMeans found in the sourceAuthority");
result.setValue(ComplianceValue.COMPLIANT);
} else {
result.addComment("Provided value of dwc:establishmentMeans [" + establishmentMeans + "] not found in the sourceAuthority");
result.setValue(ComplianceValue.NOT_COMPLIANT);
}
}
} catch (SourceAuthorityException e) {
result.addComment("Error with specified bdq:sourceAuthority ["+ sourceAuthority +"]: " + e.getMessage());
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
} catch (Exception e) {
result.addComment("Error evaluating dwc:establishmentMeans: " + e.getMessage());
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
}
}

return result;
}

/**
* Propose amendment to the value of dwc:establishmentMeans using bdq:sourceAuthority.
*
* Provides: AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED
* Provides: 269 AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED
* Version: 2024-02-08
*
* @param establishmentMeans the provided dwc:establishmentMeans to evaluate as ActedUpon.
* @param sourceAuthority the bdq:sourceAuthority to consult.
* @return DQResponse the response of type AmendmentValue to return
*/
@Amendment(label="AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED", description="Propose amendment to the value of dwc:establishmentMeans using bdq:sourceAuthority.")
@Provides("15d15927-7a22-43f8-88d6-298f5eb45c4c")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/15d15927-7a22-43f8-88d6-298f5eb45c4c/2024-02-08")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL PREREQUISITES_NOT_MET if dwc:establishmentMeans is EMPTY; AMENDED the value of dwc:establishmentMeans if it can be unambiguously matched to a term in bdq:sourceAuthority; otherwise NOT_AMENDED bdq:sourceAuthority default = 'Darwin Core establishmentMeans' {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]} {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}")
public DQResponse<AmendmentValue> amendmentEstablishmentmeansStandardized(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans
public static DQResponse<AmendmentValue> amendmentEstablishmentmeansStandardized(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans,
@Parameter(name="bdq:sourceAuthority") String sourceAuthority
) {
DQResponse<AmendmentValue> result = new DQResponse<AmendmentValue>();

//TODO: Implement specification
// Specification
// EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority
// is not available; INTERNAL PREREQUISITES_NOT_MET if dwc:establishmentMeans
// is EMPTY; AMENDED the value of dwc:establishmentMeans if
// it can be unambiguously matched to a term in bdq:sourceAuthority;
// otherwise NOT_AMENDED bdq:sourceAuthority default = "Darwin
// Core establishmentMeans" {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]}
// {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}
// otherwise NOT_AMENDED
//

//TODO: Parameters. This test is defined as parameterized.
// bdq:sourceAuthority
// Parameters. This test is defined as parameterized.
// bdq:sourceAuthority default = "Darwin
// Core establishmentMeans" {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]}
// {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}

if (MetadataUtils.isEmpty(establishmentMeans)) {
result.addComment("No Value provided for dwc:establishmentMeans");
result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET);
} else {
if (MetadataUtils.isEmpty(sourceAuthority)) {
sourceAuthority = "GBIF EstablishmentMeans Vocabulary";
}
try {
MetadataSourceAuthority sourceAuthorityObject = new MetadataSourceAuthority(sourceAuthority);
if (sourceAuthorityObject.getAuthority().equals(EnumMetadataSourceAuthority.INVALID)) {
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
}
if (!MetadataSingleton.getInstance().isLoaded()) {
result.addComment("Error accessing sourceAuthority: " + MetadataSingleton.getInstance().getLoadError() );
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
} else {
if (MetadataSingleton.getInstance().getEstablishmentMeansTerms().containsKey(establishmentMeans)) {
result.addComment("Provided value of dwc:establishmentMeans found in the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
} else {
if (MetadataSingleton.getInstance().getEstablishmentMeansValues().containsKey(establishmentMeans.trim().toLowerCase())) {
String match = MetadataSingleton.getInstance().getEstablishmentMeansValues().get(establishmentMeans.trim().toLowerCase());
result.setResultState(ResultState.AMENDED);
Map<String, String> values = new HashMap<>();
values.put("dwc:establishmentMeans", match) ;
result.setValue(new AmendmentValue(values));
} else {
result.addComment("Provided value of dwc:establishmentMeans [" + establishmentMeans + "] unable to be conformed to the the sourceAuthority");
result.setResultState(ResultState.NOT_AMENDED);
}
}
}
} catch (SourceAuthorityException e) {
result.addComment("Error with specified bdq:sourceAuthority ["+ sourceAuthority +"]: " + e.getMessage());
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
} catch (Exception e) {
result.addComment("Error evaluating dwc:establishmentMeans: " + e.getMessage());
result.setResultState(ResultState.EXTERNAL_PREREQUISITES_NOT_MET);
}
}

return result;
}
Expand Down Expand Up @@ -1935,7 +2019,7 @@ public static DQResponse<ComplianceValue> validationPathwayNotempty(
@Provides("43abded0-c3bf-44e7-8c1f-c4207608b1fa")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/43abded0-c3bf-44e7-8c1f-c4207608b1fa/2024-02-11")
@Specification("COMPLIANT if the value of dwc:individualCount is interpretable an integer; otherwise NOT_COMPLIANT. ")
public DQResponse<ComplianceValue> validationIndividualcountInteger(
public static DQResponse<ComplianceValue> validationIndividualcountInteger(
@ActedUpon("dwc:individualCount") String individualCount
) {
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,42 @@ public static DQResponse<AmendmentValue> amendmentPathwayStandardized(
) {
return amendmentPathwayStandardized(pathway,null);
}

/**
* Does the value of dwc:establishmentMeans occur in the default bdq:sourceAuthority?
*
* Provides: 268 VALIDATION_ESTABLISHMENTMEANS_STANDARD
* Version: 2024-02-08
*
* @param establishmentMeans the provided dwc:establishmentMeans to evaluate as ActedUpon.
* @return DQResponse the response of type ComplianceValue to return
*/
@Validation(label="VALIDATION_ESTABLISHMENTMEANS_STANDARD", description="Does the value of dwc:establishmentMeans occur in bdq:sourceAuthority?")
@Provides("4eb48fdf-7299-4d63-9d08-246902e2857f")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/4eb48fdf-7299-4d63-9d08-246902e2857f/2024-02-08")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL_PREREQUISITES_NOT_MET if dwc:establishmentMeans is EMPTY; COMPLIANT if the value of dwc:establishmentMeans is in the bdq:sourceAuthority; otherwise NOT_COMPLIANT. bdq:sourceAuthority default = 'Darwin Core establishmentMeans' {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]} {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}")
public static DQResponse<ComplianceValue> validationEstablishmentmeansStandard(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans
) {
return validationEstablishmentmeansStandard(establishmentMeans, null);
}

/**
* Propose amendment to the value of dwc:establishmentMeans using bdq:sourceAuthority.
*
* Provides: 269 AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED
* Version: 2024-02-08
*
* @param establishmentMeans the provided dwc:establishmentMeans to evaluate as ActedUpon.
* @return DQResponse the response of type AmendmentValue to return
*/
@Amendment(label="AMENDMENT_ESTABLISHMENTMEANS_STANDARDIZED", description="Propose amendment to the value of dwc:establishmentMeans using bdq:sourceAuthority.")
@Provides("15d15927-7a22-43f8-88d6-298f5eb45c4c")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/15d15927-7a22-43f8-88d6-298f5eb45c4c/2024-02-08")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL PREREQUISITES_NOT_MET if dwc:establishmentMeans is EMPTY; AMENDED the value of dwc:establishmentMeans if it can be unambiguously matched to a term in bdq:sourceAuthority; otherwise NOT_AMENDED bdq:sourceAuthority default = 'Darwin Core establishmentMeans' {[https://dwc.tdwg.org/list/#dwc_establishmentMeans]} {dwc:establishmentMeans vocabulary API [https://api.gbif.org/v1/vocabularies/EstablishmentMeans/concepts]}")
public static DQResponse<AmendmentValue> amendmentEstablishmentmeansStandardized(
@ActedUpon("dwc:establishmentMeans") String establishmentMeans
) {
return amendmentEstablishmentmeansStandardized(establishmentMeans, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public enum EnumMetadataSourceAuthority {
* GBIF Degree of Establishment Vocabulary
*/
GBIF_DEGREEOFESTABLISHMENT,
/**
* GBIF Establishment Means Vocabulary
*/
GBIF_ESTABLISHMENTMEANS,
/**
* Darwin Core Class Names
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public MetadataSourceAuthority(String authorityString) throws SourceAuthorityExc
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/Sex")) {
this.authority = EnumMetadataSourceAuthority.GBIF_SEX;

} else if (authorityString.toUpperCase().equals("GBIF ESTABLISHMENTMEANS VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_ESTABLISHMENTMEANS;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/EstabllishmentMeans")) {
this.authority = EnumMetadataSourceAuthority.GBIF_ESTABLISHMENTMEANS;
} else if (authorityString.equals("Darwin Core establishmentMeans")) {
// TODO: This should point at the TDWG vocabulary
this.authority = EnumMetadataSourceAuthority.GBIF_ESTABLISHMENTMEANS;

} else if (authorityString.toUpperCase().equals("GBIF DEGREEOFESTABLISHMENT VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_DEGREEOFESTABLISHMENT;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/DegreeOfEstablishment")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class MetadataSingleton {

private Map<String,List<String>> degreeOfEstablishmentTerms = new HashMap<String,List<String>>();
private Map<String,String> degreeOfEstablishmentValues = new HashMap<String,String>();

private Map<String,List<String>> establishmentMeansTerms = new HashMap<String,List<String>>();
private Map<String,String> establishmentMeansValues = new HashMap<String,String>();

private MetadataSingleton() {
init();
Expand Down Expand Up @@ -131,6 +134,17 @@ private void init() {
degreeOfEstablishmentValues.put(i.next(), key);
}
}

establishmentMeansTerms = gbif.loadVocabulary("EstablishmentMeans");
keys = establishmentMeansTerms.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
List<String> values = establishmentMeansTerms.get(key);
Iterator<String> i = values.iterator();
while (i.hasNext()) {
establishmentMeansValues.put(i.next(), key);
}
}

loaded = true;
loadError = "";
Expand Down Expand Up @@ -235,6 +249,26 @@ public Map<String, List<String>> getDegreeOfEstablishmentTerms() {
return degreeOfEstablishmentTerms;
}

/**
* get the establishmentMeans value:key pairs
* for finding vocabulary values for alternative labels
*
* @return the map of establishmentMeans values from the vocabulary
*/
public Map<String,String> getEstablishmentMeansValues() {
return establishmentMeansValues;
}

/**
* get the establishmentMeans key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of establishmentMeans values from the vocabulary
*/
public Map<String, List<String>> getEstablishmentMeansTerms() {
return establishmentMeansTerms;
}

/**
* @return true if vocabularies have been loaded
*/
Expand Down
Loading

0 comments on commit 005d9d9

Please sign in to comment.